summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-06-13 11:31:36 +0200
committerParménides GV <parmegv@sdf.org>2014-06-13 11:31:36 +0200
commit36247e71df88fa13c6c5a887de3b11d9a883615f (patch)
tree099535ca64dc0b0779d23159b3323dc1f65828b4 /app/src/main
parent3532eff1b86f6b5ae4268393c4b5c61350c89faf (diff)
Disconnect works, eip status receiver.
Disconnect uses the ics-openvpn activity, and the dialog prompting the user to confirm the disconnection is only shown when eip is connected or is trying to connect.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/AndroidManifest.xml9
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EIP.java19
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipStatusReceiver.java17
3 files changed, 36 insertions, 9 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 51ce3e80..860f0e1e 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -53,6 +53,15 @@
</intent-filter>
</receiver>
+ <receiver
+ android:name="se.leap.bitmaskclient.EipStatusReceiver"
+ android:enabled="true"
+ android:permission="android.permission.ACCESS_NETWORK_STATE" >
+ <intent-filter>
+ <action android:name="de.blinkt.openvpn.VPN_STATUS" />
+ </intent-filter>
+ </receiver>
+
<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/EIP.java b/app/src/main/java/se/leap/bitmaskclient/EIP.java
index c9125f5c..59faf93f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EIP.java
@@ -31,6 +31,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import se.leap.bitmaskclient.R;
+import de.blinkt.openvpn.activities.DisconnectVPN;
import de.blinkt.openvpn.core.ConfigParser;
import de.blinkt.openvpn.core.ConfigParser.ConfigParseError;
import de.blinkt.openvpn.LaunchVPN;
@@ -68,6 +69,7 @@ public final class EIP extends IntentService {
public final static String ACTION_UPDATE_EIP_SERVICE = "se.leap.bitmaskclient.UPDATE_EIP_SERVICE";
public final static String ACTION_IS_EIP_RUNNING = "se.leap.bitmaskclient.IS_RUNNING";
public final static String EIP_NOTIFICATION = "EIP_NOTIFICATION";
+ public final static String STATUS = "eip status";
public final static String ALLOWED_ANON = "allow_anonymous";
public final static String CERTIFICATE = "cert";
public final static String PRIVATE_KEY = "private_key";
@@ -200,8 +202,9 @@ public final class EIP extends IntentService {
Bundle resultData = new Bundle();
resultData.putString(REQUEST_TAG, ACTION_IS_EIP_RUNNING);
int resultCode = Activity.RESULT_CANCELED;
+ boolean is_connected = getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getString(STATUS, "").equalsIgnoreCase("LEVEL_CONNECTED");
if (mBound) {
- resultCode = (mVpnService.isRunning()) ? Activity.RESULT_OK : Activity.RESULT_CANCELED;
+ resultCode = (is_connected) ? Activity.RESULT_OK : Activity.RESULT_CANCELED;
if (mReceiver != null){
mReceiver.send(resultCode, resultData);
@@ -215,12 +218,7 @@ public final class EIP extends IntentService {
// TODO Auto-generated catch block
e.printStackTrace();
}
- boolean running = false;
- try {
- running = mVpnService.isRunning();
- } catch (NullPointerException e){
- e.printStackTrace();
- }
+ boolean running = is_connected;
if (retrieved_vpn_service && running && mReceiver != null){
mReceiver.send(Activity.RESULT_OK, resultData);
@@ -256,8 +254,11 @@ public final class EIP extends IntentService {
private void stopEIP() {
if (mBound)
mVpnService.onRevoke();
- else
- mVpnService.getManagement().stopVPN();
+ else if(getSharedPreferences(Dashboard.SHARED_PREFERENCES, MODE_PRIVATE).getString(STATUS, "").startsWith("LEVEL_CONNECT")){
+ Intent disconnect_vpn = new Intent(this, DisconnectVPN.class);
+ disconnect_vpn.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(disconnect_vpn);
+ }
if (mReceiver != null){
Bundle resultData = new Bundle();
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipStatusReceiver.java b/app/src/main/java/se/leap/bitmaskclient/EipStatusReceiver.java
new file mode 100644
index 00000000..8793cf36
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/EipStatusReceiver.java
@@ -0,0 +1,17 @@
+package se.leap.bitmaskclient;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
+
+public class EipStatusReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals("de.blinkt.openvpn.VPN_STATUS")) {
+ context.getSharedPreferences(Dashboard.SHARED_PREFERENCES, Context.MODE_PRIVATE).edit().putString(EIP.STATUS, intent.getStringExtra("status")).commit();
+ }
+ }
+}