summaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-12-17 12:25:31 +0100
committerParménides GV <parmegv@sdf.org>2014-12-17 12:25:31 +0100
commit63ae29d808da4c85c223f2e2b6824322b8fc45df (patch)
tree4590b07249703ab246621c807852599adaa3bee9 /app/src
parentdbd6f2c57e4565d4e7a76b4ae2a5520aa877f121 (diff)
Stop normal and blocking VPNs correctly
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java10
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EIP.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java24
3 files changed, 30 insertions, 6 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 92d2a8bd..fc412449 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -26,6 +26,7 @@ import de.blinkt.openvpn.activities.DisconnectVPN;
import se.leap.bitmaskclient.eip.Constants;
import se.leap.bitmaskclient.eip.EIP;
import se.leap.bitmaskclient.eip.EipStatus;
+import se.leap.bitmaskclient.eip.VoidVpnService;
public class EipFragment extends Fragment implements Observer {
@@ -306,14 +307,17 @@ public class EipFragment extends Fragment implements Observer {
case Activity.RESULT_OK:
break;
case Activity.RESULT_CANCELED:
+
break;
}
} else if (request.equals(Constants.ACTION_STOP_EIP)) {
switch (resultCode){
case Activity.RESULT_OK:
- Intent disconnect_vpn = new Intent(parent_activity, DisconnectVPN.class);
- parent_activity.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
- eip_status.setDisconnecting();
+ if(eip_status.isConnecting())
+ VoidVpnService.stop();
+ Intent disconnect_vpn = new Intent(parent_activity, DisconnectVPN.class);
+ parent_activity.startActivityForResult(disconnect_vpn, EIP.DISCONNECT);
+ eip_status.setDisconnecting();
break;
case Activity.RESULT_CANCELED:
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 7017e874..3d3070c8 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java
@@ -149,7 +149,7 @@ public final class EIP extends IntentService {
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())
+ if(eip_status.isConnected() || eip_status.isConnecting())
result_code = Activity.RESULT_OK;
tellToReceiver(ACTION_STOP_EIP, result_code);
diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
index a6f9fe76..0c773208 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -2,14 +2,18 @@ package se.leap.bitmaskclient.eip;
import android.content.Intent;
import android.net.VpnService;
+import android.os.ParcelFileDescriptor;
+
+import java.io.IOException;
public class VoidVpnService extends VpnService {
static final String TAG = VoidVpnService.class.getSimpleName();
+ static ParcelFileDescriptor fd;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- String action = intent.getAction();
+ String action = intent != null ? intent.getAction() : "";
if (action == Constants.START_BLOCKING_VPN_PROFILE) {
new Thread(new Runnable() {
public void run() {
@@ -20,7 +24,7 @@ public class VoidVpnService extends VpnService {
builder.addRoute("192.168.1.0", 24);
builder.addDnsServer("10.42.0.1");
try {
- builder.establish();
+ fd = builder.establish();
} catch (Exception e) {
e.printStackTrace();
}
@@ -30,4 +34,20 @@ public class VoidVpnService extends VpnService {
}
return 0;
}
+
+ @Override
+ public void onRevoke() {
+ super.onRevoke();
+ }
+
+ public static boolean stop() {
+ try {
+ fd.close();
+ return true;
+ } catch (IOException | NullPointerException e) {
+ android.util.Log.d(TAG, "VoidVpnService didn't stop");
+ e.printStackTrace();
+ return false;
+ }
+ }
}