diff options
Diffstat (limited to 'app')
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; } } } |