summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/Dashboard.java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java70
1 files changed, 34 insertions, 36 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 4e6120ab..afe1a638 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -127,33 +127,28 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
case 91: // 0.6.0 without Bug #5999
case 101: // 0.8.0
if(!preferences.getString(Constants.KEY, "").isEmpty())
- updateEipService();
+ eip_fragment.updateEipService();
break;
}
} catch (NameNotFoundException e) {
Log.d(TAG, "Handle version didn't find any " + getPackageName() + " package");
}
}
-
- @SuppressLint("CommitPrefEdits")
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
- if ( resultCode == RESULT_OK ) {
- preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
- updateEipService();
-
- if (data.hasExtra(Provider.KEY)) {
- provider = data.getParcelableExtra(Provider.KEY);
- preferences.edit().putBoolean(Constants.PROVIDER_CONFIGURED, true).commit();
- preferences.edit().putString(Provider.MAIN_URL, provider.mainUrl().toString()).apply();
- preferences.edit().putString(Provider.KEY, provider.definition().toString()).apply();
- }
- buildDashboard(false);
- invalidateOptionsMenu();
- if (data.hasExtra(SessionDialog.TAG)) {
- sessionDialog(Bundle.EMPTY);
- }
+ if ( resultCode == RESULT_OK && data.hasExtra(Provider.KEY)) {
+ provider = data.getParcelableExtra(Provider.KEY);
+ providerToPreferences(provider);
+
+ buildDashboard(false);
+ invalidateOptionsMenu();
+ if (data.hasExtra(SessionDialog.TAG)) {
+ sessionDialog(Bundle.EMPTY);
+ }
+
+ preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
} else if (resultCode == RESULT_CANCELED && data.hasExtra(ACTION_QUIT)) {
finish();
} else
@@ -163,6 +158,13 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
}
+ @SuppressLint("CommitPrefEdits")
+ private void providerToPreferences(Provider provider) {
+ preferences.edit().putBoolean(Constants.PROVIDER_CONFIGURED, true).commit();
+ preferences.edit().putString(Provider.MAIN_URL, provider.mainUrl().toString()).apply();
+ preferences.edit().putString(Provider.KEY, provider.definition().toString()).apply();
+ }
+
private void configErrorDialog() {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(getAppContext());
alertBuilder.setTitle(getResources().getString(R.string.setup_error_title));
@@ -296,11 +298,14 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
providerApiCommand(Bundle.EMPTY, R.string.logout_message, ProviderAPI.LOG_OUT);
}
- private void downloadAuthedUserCertificate() {
- Bundle parameters = new Bundle();
- parameters.putString(ConfigurationWizard.TYPE_OF_CERTIFICATE, ConfigurationWizard.AUTHED_CERTIFICATE);
-
- providerApiCommand(parameters, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE);
+ protected void downloadVpnCertificate() {
+ boolean is_authenticated = !LeapSRPSession.getToken().isEmpty();
+ boolean allowed_anon = preferences.getBoolean(Constants.ALLOWED_ANON, false);
+ if(allowed_anon || is_authenticated)
+ providerApiCommand(Bundle.EMPTY, R.string.downloading_certificate_message, ProviderAPI.DOWNLOAD_CERTIFICATE);
+ else
+ sessionDialog(Bundle.EMPTY);
+
}
private Bundle bundleParameters(String username, String password) {
@@ -312,8 +317,8 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
return parameters;
}
- private void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) {
- if(eip_fragment != null) {
+ protected void providerApiCommand(Bundle parameters, int progressbar_message_resId, String providerApi_action) {
+ if(eip_fragment != null && progressbar_message_resId != 0) {
eip_fragment.progress_bar.setVisibility(ProgressBar.VISIBLE);
setStatusMessage(progressbar_message_resId);
}
@@ -322,7 +327,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
startService(command);
}
- protected Intent prepareProviderAPICommand(Bundle parameters, String action) {
+ private Intent prepareProviderAPICommand(Bundle parameters, String action) {
providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler());
providerAPI_result_receiver.setReceiver(this);
@@ -371,7 +376,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
updateViewHidingProgressBar(resultCode);
- downloadAuthedUserCertificate();
+ downloadVpnCertificate();
} else if(resultCode == ProviderAPI.FAILED_LOGIN) {
updateViewHidingProgressBar(resultCode);
sessionDialog(resultData);
@@ -386,16 +391,15 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
setResult(RESULT_CANCELED);
} else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE) {
updateViewHidingProgressBar(resultCode);
- updateEipService();
+ eip_fragment.updateEipService();
setResult(RESULT_OK);
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE) {
updateViewHidingProgressBar(resultCode);
setResult(RESULT_CANCELED);
}
else if(resultCode == ProviderAPI.CORRECTLY_DOWNLOADED_EIP_SERVICE) {
+ eip_fragment.updateEipService();
setResult(RESULT_OK);
-
- updateEipService();
} else if(resultCode == ProviderAPI.INCORRECTLY_DOWNLOADED_EIP_SERVICE) {
setResult(RESULT_CANCELED);
}
@@ -407,12 +411,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
invalidateOptionsMenu();
}
- private void updateEipService() {
- Intent updateEIP = new Intent(getApplicationContext(), EIP.class);
- updateEIP.setAction(Constants.ACTION_UPDATE_EIP_SERVICE);
- startService(updateEIP);
- }
-
private void changeStatusMessage(final int previous_result_code) {
ResultReceiver status_receiver = new ResultReceiver(new Handler()){
protected void onReceiveResult(int resultCode, Bundle resultData){