summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-15 11:30:28 +0100
committerParménides GV <parmegv@sdf.org>2014-12-15 11:30:28 +0100
commit582758a34f6fd82ad1071bf9a196f0fa048689e8 (patch)
tree4df139d81922e4d3eebd5191996e27ff2c203673 /app/src/main/java/se/leap/bitmaskclient/Dashboard.java
parent97aded26654ede8204a313dd6967b678a72a2a10 (diff)
Working on Android 5.
Beware! https://code.google.com/p/android/issues/detail?id=80074: Wrong VpnService.prepare() behavior after re-installation of the VPN app on Android 5.0 "The following steps will cause incorrect behavior of the VpnService.prepare(): 1. Establish VPN connection using any VPN app. VpnService.prepare() will return an intent for the "Connection request" system activity. Once user accepts it, VPN connection can be established successfully. 2. Uninstall VPN app. 3. Re-install the same VPN app. 4. Now VpnService.prepare() returns null, as if the VPN service has been already prepared. 5. Now VpnService.protect() returns false and VPN connection fails. Device reboot is needed in order to be able to establish VPN connection again."
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/Dashboard.java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java72
1 files changed, 42 insertions, 30 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 3ecf5e52..862086eb 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -16,6 +16,7 @@
*/
package se.leap.bitmaskclient;
+import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DialogFragment;
@@ -34,6 +35,7 @@ import android.view.MenuItem;
import android.widget.ProgressBar;
import android.widget.TextView;
+import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
import org.json.JSONObject;
@@ -48,7 +50,7 @@ import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
/**
- * The main user facing Activity of LEAP Android, consisting of status, controls,
+ * The main user facing Activity of Bitmask Android, consisting of status, controls,
* and access to preferences.
*
* @author Sean Leonard <meanderingcode@aetherislands.net>
@@ -81,7 +83,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
public ProviderAPIResultReceiver providerAPI_result_receiver;
@Override
- protected void onSaveInstanceState(Bundle outState) {
+ protected void onSaveInstanceState(@NotNull Bundle outState) {
if(provider != null)
outState.putParcelable(Provider.KEY, provider);
super.onSaveInstanceState(outState);
@@ -99,24 +101,36 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
fragment_manager = new FragmentManagerEnhanced(getFragmentManager());
handleVersion();
- if(savedInstanceState != null)
- provider = savedInstanceState.getParcelable(Provider.KEY);
- if(provider == null && preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false))
- try {
- provider = new Provider(new URL(preferences.getString(Provider.MAIN_URL, "")));
- provider.define(new JSONObject(preferences.getString(Provider.KEY, "")));
- } catch (MalformedURLException e) {
- e.printStackTrace();
- } catch (JSONException e) {
- e.printStackTrace();
- }
-
+ provider = getSavedProvider(savedInstanceState);
if (provider == null || provider.getName().isEmpty())
startActivityForResult(new Intent(this,ConfigurationWizard.class),CONFIGURE_LEAP);
else
buildDashboard(getIntent().getBooleanExtra(ON_BOOT, false));
}
+ private Provider getSavedProvider(Bundle savedInstanceState) {
+ Provider provider = null;
+ if(savedInstanceState != null)
+ provider = savedInstanceState.getParcelable(Provider.KEY);
+ else if(preferences.getBoolean(Constants.PROVIDER_CONFIGURED, false))
+ provider = getSavedProviderFromSharedPreferences();
+
+ return provider;
+ }
+
+ private Provider getSavedProviderFromSharedPreferences() {
+ Provider provider = null;
+ try {
+ provider = new Provider(new URL(preferences.getString(Provider.MAIN_URL, "")));
+ provider.define(new JSONObject(preferences.getString(Provider.KEY, "")));
+ } catch (MalformedURLException | JSONException e) {
+ e.printStackTrace();
+ }
+
+ return provider;
+ }
+
+
private void handleVersion() {
try {
int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
@@ -140,13 +154,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
}
+ @SuppressLint("CommitPrefEdits")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
Log.d(TAG, "onActivityResult: requestCode = " + requestCode);
if ( requestCode == CONFIGURE_LEAP || requestCode == SWITCH_PROVIDER) {
- // It should be equivalent: if ( (requestCode == CONFIGURE_LEAP) || (data!= null && data.hasExtra(STOP_FIRST))) {
if ( resultCode == RESULT_OK ) {
- preferences.edit().putInt(Constants.PARSED_SERIAL, 0).apply();
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
updateEipService();
@@ -205,7 +218,6 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
ButterKnife.inject(this);
provider_name.setText(provider.getDomain());
-
if ( provider.hasEIP()){
fragment_manager.removePreviousFragment(EipServiceFragment.TAG);
@@ -412,16 +424,16 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
@Override
public void onReceiveResult(int resultCode, Bundle resultData) {
Log.d(TAG, "onReceiveResult");
- if(resultCode == ProviderAPI.SRP_REGISTRATION_SUCCESSFUL) {
+ if(resultCode == ProviderAPI.SUCCESSFUL_SIGNUP) {
String username = resultData.getString(SessionDialog.USERNAME);
String password = resultData.getString(SessionDialog.PASSWORD);
logIn(username, password);
- } else if(resultCode == ProviderAPI.SRP_REGISTRATION_FAILED) {
+ } else if(resultCode == ProviderAPI.FAILED_SIGNUP) {
changeStatusMessage(resultCode);
hideProgressBar();
signUpDialog(resultData);
- } else if(resultCode == ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL) {
+ } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGIN) {
changeStatusMessage(resultCode);
hideProgressBar();
@@ -431,12 +443,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).apply();
downloadAuthedUserCertificate();
- } else if(resultCode == ProviderAPI.SRP_AUTHENTICATION_FAILED) {
+ } else if(resultCode == ProviderAPI.FAILED_LOGIN) {
changeStatusMessage(resultCode);
hideProgressBar();
logInDialog(resultData);
- } else if(resultCode == ProviderAPI.LOGOUT_SUCCESSFUL) {
+ } else if(resultCode == ProviderAPI.SUCCESSFUL_LOGOUT) {
changeStatusMessage(resultCode);
hideProgressBar();
@@ -477,7 +489,7 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
}
}
};
- updateEIP.putExtra(Constants.RECEIVER_TAG, receiver);
+ //updateEIP.putExtra(Constants.RECEIVER_TAG, receiver);
startService(updateEIP);
}
@@ -491,11 +503,11 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
if (resultCode == Activity.RESULT_OK){
switch(previous_result_code){
- case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
- case ProviderAPI.SRP_AUTHENTICATION_FAILED: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
+ case ProviderAPI.SUCCESSFUL_LOGIN: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
+ case ProviderAPI.FAILED_LOGIN: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.authed_secured_status); break;
case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.incorrectly_downloaded_certificate_message); break;
- case ProviderAPI.LOGOUT_SUCCESSFUL: eip_fragment.status_message.setText(R.string.logged_out_message); break;
+ case ProviderAPI.SUCCESSFUL_LOGOUT: eip_fragment.status_message.setText(R.string.logged_out_message); break;
case ProviderAPI.LOGOUT_FAILED: eip_fragment.status_message.setText(R.string.log_out_failed_message); break;
}
@@ -504,12 +516,12 @@ public class Dashboard extends Activity implements SessionDialog.SessionDialogIn
switch(previous_result_code){
- case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
- case ProviderAPI.SRP_AUTHENTICATION_FAILED: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
- case ProviderAPI.SRP_REGISTRATION_FAILED: eip_fragment.status_message.setText(R.string.registration_failed_message); break;
+ case ProviderAPI.SUCCESSFUL_LOGIN: eip_fragment.status_message.setText(R.string.succesful_authentication_message); break;
+ case ProviderAPI.FAILED_LOGIN: eip_fragment.status_message.setText(R.string.authentication_failed_message); break;
+ case ProviderAPI.FAILED_SIGNUP: eip_fragment.status_message.setText(R.string.registration_failed_message); break;
case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: break;
case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eip_fragment.status_message.setText(R.string.incorrectly_downloaded_certificate_message); break;
- case ProviderAPI.LOGOUT_SUCCESSFUL: eip_fragment.status_message.setText(R.string.logged_out_message); break;
+ case ProviderAPI.SUCCESSFUL_LOGOUT: eip_fragment.status_message.setText(R.string.logged_out_message); break;
case ProviderAPI.LOGOUT_FAILED: eip_fragment.status_message.setText(R.string.log_out_failed_message); break;
}
}