summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-11-22 00:10:46 +0100
committerParménides GV <parmegv@sdf.org>2014-11-27 17:49:56 +0100
commite4d4c07be386f809a8ac028df8146916fc0f7597 (patch)
tree201e711ed102580587c8c934bf1acecd1c6db842 /app
parent2681e877c6c2e871247cf5e42269d1b867422f1f (diff)
EipStatus detects and notifies changes by itself.
Initial status message is "not connected", rather than "unknown".
Diffstat (limited to 'app')
-rw-r--r--app/src/main/AndroidManifest.xml4
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/Dashboard.java9
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java31
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/LogInDialog.java3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java3
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java5
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java29
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java2
-rw-r--r--app/src/main/res/layout-xlarge/eip_service_fragment.xml2
-rw-r--r--app/src/main/res/layout/eip_service_fragment.xml2
10 files changed, 52 insertions, 38 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 61f2a63b..7d1063ef 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -62,7 +62,9 @@
</receiver>
<activity
- android:name="se.leap.bitmaskclient.eip.VoidVpnLauncher" />
+ android:name="se.leap.bitmaskclient.eip.VoidVpnLauncher"
+ android:theme="@android:style/Theme.NoDisplay" />
+
<activity
android:theme="@android:style/Theme.DeviceDefault.Light.Dialog"
android:name="de.blinkt.openvpn.activities.DisconnectVPN" />
diff --git a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
index 4bebf14a..4f6c6285 100644
--- a/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
+++ b/app/src/main/java/se/leap/bitmaskclient/Dashboard.java
@@ -134,7 +134,7 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
finish();
} else
configErrorDialog();
- } else if(requestCode == 33) {
+ } else if(requestCode == EIP.DISCONNECT) {
EipStatus.getInstance().setConnectedOrDisconnected();
}
}
@@ -317,13 +317,8 @@ public class Dashboard extends Activity implements LogInDialog.LogInDialogInterf
startService(provider_API_command);
}
- public void cancelAuthedEipOn() {
- EipServiceFragment eipFragment = (EipServiceFragment) getFragmentManager().findFragmentByTag(EipServiceFragment.TAG);
- eipFragment.checkEipSwitch(false);
- }
-
public void cancelLoginOrSignup() {
- hideProgressBar();
+ EipStatus.getInstance().setConnectedOrDisconnected();
}
/**
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
index 0cdc8c75..f29d1338 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipServiceFragment.java
@@ -23,7 +23,7 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
protected static final String IS_CONNECTED = TAG + ".is_connected";
protected static final String STATUS_MESSAGE = TAG + ".status_message";
public static final String START_ON_BOOT = "start on boot";
-
+
private View eipFragment;
private static Switch eipSwitch;
private View eipDetail;
@@ -174,7 +174,6 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
}
public void startEipFromScratch() {
- eip_status.setConnecting();
eipFragment.findViewById(R.id.eipProgress).setVisibility(View.VISIBLE);
String status = parent_activity.getString(R.string.eip_status_start_pending);
setStatusMessage(status);
@@ -212,6 +211,7 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
@Override
public void update (Observable observable, Object data) {
+ Log.d(TAG, "handleNewState?");
if(observable instanceof EipStatus) {
this.eip_status = (EipStatus) observable;
final EipStatus eip_status = (EipStatus) observable;
@@ -225,6 +225,7 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
}
private void handleNewState(EipStatus eip_status) {
+ Log.d(TAG, "handleNewState: " + eip_status.toString());
if(eip_status.wantsToDisconnect())
setDisconnectedUI();
else if (eip_status.isConnected())
@@ -249,12 +250,14 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
}
private void adjustSwitch() {
- if(eip_status.isConnected()) {
- Log.d(TAG, "adjustSwitch, isConnected, is checked? " + eipSwitch.isChecked());
+ if(eip_status.isConnected() || eip_status.isConnecting()) {
+ Log.d(TAG, "adjustSwitch, isConnected || isConnecting, is checked? " + eipSwitch.isChecked());
if(!eipSwitch.isChecked()) {
eipSwitch.setChecked(true);
}
} else {
+ Log.d(TAG, "adjustSwitch, !isConnected && !isConnecting? " + eip_status.toString());
+
if(eipSwitch.isChecked()) {
eipSwitch.setChecked(false);
}
@@ -267,6 +270,7 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
String prefix = parent_activity.getString(localizedResId);
setStatusMessage(prefix + " " + logmessage);
+ adjustSwitch();
}
protected void setStatusMessage(String status) {
@@ -280,6 +284,14 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
parent_activity.findViewById(R.id.eipProgress).setVisibility(View.GONE);
}
+ public static EipStatus getEipStatus() {
+ return eip_status;
+ }
+
+ public void checkEipSwitch(boolean activated) {
+ eipSwitch.setChecked(activated);
+ }
+
protected class EIPReceiver extends ResultReceiver {
protected EIPReceiver(Handler handler){
@@ -309,7 +321,7 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
switch (resultCode){
case Activity.RESULT_OK:
Intent disconnect_vpn = new Intent(parent_activity, DisconnectVPN.class);
- parent_activity.startActivityForResult(disconnect_vpn, 33);
+ parent_activity.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
eip_status.setDisconnecting();
break;
case Activity.RESULT_CANCELED:
@@ -359,13 +371,4 @@ public class EipServiceFragment extends Fragment implements Observer, CompoundBu
public static EIPReceiver getReceiver() {
return mEIPReceiver;
}
-
- public static boolean isEipSwitchChecked() {
- return eipSwitch.isChecked();
- }
-
- public void checkEipSwitch(boolean checked) {
- eipSwitch.setChecked(checked);
- }
-
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/LogInDialog.java b/app/src/main/java/se/leap/bitmaskclient/LogInDialog.java
index cede9bfb..97a9aecc 100644
--- a/app/src/main/java/se/leap/bitmaskclient/LogInDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/LogInDialog.java
@@ -112,7 +112,6 @@ public class LogInDialog extends SessionDialogInterface {
*/
public interface LogInDialogInterface {
public void logIn(String username, String password);
- public void cancelAuthedEipOn();
public void signUp(String username, String password);
public void cancelLoginOrSignup();
}
@@ -142,6 +141,6 @@ public class LogInDialog extends SessionDialogInterface {
public void onCancel(DialogInterface dialog) {
super.onCancel(dialog);
if(is_eip_pending)
- interface_with_Dashboard.cancelAuthedEipOn();
+ interface_with_Dashboard.cancelLoginOrSignup();
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java b/app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java
index 16ad2d19..d197e589 100644
--- a/app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/SignUpDialog.java
@@ -103,7 +103,6 @@ public class SignUpDialog extends SessionDialogInterface {
*/
public interface SignUpDialogInterface {
public void signUp(String username, String password);
- public void cancelAuthedEipOn();
public void cancelLoginOrSignup();
}
@@ -131,7 +130,7 @@ public class SignUpDialog extends SessionDialogInterface {
@Override
public void onCancel(DialogInterface dialog) {
if(is_eip_pending)
- interface_with_Dashboard.cancelAuthedEipOn();
+ interface_with_Dashboard.cancelLoginOrSignup();
super.onCancel(dialog);
}
}
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 577f42a3..379fb246 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -47,6 +47,9 @@ public final class EIP extends IntentService {
public final static String TAG = EIP.class.getSimpleName();
public final static String SERVICE_API_PATH = "config/eip-service.json";
+
+
+ public static final int DISCONNECT = 15;
private static Context context;
private static ResultReceiver mReceiver;
@@ -95,13 +98,13 @@ public final class EIP extends IntentService {
* It also sets up early routes.
*/
private void startEIP() {
- earlyRoutes();
GatewaySelector gateway_selector = new GatewaySelector(gateways);
activeGateway = gateway_selector.select();
if(activeGateway != null && activeGateway.getProfile() != null) {
mReceiver = EipServiceFragment.getReceiver();
launchActiveGateway();
}
+ earlyRoutes();
}
/**
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 ee14f2db..82c3ceb8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
@@ -29,7 +29,6 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
private static VpnStatus.ConnectionStatus level = VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED;
private static boolean wants_to_disconnect = false;
private static boolean is_disconnecting = false;
- private static boolean is_connecting = false;
private String state, log_message;
private int localized_res_id;
@@ -55,6 +54,8 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
current_status.setChanged();
if(isConnected() || isDisconnected())
setConnectedOrDisconnected();
+ else if(isConnecting())
+ setConnecting();
Log.d(TAG, "update state with level " + level);
current_status.notifyObservers();
}
@@ -63,14 +64,17 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
return is_disconnecting;
}
- public boolean isConnecting() {
- return is_connecting;
- }
-
public boolean wantsToDisconnect() {
return wants_to_disconnect;
}
+ public boolean isConnecting() {
+ return
+ !isConnected() &&
+ !isDisconnected() &&
+ !isPaused();
+ }
+
public boolean isConnected() {
return level == VpnStatus.ConnectionStatus.LEVEL_CONNECTED;
}
@@ -79,14 +83,19 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
return level == VpnStatus.ConnectionStatus.LEVEL_NOTCONNECTED;
}
+ public boolean isPaused() {
+ return level == VpnStatus.ConnectionStatus.LEVEL_VPNPAUSED;
+ }
+
public void setConnecting() {
- is_connecting = true;
is_disconnecting = false;
wants_to_disconnect = false;
+ current_status.setChanged();
+ current_status.notifyObservers();
}
public void setConnectedOrDisconnected() {
- is_connecting = false;
+ Log.d(TAG, "setConnectedOrDisconnected()");
is_disconnecting = false;
wants_to_disconnect = false;
current_status.setChanged();
@@ -95,7 +104,6 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
public void setDisconnecting() {
is_disconnecting = true;
- is_connecting = false;
wants_to_disconnect = false;
}
@@ -139,4 +147,9 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
this.level = level;
}
+ @Override
+ public String toString() {
+ return "State: " + state + " Level: " + level.toString();
+ }
+
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
index 9814c167..d79d8003 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnLauncher.java
@@ -8,7 +8,7 @@ import android.os.Bundle;
public class VoidVpnLauncher extends Activity {
private static final int VPN_USER_PERMISSION = 71;
-
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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 c6ac96a9..d217e1a1 100644
--- a/app/src/main/res/layout-xlarge/eip_service_fragment.xml
+++ b/app/src/main/res/layout-xlarge/eip_service_fragment.xml
@@ -67,7 +67,7 @@
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="true"
- android:text="@string/status_unknown"
+ android:text="@string/eip_state_not_connected"
android:textSize="16sp" />
</RelativeLayout>
diff --git a/app/src/main/res/layout/eip_service_fragment.xml b/app/src/main/res/layout/eip_service_fragment.xml
index 65aa4aa8..be2aa791 100644
--- a/app/src/main/res/layout/eip_service_fragment.xml
+++ b/app/src/main/res/layout/eip_service_fragment.xml
@@ -64,7 +64,7 @@
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:clickable="true"
- android:text="@string/status_unknown" />
+ android:text="@string/eip_state_not_connected" />
</RelativeLayout>