diff options
author | Parménides GV <parmegv@sdf.org> | 2014-11-19 20:20:31 +0100 |
---|---|---|
committer | Parménides GV <parmegv@sdf.org> | 2014-11-26 13:02:05 +0100 |
commit | 50949530a8453e1aa62c0ff277849d6f83fe0f76 (patch) | |
tree | b338a18a838c7617c25af33be6e8d8daa03a4a89 /app/src/main | |
parent | bc3af9b45a962721002e249806e0e9edd01e3e8b (diff) |
Eip status messages refactored.
Diffstat (limited to 'app/src/main')
6 files changed, 140 insertions, 166 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java index b139f73f..fe3c3f23 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java +++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java @@ -57,7 +57,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf private EipServiceFragment eipFragment; private ProgressBar mProgressBar; - private TextView eipStatus; + private TextView status_message; public ProviderAPIResultReceiver providerAPI_result_receiver; private static Provider provider; @@ -116,28 +116,29 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf super.onPause(); } - @Override - protected void onActivityResult(int requestCode, int resultCode, final Intent data){ - 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).commit(); - preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).commit(); - Intent updateEIP = new Intent(getApplicationContext(), EIP.class); - updateEIP.setAction(Constants.ACTION_UPDATE_EIP_SERVICE); - startService(updateEIP); - buildDashboard(false); - invalidateOptionsMenu(); - if(data != null && data.hasExtra(LogInDialog.TAG)) { - View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0); - logInDialog(Bundle.EMPTY); - } - } else if(resultCode == RESULT_CANCELED && (data == null || data.hasExtra(ACTION_QUIT))) { - finish(); - } else - configErrorDialog(); + @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).commit(); + preferences.edit().putBoolean(Constants.AUTHED_EIP, authed_eip).commit(); + updateEipService(); + buildDashboard(false); + invalidateOptionsMenu(); + if(data != null && data.hasExtra(LogInDialog.TAG)) { + View view = ((ViewGroup)findViewById(android.R.id.content)).getChildAt(0); + logInDialog(Bundle.EMPTY); } + } else if(resultCode == RESULT_CANCELED && (data == null || data.hasExtra(ACTION_QUIT))) { + finish(); + } else + configErrorDialog(); + } else if(requestCode == 33) { + EipStatus.getInstance().setConnectedOrDisconnected(); } + } /** * Dialog shown when encountering a configuration error. Such errors require @@ -273,7 +274,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf private Intent prepareProviderAPICommand() { mProgressBar = (ProgressBar) findViewById(R.id.eipProgress); - eipStatus = (TextView) findViewById(R.id.eipStatus); + status_message = (TextView) findViewById(R.id.status_message); providerAPI_result_receiver = new ProviderAPIResultReceiver(new Handler()); providerAPI_result_receiver.setReceiver(this); @@ -307,7 +308,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf parameters.putString(SessionDialogInterface.PASSWORD, password); mProgressBar.setVisibility(ProgressBar.VISIBLE); - eipStatus.setText(R.string.authenticating_message); + status_message.setText(R.string.authenticating_message); provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters); provider_API_command.setAction(ProviderAPI.SRP_AUTH); @@ -331,8 +332,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf if(mProgressBar == null) mProgressBar = (ProgressBar) findViewById(R.id.eipProgress); mProgressBar.setVisibility(ProgressBar.VISIBLE); - if(eipStatus == null) eipStatus = (TextView) findViewById(R.id.eipStatus); - eipStatus.setText(R.string.logout_message); + if(status_message == null) status_message = (TextView) findViewById(R.id.status_message); + status_message.setText(R.string.logout_message); provider_API_command.setAction(ProviderAPI.LOG_OUT); startService(provider_API_command); @@ -362,7 +363,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf parameters.putString(SessionDialogInterface.PASSWORD, password); mProgressBar.setVisibility(ProgressBar.VISIBLE); - eipStatus.setText(R.string.signingup_message); + status_message.setText(R.string.signingup_message); provider_API_command.putExtra(ProviderAPI.PARAMETERS, parameters); provider_API_command.setAction(ProviderAPI.SRP_REGISTER); @@ -390,6 +391,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf @Override public void onReceiveResult(int resultCode, Bundle resultData) { + Log.d(TAG, "onReceiveResult"); if(resultCode == ProviderAPI.SRP_REGISTRATION_SUCCESSFUL) { String username = resultData.getString(SessionDialogInterface.USERNAME); String password = resultData.getString(SessionDialogInterface.PASSWORD); @@ -466,17 +468,17 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf protected void onReceiveResult(int resultCode, Bundle resultData){ super.onReceiveResult(resultCode, resultData); String request = resultData.getString(Constants.REQUEST_TAG); - if(eipStatus == null) eipStatus = (TextView) findViewById(R.id.eipStatus); + if(status_message == null) status_message = (TextView) findViewById(R.id.status_message); if (request.equalsIgnoreCase(Constants.ACTION_IS_EIP_RUNNING)){ if (resultCode == Activity.RESULT_OK){ switch(previous_result_code){ - case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eipStatus.setText(R.string.succesful_authentication_message); break; - case ProviderAPI.SRP_AUTHENTICATION_FAILED: eipStatus.setText(R.string.authentication_failed_message); break; - case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.authed_secured_status); break; - case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.incorrectly_downloaded_certificate_message); break; - case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.logged_out_message); break; - case ProviderAPI.LOGOUT_FAILED: eipStatus.setText(R.string.log_out_failed_message); break; + case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: status_message.setText(R.string.succesful_authentication_message); break; + case ProviderAPI.SRP_AUTHENTICATION_FAILED: status_message.setText(R.string.authentication_failed_message); break; + case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: status_message.setText(R.string.authed_secured_status); break; + case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: status_message.setText(R.string.incorrectly_downloaded_certificate_message); break; + case ProviderAPI.LOGOUT_SUCCESSFUL: status_message.setText(R.string.logged_out_message); break; + case ProviderAPI.LOGOUT_FAILED: status_message.setText(R.string.log_out_failed_message); break; } } @@ -484,13 +486,13 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf switch(previous_result_code){ - case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: eipStatus.setText(R.string.succesful_authentication_message); break; - case ProviderAPI.SRP_AUTHENTICATION_FAILED: eipStatus.setText(R.string.authentication_failed_message); break; - case ProviderAPI.SRP_REGISTRATION_FAILED: eipStatus.setText(R.string.registration_failed_message); break; + case ProviderAPI.SRP_AUTHENTICATION_SUCCESSFUL: status_message.setText(R.string.succesful_authentication_message); break; + case ProviderAPI.SRP_AUTHENTICATION_FAILED: status_message.setText(R.string.authentication_failed_message); break; + case ProviderAPI.SRP_REGISTRATION_FAILED: status_message.setText(R.string.registration_failed_message); break; case ProviderAPI.CORRECTLY_DOWNLOADED_CERTIFICATE: break; - case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: eipStatus.setText(R.string.incorrectly_downloaded_certificate_message); break; - case ProviderAPI.LOGOUT_SUCCESSFUL: eipStatus.setText(R.string.logged_out_message); break; - case ProviderAPI.LOGOUT_FAILED: eipStatus.setText(R.string.log_out_failed_message); break; + case ProviderAPI.INCORRECTLY_DOWNLOADED_CERTIFICATE: status_message.setText(R.string.incorrectly_downloaded_certificate_message); break; + case ProviderAPI.LOGOUT_SUCCESSFUL: status_message.setText(R.string.logged_out_message); break; + case ProviderAPI.LOGOUT_FAILED: status_message.setText(R.string.log_out_failed_message); break; } } } diff --git a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java index 675619ca..7dfb628d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java @@ -17,70 +17,70 @@ import java.util.*; public class EipServiceFragment extends Fragment implements Observer, CompoundButton.OnCheckedChangeListener { - protected static final String IS_EIP_PENDING = "is_eip_pending"; + protected static final String IS_EIP_PENDING = "is_eip_pending"; public static final String START_ON_BOOT = "start on boot"; - private View eipFragment; - private static Switch eipSwitch; - private View eipDetail; - private TextView eipStatus; - private EipStatus eip_status; + private View eipFragment; + private static Switch eipSwitch; + private View eipDetail; + private TextView status_message; private static EIPReceiver mEIPReceiver; - + private static EipStatus eip_status; public static String TAG = "se.leap.bitmask.EipServiceFragment"; - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + eip_status = EipStatus.getInstance(); + eip_status.addObserver(this); + mEIPReceiver = new EIPReceiver(new Handler()); + + if (savedInstanceState != null && savedInstanceState.getBoolean(IS_EIP_PENDING)) + eip_status.setConnecting(); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { - eipFragment = inflater.inflate(R.layout.eip_service_fragment, container, false); - eipDetail = ((RelativeLayout) eipFragment.findViewById(R.id.eipDetail)); - eipDetail.setVisibility(View.VISIBLE); + eipFragment = inflater.inflate(R.layout.eip_service_fragment, container, false); + eipDetail = ((RelativeLayout) eipFragment.findViewById(R.id.eipDetail)); + eipDetail.setVisibility(View.VISIBLE); - View eipSettings = eipFragment.findViewById(R.id.eipSettings); - eipSettings.setVisibility(View.GONE); // FIXME too! + View eipSettings = eipFragment.findViewById(R.id.eipSettings); + eipSettings.setVisibility(View.GONE); // FIXME too! - if (EIP.mIsStarting) - eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); + if (eip_status.isConnecting()) + eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); - eipStatus = (TextView) eipFragment.findViewById(R.id.eipStatus); + status_message = (TextView) eipFragment.findViewById(R.id.status_message); - eipSwitch = (Switch) eipFragment.findViewById(R.id.eipSwitch); - eipSwitch.setOnCheckedChangeListener(this); + eipSwitch = (Switch) eipFragment.findViewById(R.id.eipSwitch); + eipSwitch.setOnCheckedChangeListener(this); - if(getArguments() != null && getArguments().containsKey(START_ON_BOOT) && getArguments().getBoolean(START_ON_BOOT)) - startEipFromScratch(); + if(getArguments() != null && getArguments().containsKey(START_ON_BOOT) && getArguments().getBoolean(START_ON_BOOT)) + startEipFromScratch(); - return eipFragment; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - EipStatus.getInstance().addObserver(this); - mEIPReceiver = new EIPReceiver(new Handler()); - - if (savedInstanceState != null) - EIP.mIsStarting = savedInstanceState.getBoolean(IS_EIP_PENDING); - } + return eipFragment; + } - @Override - public void onResume() { - super.onResume(); - eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY); - } + @Override + public void onResume() { + super.onResume(); + eipCommand(Constants.ACTION_CHECK_CERT_VALIDITY); + } - @Override - public void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(IS_EIP_PENDING, EIP.mIsStarting); - } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(IS_EIP_PENDING, eip_status.isConnecting()); + } protected void saveEipStatus() { boolean eip_is_on = false; - Log.d("bitmask", "saveEipStatus"); + Log.d(TAG, "saveEipStatus"); if(eipSwitch.isChecked()) { eip_is_on = true; } @@ -88,6 +88,7 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu if(getActivity() != null) Dashboard.preferences.edit().putBoolean(Dashboard.START_ON_BOOT, eip_is_on).commit(); } + @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.equals(eipSwitch)){ @@ -117,7 +118,7 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu private boolean canStartEIP() { boolean certificateExists = !Dashboard.preferences.getString(Constants.CERTIFICATE, "").isEmpty(); boolean isAllowedAnon = Dashboard.preferences.getBoolean(Constants.ALLOWED_ANON, false); - return (isAllowedAnon || certificateExists) && !EIP.mIsStarting && !EIP.isConnected(); + return (isAllowedAnon || certificateExists) && !eip_status.isConnected(); } private boolean canLogInToStartEIP() { @@ -125,14 +126,13 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu boolean isLoggedIn = !LeapSRPSession.getToken().isEmpty(); Log.d(TAG, "Allow registered? " + isAllowedRegistered); Log.d(TAG, "Is logged in? " + isLoggedIn); - return isAllowedRegistered && !isLoggedIn && !EIP.mIsStarting && !EIP.isConnected(); + return isAllowedRegistered && !isLoggedIn && !eip_status.isConnecting() && !eip_status.isConnected(); } private void handleSwitchOff() { - if(EIP.mIsStarting) { + if(eip_status.isConnecting()) { askPendingStartCancellation(); - } else if(EIP.isConnected()) { - Log.d(TAG, "Stopping EIP"); + } else if(eip_status.isConnected()) { stopEIP(); } } @@ -150,7 +150,6 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu .setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - Log.d(TAG, "askPendingStartCancellation checks the switch to true"); eipSwitch.setChecked(true); } }) @@ -158,13 +157,12 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu } public void startEipFromScratch() { - EIP.mIsStarting = true; + eip_status.setConnecting(); eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); String status = getResources().getString(R.string.eip_status_start_pending); setEipStatus(status); if(!eipSwitch.isChecked()) { - Log.d(TAG, "startEipFromScratch checks the switch to true"); eipSwitch.setChecked(true); saveEipStatus(); } @@ -172,7 +170,6 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu } protected void stopEIP() { - EIP.mIsStarting = false; View eipProgressBar = getActivity().findViewById(R.id.eipProgress); if(eipProgressBar != null) eipProgressBar.setVisibility(View.GONE); @@ -199,56 +196,42 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu @Override public void update (Observable observable, Object data) { if(observable instanceof EipStatus) { + this.eip_status = (EipStatus) observable; final EipStatus eip_status = (EipStatus) observable; - EipStatus previous_status = eip_status.getPreviousStatus(); - boolean isNewLevel = eip_status.getLevel() != previous_status.getLevel(); - if(!eip_status.wantsToDisconnect() && (isNewLevel || eip_status.isConnected())) { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - handleNewState(eip_status); - } - }); - } else if(eip_status.wantsToDisconnect() && eip_status.isConnected()) { - setDisconnectedUI(); - // EIP.lastConnectionStatusLevel = VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED; - // updateState(state, logmessage, localizedResId, level); - } + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + handleNewState(eip_status); + } + }); } } private void handleNewState(EipStatus eip_status) { final String state = eip_status.getState(); - final String logmessage = eip_status.getLogMessage(); - final int localizedResId = eip_status.getLocalizedResId(); - final VpnStatus.ConnectionStatus level = eip_status.getLevel(); - if (level == VpnStatus.ConnectionStatus.LEVEL_CONNECTED) + if(eip_status.wantsToDisconnect()) + setDisconnectedUI(); + else if (eip_status.isConnected()) setConnectedUI(); else if (eip_status.isDisconnected() && !eip_status.isConnecting()) setDisconnectedUI(); - else if (level == VpnStatus.ConnectionStatus.LEVEL_CONNECTING_NO_SERVER_REPLY_YET) - setNoServerReplyUI(localizedResId, logmessage); - else if (level == VpnStatus.ConnectionStatus.LEVEL_CONNECTING_SERVER_REPLIED) - setServerReplyUI(state, localizedResId, logmessage); + else + setInProgressUI(eip_status); } private void setConnectedUI() { hideProgressBar(); - String status = getString(R.string.eip_state_connected); - setEipStatus(status); adjustSwitch(); + setEipStatus(getString(R.string.eip_state_connected)); } private void setDisconnectedUI(){ hideProgressBar(); - - String status = getString(R.string.eip_state_not_connected); - setEipStatus(status); adjustSwitch(); + setEipStatus(getString(R.string.eip_state_not_connected)); } private void adjustSwitch() { - EipStatus eip_status = EipStatus.getInstance(); if(eip_status.isConnected()) { if(!eipSwitch.isChecked()) { eipSwitch.setChecked(true); @@ -260,25 +243,18 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu } } - private void setNoServerReplyUI(int localizedResId, String logmessage) { - if(eipStatus != null) { - String prefix = getString(localizedResId); - setEipStatus(prefix + " " + logmessage); - } - } - - private void setServerReplyUI(String state, int localizedResId, String logmessage) { - if(eipStatus != null) - if(state.equals("AUTH") || state.equals("GET_CONFIG")) { - String prefix = getString(localizedResId); - setEipStatus(prefix + " " + logmessage); - } + private void setInProgressUI(EipStatus eip_status) { + int localizedResId = eip_status.getLocalizedResId(); + String logmessage = eip_status.getLogMessage(); + String prefix = getString(localizedResId); + + setEipStatus(prefix + " " + logmessage); } protected void setEipStatus(String status) { - if(eipStatus == null) - eipStatus = (TextView) getActivity().findViewById(R.id.eipStatus); - eipStatus.setText(status); + if(status_message == null) + status_message = (TextView) getActivity().findViewById(R.id.status_message); + status_message.setText(status); } private void hideProgressBar() { @@ -319,7 +295,6 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu Log.d(TAG, "Action start eip = Result OK"); checked = true; eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE); - EIP.mIsStarting = false; break; case Activity.RESULT_CANCELED: checked = false; @@ -329,8 +304,10 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu } else if (request == Constants.ACTION_STOP_EIP) { switch (resultCode){ case Activity.RESULT_OK: - checked = false; - break; + Intent disconnect_vpn = new Intent(getActivity(), DisconnectVPN.class); + getActivity().startActivityForResult(disconnect_vpn, 33); + eip_status.setDisconnecting(); + break; case Activity.RESULT_CANCELED: checked = true; break; @@ -388,7 +365,5 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu public void checkEipSwitch(boolean checked) { eipSwitch.setChecked(checked); - // Log.d(TAG, "checkEipSwitch"); - // onCheckedChanged(eipSwitch, checked); } } 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 97ef485a..577f42a3 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -57,10 +57,6 @@ public final class EIP extends IntentService { private static ProfileManager profile_manager; private static Gateway activeGateway = null; - public static VpnStatus.ConnectionStatus lastConnectionStatusLevel; - public static boolean mIsDisconnecting = false; - public static boolean mIsStarting = false; - public EIP(){ super("LEAPEIP"); } @@ -133,16 +129,13 @@ public final class EIP extends IntentService { * if there is no bound service. Sends a message to the requesting ResultReceiver. */ private void stopEIP() { - if(isConnected()) { - Intent disconnect_vpn = new Intent(this, DisconnectVPN.class); - disconnect_vpn.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(disconnect_vpn); - mIsDisconnecting = true; - lastConnectionStatusLevel = VpnStatus.ConnectionStatus.UNKNOWN_LEVEL; // Wait for the decision of the user - Log.d(TAG, "mIsDisconnecting = true"); - } + EipStatus eip_status = EipStatus.getInstance(); + Log.d(TAG, "stopEip(): eip is connected? " + eip_status.isConnected()); + int result_code = Activity.RESULT_CANCELED; + if(eip_status.isConnected()) + result_code = Activity.RESULT_OK; - tellToReceiver(ACTION_STOP_EIP, Activity.RESULT_OK); + tellToReceiver(ACTION_STOP_EIP, result_code); } private void tellToReceiver(String action, int resultCode) { @@ -160,17 +153,12 @@ public final class EIP extends IntentService { */ private void isRunning() { - int resultCode = (isConnected()) ? + EipStatus eip_status = EipStatus.getInstance(); + int resultCode = (eip_status.isConnected()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED; tellToReceiver(ACTION_IS_EIP_RUNNING, resultCode); } - - public static boolean isConnected() { - return lastConnectionStatusLevel != null - && lastConnectionStatusLevel.equals(VpnStatus.ConnectionStatus.LEVEL_CONNECTED) - && !mIsDisconnecting; - } /** * Loads eip-service.json from SharedPreferences and calls {@link updateGateways()} diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java index c58650ba..ee14f2db 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java @@ -53,6 +53,8 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { current_status.setLocalizedResId(localizedResId); current_status.setLevel(level); current_status.setChanged(); + if(isConnected() || isDisconnected()) + setConnectedOrDisconnected(); Log.d(TAG, "update state with level " + level); current_status.notifyObservers(); } @@ -74,7 +76,7 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { } public boolean isDisconnected() { - return level == VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED || level == VpnStatus.ConnectionStatus.LEVEL_AUTH_FAILED; + return level == VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED; } public void setConnecting() { @@ -83,11 +85,18 @@ public class EipStatus extends Observable implements VpnStatus.StateListener { wants_to_disconnect = false; } + public void setConnectedOrDisconnected() { + is_connecting = false; + is_disconnecting = false; + wants_to_disconnect = false; + current_status.setChanged(); + current_status.notifyObservers(); + } + public void setDisconnecting() { is_disconnecting = true; is_connecting = false; wants_to_disconnect = false; - level = VpnStatus.ConnectionStatus.UNKNOWN_LEVEL; // Wait for the decision of the user } public void setWantsToDisconnect() { diff --git a/app/src/main/res/layout-xlarge/eip_service_fragment.xml b/app/src/main/res/layout-xlarge/eip_service_fragment.xml index e5c7f23d..c6ac96a9 100644 --- a/app/src/main/res/layout-xlarge/eip_service_fragment.xml +++ b/app/src/main/res/layout-xlarge/eip_service_fragment.xml @@ -61,7 +61,7 @@ android:src="@drawable/ic_sysbar_quicksettings" /> <TextView - android:id="@+id/eipStatus" + android:id="@+id/status_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" diff --git a/app/src/main/res/layout/eip_service_fragment.xml b/app/src/main/res/layout/eip_service_fragment.xml index 5992a873..65aa4aa8 100644 --- a/app/src/main/res/layout/eip_service_fragment.xml +++ b/app/src/main/res/layout/eip_service_fragment.xml @@ -58,7 +58,7 @@ android:src="@drawable/ic_sysbar_quicksettings" /> <TextView - android:id="@+id/eipStatus" + android:id="@+id/status_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" |