From e4eeef39a6219d2abba26af5a588bc51c4f5af5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Tue, 24 Mar 2015 17:40:50 +0100 Subject: 9 out of 10 times, in a row, void vpn is closed. --- .../java/se/leap/bitmaskclient/EipFragment.java | 1 + .../java/se/leap/bitmaskclient/eip/EipStatus.java | 2 -- .../se/leap/bitmaskclient/eip/VoidVpnService.java | 32 ++++++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) (limited to 'app') 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; } } } -- cgit v1.2.3