summaryrefslogtreecommitdiff
path: root/src/se/leap
diff options
context:
space:
mode:
Diffstat (limited to 'src/se/leap')
-rw-r--r--src/se/leap/bitmaskclient/ConfigHelper.java3
-rw-r--r--src/se/leap/bitmaskclient/ConfigurationWizard.java25
-rw-r--r--src/se/leap/bitmaskclient/DownloadFailedDialog.java27
-rw-r--r--src/se/leap/bitmaskclient/ProviderAPI.java46
4 files changed, 85 insertions, 16 deletions
diff --git a/src/se/leap/bitmaskclient/ConfigHelper.java b/src/se/leap/bitmaskclient/ConfigHelper.java
index dd7049a7..6b49d7d7 100644
--- a/src/se/leap/bitmaskclient/ConfigHelper.java
+++ b/src/se/leap/bitmaskclient/ConfigHelper.java
@@ -168,6 +168,9 @@ public class ConfigHelper {
return shared_preferences.getInt(shared_preferences_key, 0);
}
+ protected static boolean sharedPrefContainsKey(String shared_preferences_key) {
+ return shared_preferences.contains(shared_preferences_key);
+ }
/*
* This method defaults to false.
* If you use this method, be sure to fail-closed on false!
diff --git a/src/se/leap/bitmaskclient/ConfigurationWizard.java b/src/se/leap/bitmaskclient/ConfigurationWizard.java
index 0cdd4561..f4409056 100644
--- a/src/se/leap/bitmaskclient/ConfigurationWizard.java
+++ b/src/se/leap/bitmaskclient/ConfigurationWizard.java
@@ -25,6 +25,11 @@ import org.json.JSONObject;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.ProviderAPIResultReceiver.Receiver;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
+
+import se.leap.bitmaskclient.DownloadFailedDialog.DownloadFailedDialogInterface;
+import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface;
+import se.leap.bitmaskclient.ProviderDetailFragment.ProviderDetailFragmentInterface;
+
import android.app.Activity;
import android.app.DialogFragment;
import android.app.Fragment;
@@ -61,7 +66,7 @@ import android.widget.TextView;
*
*/
public class ConfigurationWizard extends Activity
-implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogInterface, ProviderDetailFragment.ProviderDetailFragmentInterface, Receiver {
+implements ProviderListFragment.Callbacks, NewProviderDialogInterface, ProviderDetailFragmentInterface, DownloadFailedDialogInterface, Receiver {
private ProgressBar mProgressBar;
private TextView progressbar_description;
@@ -192,7 +197,11 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
startProgressBar(provider_index+1);
provider_list_fragment.hideAllBut(provider_index);
- setUpProvider(selected_provider.providerMainUrl(), true);
+
+ boolean danger_on = true;
+ if(ConfigHelper.sharedPrefContainsKey(ProviderItem.DANGER_ON))
+ danger_on = ConfigHelper.getBoolFromSharedPref(ProviderItem.DANGER_ON);
+ setUpProvider(selected_provider.providerMainUrl(), danger_on);
}
@Override
@@ -394,6 +403,7 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
}
private void autoSelectProvider(String provider_main_url, boolean danger_on) {
+ ConfigHelper.saveSharedPref(ProviderItem.DANGER_ON, danger_on);
onItemSelected(getId(provider_main_url));
}
@@ -415,7 +425,16 @@ implements ProviderListFragment.Callbacks, NewProviderDialog.NewProviderDialogIn
startService(provider_API_command);
}
-
+
+ public void retrySetUpProvider() {
+ Intent provider_API_command = new Intent(this, ProviderAPI.class);
+
+ provider_API_command.setAction(ProviderAPI.SET_UP_PROVIDER);
+ provider_API_command.putExtra(ProviderAPI.RECEIVER_KEY, providerAPI_result_receiver);
+
+ startService(provider_API_command);
+ }
+
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.configuration_wizard_activity, menu);
diff --git a/src/se/leap/bitmaskclient/DownloadFailedDialog.java b/src/se/leap/bitmaskclient/DownloadFailedDialog.java
index 3ce101a6..72455b2f 100644
--- a/src/se/leap/bitmaskclient/DownloadFailedDialog.java
+++ b/src/se/leap/bitmaskclient/DownloadFailedDialog.java
@@ -17,6 +17,8 @@
package se.leap.bitmaskclient;
import se.leap.bitmaskclient.R;
+import se.leap.bitmaskclient.NewProviderDialog.NewProviderDialogInterface;
+import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
@@ -47,7 +49,13 @@ public class DownloadFailedDialog extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(reason_to_fail)
- .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+ .setPositiveButton(R.string.retry, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.dismiss();
+ interface_with_ConfigurationWizard.retrySetUpProvider();
+ }
+ })
+ .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
}
@@ -56,4 +64,21 @@ public class DownloadFailedDialog extends DialogFragment {
// Create the AlertDialog object and return it
return builder.create();
}
+
+ public interface DownloadFailedDialogInterface {
+ public void retrySetUpProvider();
+ }
+
+ DownloadFailedDialogInterface interface_with_ConfigurationWizard;
+
+ @Override
+ public void onAttach(Activity activity) {
+ super.onAttach(activity);
+ try {
+ interface_with_ConfigurationWizard = (DownloadFailedDialogInterface) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString()
+ + " must implement NoticeDialogListener");
+ }
+ }
}
diff --git a/src/se/leap/bitmaskclient/ProviderAPI.java b/src/se/leap/bitmaskclient/ProviderAPI.java
index 0070b307..5d049d42 100644
--- a/src/se/leap/bitmaskclient/ProviderAPI.java
+++ b/src/se/leap/bitmaskclient/ProviderAPI.java
@@ -116,12 +116,15 @@ public class ProviderAPI extends IntentService {
INCORRECTLY_DOWNLOADED_ANON_CERTIFICATE = 14
;
- public static boolean
+ private static boolean
CA_CERT_DOWNLOADED = false,
PROVIDER_JSON_DOWNLOADED = false,
EIP_SERVICE_JSON_DOWNLOADED = false
;
+ static private String last_provider_main_url;
+ static private boolean last_danger_on = false;
+
public ProviderAPI() {
super("ProviderAPI");
Log.v("ClassName", "Provider API");
@@ -425,21 +428,28 @@ public class ProviderAPI extends IntentService {
*/
private Bundle setUpProvider(Bundle task) {
int progress = 0;
- boolean danger_on = task.getBoolean(ProviderItem.DANGER_ON);
- String provider_main_url = task.getString(Provider.MAIN_URL);
+ Bundle current_download = new Bundle();
+
+ if(task != null && task.containsKey(ProviderItem.DANGER_ON) && task.containsKey(Provider.MAIN_URL)) {
+ last_danger_on = task.getBoolean(ProviderItem.DANGER_ON);
+ last_provider_main_url = task.getString(Provider.MAIN_URL);
+ CA_CERT_DOWNLOADED = PROVIDER_JSON_DOWNLOADED = EIP_SERVICE_JSON_DOWNLOADED = false;
+ }
- Bundle current_download = downloadCACert(provider_main_url, danger_on);
- if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
+ if(!CA_CERT_DOWNLOADED)
+ current_download = downloadCACert(last_provider_main_url, last_danger_on);
+ if(CA_CERT_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
broadcast_progress(progress++);
- //CA_CERT_DOWNLOADED = true;
- current_download = getAndSetProviderJson(provider_main_url);
- if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
+ CA_CERT_DOWNLOADED = true;
+ if(!PROVIDER_JSON_DOWNLOADED)
+ current_download = getAndSetProviderJson(last_provider_main_url);
+ if(PROVIDER_JSON_DOWNLOADED || (current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY))) {
broadcast_progress(progress++);
- //PROVIDER_JSON_DOWNLOADED = true;
+ PROVIDER_JSON_DOWNLOADED = true;
current_download = getAndSetEipServiceJson();
if(current_download.containsKey(RESULT_KEY) && current_download.getBoolean(RESULT_KEY)) {
broadcast_progress(progress++);
- //EIP_SERVICE_JSON_DOWNLOADED = true;
+ EIP_SERVICE_JSON_DOWNLOADED = true;
}
}
}
@@ -457,15 +467,18 @@ public class ProviderAPI extends IntentService {
String reason_to_fail = cert_string;
result.putString(ERRORS, reason_to_fail);
result.putBoolean(RESULT_KEY, false);
-
}
return result;
}
+ public static boolean caCertDownloaded() {
+ return CA_CERT_DOWNLOADED;
+ }
+
private boolean validCertificate(String cert_string) {
boolean result = false;
- if(!cert_string.isEmpty()) {
+ if(!ConfigHelper.checkErrorenousDownload(cert_string)) {
X509Certificate certCert = ConfigHelper.parseX509CertificateFromString(cert_string);
try {
Base64.encodeToString( certCert.getEncoded(), Base64.DEFAULT);
@@ -498,6 +511,10 @@ public class ProviderAPI extends IntentService {
}
+ public static boolean providerJsonDownloaded() {
+ return PROVIDER_JSON_DOWNLOADED;
+ }
+
private Bundle getAndSetEipServiceJson() {
Bundle result = new Bundle();
String eip_service_json_string = "";
@@ -518,6 +535,11 @@ public class ProviderAPI extends IntentService {
}
return result;
}
+
+ public static boolean eipServiceDownloaded() {
+ return EIP_SERVICE_JSON_DOWNLOADED;
+ }
+
/**
* Tries to download the contents of the provided url using commercially validated CA certificate from chosen provider.
*