summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorParménides GV <parmegv@sdf.org>2014-10-07 21:17:12 +0200
committerParménides GV <parmegv@sdf.org>2014-10-07 21:17:12 +0200
commitc4df01ab94c85ecf4a106b187a03e4859a857b1c (patch)
tree963423d6253b241d83442bba15b7abd303ea8b33 /app/src/main/java
parentfa218f752003adcfb040053cfb88b36637060de7 (diff)
Set up early routes on boot too.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/EIP.java8
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/VoidVpnLauncher.java36
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java30
3 files changed, 68 insertions, 6 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/EIP.java b/app/src/main/java/se/leap/bitmaskclient/EIP.java
index add5a1d1..0197692b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/EIP.java
+++ b/app/src/main/java/se/leap/bitmaskclient/EIP.java
@@ -185,16 +185,18 @@ public final class EIP extends IntentService {
* Intent to {@link se.leap.openvpn.LaunchVPN}
*/
private void startEIP() {
- activeGateway = selectGateway();
earlyRoutes();
+ activeGateway = selectGateway();
+
if(activeGateway != null && activeGateway.mVpnProfile != null) {
launchActiveGateway();
}
}
private void earlyRoutes() {
- VoidVpnService voidVpn = new VoidVpnService();
- voidVpn.setUp(context);
+ Intent void_vpn_launcher = new Intent(context, VoidVpnLauncher.class);
+ void_vpn_launcher.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ startActivity(void_vpn_launcher);
}
private void launchActiveGateway() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/VoidVpnLauncher.java b/app/src/main/java/se/leap/bitmaskclient/VoidVpnLauncher.java
new file mode 100644
index 00000000..23e61eab
--- /dev/null
+++ b/app/src/main/java/se/leap/bitmaskclient/VoidVpnLauncher.java
@@ -0,0 +1,36 @@
+package se.leap.bitmaskclient;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.VpnService;
+import android.os.Bundle;
+
+public class VoidVpnLauncher extends Activity {
+
+ private static final int VPN_USER_PERMISSION= 71;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setUp();
+ }
+
+ public void setUp() {
+ Intent blocking_intent = VpnService.prepare(getApplicationContext()); // stops the VPN connection created by another application.
+ if(blocking_intent != null)
+ startActivityForResult(blocking_intent, VPN_USER_PERMISSION);
+ else {
+ onActivityResult(VPN_USER_PERMISSION, RESULT_OK, null);
+ }
+ }
+
+ protected void onActivityResult(int requestCode, int resultCode, Intent data){
+ if(requestCode == VPN_USER_PERMISSION) {
+ if(resultCode == RESULT_OK) {
+ Intent void_vpn_service = new Intent(getApplicationContext(), VoidVpnService.class);
+ void_vpn_service.setAction(VoidVpnService.START_BLOCKING_VPN_PROFILE);
+ startService(void_vpn_service);
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java b/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java
index ec88fd48..5f7c0ab1 100644
--- a/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java
+++ b/app/src/main/java/se/leap/bitmaskclient/VoidVpnService.java
@@ -1,11 +1,28 @@
package se.leap.bitmaskclient;
-import android.content.Context;
+import android.content.Intent;
import android.net.VpnService;
+import android.util.Log;
public class VoidVpnService extends VpnService {
- public void setUp(Context context) {
- VpnService.prepare(context); // stops the VPN connection created by another application.
+
+ static final String START_BLOCKING_VPN_PROFILE = "se.leap.bitmaskclient.START_BLOCKING_VPN_PROFILE";
+ static final String TAG = VoidVpnService.class.getSimpleName();
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ String action = intent.getAction();
+ if (action == START_BLOCKING_VPN_PROFILE) {
+ new Thread(new Runnable() {
+ public void run() {
+ blockConnections();
+ }
+ }).run();
+ }
+ return 0;
+ }
+
+ public void blockConnections() {
Builder builder = new Builder();
builder.addAddress("10.42.0.8",16);
builder.addRoute("0.0.0.0", 1);
@@ -13,5 +30,12 @@ public class VoidVpnService extends VpnService {
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();
+ }
}
}