diff options
author | Parménides GV <parmegv@sdf.org> | 2015-01-14 17:18:19 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2015-01-19 16:00:06 +0100 |
commit | 744272dd1d43913c8112d1dedcb0b5a9023c491e (patch) | |
tree | 365d65a9a6929f3c5a71eb779c3dfd6671c1298d | |
parent | b3ea137781af2eacd0a5b75f24030cfbc3c9d962 (diff) |
Connect if logged in after turning switch on
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/Dashboard.java | 49 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/EipFragment.java | 20 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/EIP.java | 5 |
3 files changed, 42 insertions, 32 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index 94be7cd1..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)); @@ -389,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); } @@ -410,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){ diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java index bbcaa577..b2898249 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java @@ -49,6 +49,7 @@ public class EipFragment extends Fragment implements Observer { private static EIPReceiver mEIPReceiver; private static EipStatus eip_status; private boolean is_starting_to_connect; + private boolean wants_to_connect; @Override public void onAttach(Activity activity) { @@ -127,7 +128,7 @@ public class EipFragment extends Fragment implements Observer { if(canStartEIP()) startEipFromScratch(); else if(canLogInToStartEIP()) { - Log.d(TAG, "Can Log In to start EIP"); + wants_to_connect = true; Bundle bundle = new Bundle(); bundle.putBoolean(IS_PENDING, true); dashboard.sessionDialog(bundle); @@ -176,6 +177,7 @@ public class EipFragment extends Fragment implements Observer { } public void startEipFromScratch() { + wants_to_connect = false; is_starting_to_connect = true; progress_bar.setVisibility(View.VISIBLE); eip_switch.setVisibility(View.VISIBLE); @@ -205,6 +207,10 @@ public class EipFragment extends Fragment implements Observer { eipCommand(Constants.ACTION_STOP_EIP); } + + protected void updateEipService() { + eipCommand(Constants.ACTION_UPDATE_EIP_SERVICE); + } /** * Send a command to EIP @@ -339,7 +345,17 @@ public class EipFragment extends Fragment implements Observer { dashboard.downloadVpnCertificate(); break; } - } + } else if (request.equals(Constants.ACTION_UPDATE_EIP_SERVICE)) { + switch (resultCode) { + case Activity.RESULT_OK: + if(wants_to_connect) + startEipFromScratch(); + break; + case Activity.RESULT_CANCELED: + handleNewState(eip_status); + break; + } + } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index a5cc817a..3b72a486 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -64,10 +64,8 @@ public final class EIP extends IntentService { context = getApplicationContext(); preferences = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE); eip_definition = eipDefinitionFromPreferences(); - if(gateways_manager.isEmpty()) { - gateways_manager = new GatewaysManager(context, preferences); + if(gateways_manager.isEmpty()) gatewaysFromPreferences(); - } } @Override @@ -179,6 +177,7 @@ public final class EIP extends IntentService { private void gatewaysFromPreferences() { String gateways_string = preferences.getString(Gateway.TAG, ""); + gateways_manager = new GatewaysManager(context, preferences); gateways_manager.addFromString(gateways_string); preferences.edit().remove(Gateway.TAG).apply(); } |