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/java/se/leap/bitmaskclient/eip | |
parent | bc3af9b45a962721002e249806e0e9edd01e3e8b (diff) |
Eip status messages refactored.
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/eip')
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/EIP.java | 28 | ||||
-rw-r--r-- | app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java | 13 |
2 files changed, 19 insertions, 22 deletions
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() { |