summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2015-03-24 17:40:50 +0100
committerParménides GV <parmegv@sdf.org>2015-03-24 17:40:50 +0100
commite4eeef39a6219d2abba26af5a588bc51c4f5af5b (patch)
tree4dd6e953068c7a324fc59dc2eda8f9583a8c1367
parent7d96019f831ec9e07246893912c0b9b8a656de41 (diff)
9 out of 10 times, in a row, void vpn is closed.
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EipFragment.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java32
3 files changed, 22 insertions, 13 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
index 8b532e24..ac869b18 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EipFragment.java
@@ -295,6 +295,7 @@ public class EipFragment extends Fragment implements Observer {
if(eip_status.errorInLast(5, dashboard.getApplicationContext())
&& !status_message.getText().toString().equalsIgnoreCase(dashboard.getString(R.string.eip_state_not_connected))){
dashboard.showLog();
+ VoidVpnService.stop();
}
status_message.setText(dashboard.getString(R.string.eip_state_not_connected));
}
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 17e290b8..d1ed0d27 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipStatus.java
@@ -48,8 +48,6 @@ public class EipStatus extends Observable implements VpnStatus.StateListener {
updateStatus(state, logmessage, localizedResId, level);
if(isConnected() || isDisconnected()) {
setConnectedOrDisconnected();
- if(isDisconnected())
- VoidVpnService.stop();
} else if(isConnecting())
setConnecting();
Log.d(TAG, "update state with level " + level);
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 0a707ab1..f87f35e2 100644
--- a/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/eip/VoidVpnService.java
@@ -11,12 +11,14 @@ public class VoidVpnService extends VpnService {
static final String TAG = VoidVpnService.class.getSimpleName();
static ParcelFileDescriptor fd;
+ static Thread thread;
+
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String action = intent != null ? intent.getAction() : "";
if (action == Constants.START_BLOCKING_VPN_PROFILE) {
- new Thread(new Runnable() {
- public void run() {
+ thread = new Thread(new Runnable() {
+ public void run() {
Builder builder = new Builder();
builder.setSession("Blocking until running");
builder.addAddress("10.42.0.8",16);
@@ -25,30 +27,38 @@ public class VoidVpnService extends VpnService {
builder.addDnsServer("10.42.0.1");
try {
fd = builder.establish();
+
} catch (Exception e) {
e.printStackTrace();
}
- android.util.Log.d(TAG, "VoidVpnService set up");
+ android.util.Log.d(TAG, "VoidVpnService set up: fd = " + fd.toString());
}
- }).run();
- }
+ });
+ thread.run();
+ }
return 0;
}
@Override
public void onRevoke() {
super.onRevoke();
+ closeFd();
+ }
+
+ public static void stop() {
+ if(thread != null)
+ thread.interrupt();
+ closeFd();
}
- public static boolean stop() {
+ private static void closeFd() {
try {
- if(fd != null)
+ if(fd != null) {
+ android.util.Log.d(TAG, "VoidVpnService closing fd = " + fd.toString());
fd.close();
- return true;
- } catch (IOException | NullPointerException e) {
- android.util.Log.d(TAG, "VoidVpnService didn't stop");
+ }
+ } catch (IOException e) {
e.printStackTrace();
- return false;
}
}
}