From 5e1d89482034c94f22547a12298bdf956761c0ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Parm=C3=A9nides=20GV?= Date: Thu, 16 Oct 2014 10:22:27 +0200 Subject: Move blocking code to thread's run. --- .../java/se/leap/bitmaskclient/VoidVpnService.java | 36 +++++++++------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'app/src') diff --git a/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java index b7289c23..7b597554 100644 --- a/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java +++ b/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java @@ -1,10 +1,11 @@ package se.leap.bitmaskclient; import android.content.Intent; +import android.os.Process; import android.net.VpnService; import android.util.Log; -public class VoidVpnService extends VpnService { +public class VoidVpnService extends VpnService { static final String START_BLOCKING_VPN_PROFILE = "se.leap.bitmaskclient.START_BLOCKING_VPN_PROFILE"; static final String TAG = VoidVpnService.class.getSimpleName(); @@ -14,29 +15,22 @@ public class VoidVpnService extends VpnService { String action = intent.getAction(); if (action == START_BLOCKING_VPN_PROFILE) { new Thread(new Runnable() { - public void run() { - blockConnections(); + public void run() { + Builder builder = new Builder(); + builder.setSession("Blocking until running"); + builder.addAddress("10.42.0.8",16); + builder.addRoute("0.0.0.0", 1); + builder.addRoute("192.168.1.0", 24); + builder.addDnsServer("10.42.0.1"); + try { + builder.establish(); + } catch (Exception e) { + e.printStackTrace(); + } + android.util.Log.d(TAG, "VoidVpnService set up"); } }).run(); } return 0; } - - public void blockConnections() { - Builder builder = new Builder(); - builder.setSession("Blocking until running"); - builder.addAddress("10.42.0.8",16); - builder.addRoute("0.0.0.0", 1); - builder.addRoute("128.0.0.0", 1); - builder.addRoute("192.168.1.0", 24); - builder.addDnsServer("10.42.0.1"); - builder.establish(); - android.util.Log.d(TAG, "VoidVpnService set up"); - try { - new java.net.Socket("sdf.org", 80); - Log.d(TAG, "VoidVpnService doesn's stop traffic"); - } catch (Exception e) { - e.printStackTrace(); - } - } } -- cgit v1.2.3