From fb3e27bdcf0d0e3f361100f4465bf154a8b312ec Mon Sep 17 00:00:00 2001 From: Nathan Freitas Date: Mon, 2 Feb 2015 16:21:04 -0500 Subject: [PATCH] more clean-up of VPN service code --- .../android/service/TorService.java | 12 ++++---- .../android/service/TorServiceConstants.java | 3 +- .../android/vpn/OrbotVpnService.java | 29 +++++-------------- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java index 423f62c1..60f151cf 100644 --- a/src/org/torproject/android/service/TorService.java +++ b/src/org/torproject/android/service/TorService.java @@ -81,7 +81,7 @@ import android.widget.RemoteViews; public class TorService extends Service implements TorServiceConstants, TorConstants, EventHandler { - public static boolean ENABLE_DEBUG_LOG = false; + public static boolean ENABLE_DEBUG_LOG = true; private int mCurrentStatus = STATUS_OFF; @@ -381,7 +381,10 @@ public class TorService extends Service implements TorServiceConstants, TorConst }else if (action.equals(CMD_UPDATE)){ processSettings(); }else if (action.equals(CMD_VPN)){ - startVpnService(); + enableVpnProxy(); + } + else if (action.equals(CMD_VPN_CLEAR)){ + clearVpnProxy(); } } }else{ @@ -1416,8 +1419,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst } } - @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) - public void startVpnService () { + public void enableVpnProxy () { SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); Editor ePrefs = prefs.edit(); @@ -1435,7 +1437,7 @@ public class TorService extends Service implements TorServiceConstants, TorConst } - public void stopVpnService () + public void clearVpnProxy () { SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); Editor ePrefs = prefs.edit(); diff --git a/src/org/torproject/android/service/TorServiceConstants.java b/src/org/torproject/android/service/TorServiceConstants.java index d979ac44..4c3adc95 100644 --- a/src/org/torproject/android/service/TorServiceConstants.java +++ b/src/org/torproject/android/service/TorServiceConstants.java @@ -82,11 +82,10 @@ public interface TorServiceConstants { public static final String CMD_NEWNYM = "newnym"; public static final String CMD_INIT = "init"; public static final String CMD_VPN = "vpn"; + public static final String CMD_VPN_CLEAR = "vpnclear"; public static final String CMD_UPDATE = "update"; - - public static final String BINARY_TOR_VERSION = "0.2.5.10-openssl1.0.1i-nonPIE-polipofix"; public static final String PREF_BINARY_TOR_VERSION_INSTALLED = "BINARY_TOR_VERSION_INSTALLED"; diff --git a/src/org/torproject/android/vpn/OrbotVpnService.java b/src/org/torproject/android/vpn/OrbotVpnService.java index 22a8af17..427799e5 100644 --- a/src/org/torproject/android/vpn/OrbotVpnService.java +++ b/src/org/torproject/android/vpn/OrbotVpnService.java @@ -18,6 +18,7 @@ package org.torproject.android.vpn; import java.io.IOException; import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.Locale; import org.torproject.android.service.TorServiceConstants; @@ -56,20 +57,6 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { private final static int VPN_MTU = 1500; - private static final int NOTIFY_ID = 10; - private static final int TRANSPROXY_NOTIFY_ID = 20; - private static final int ERROR_NOTIFY_ID = 30; - private static final int HS_NOTIFY_ID = 40; - - private boolean prefPersistNotifications = true; - - private NotificationManager mNotificationManager = null; - private android.support.v4.app.NotificationCompat.Builder mNotifyBuilder; - private Notification mNotification; - private boolean mShowExpandedNotifications = false; - private boolean mNotificationShowing = false; - - @Override public int onStartCommand(Intent intent, int flags, int startId) { @@ -101,6 +88,7 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { else { //do socks bypass trick + startSocksBypass(); } } @@ -165,23 +153,20 @@ public class OrbotVpnService extends VpnService implements Handler.Callback { String vpnName = "OrbotVPN"; String virtualGateway = "10.0.0.1"; - String virtualRoute = "10.0.0.0"; String virtualIP = "10.0.0.2"; - String virtualNetMask = "255.255.2555.0"; - String localSocks = "localhost:" + TorServiceConstants.PORT_SOCKS_DEFAULT; - String localDNS = "localhost:" + TorServiceConstants.TOR_DNS_PORT_DEFAULT; + String virtualNetMask = "255.255.255.0"; + String localSocks = "127.0.0.1:" + TorServiceConstants.PORT_SOCKS_DEFAULT; + String localDNS = "10.0.0.1:" + TorServiceConstants.TOR_DNS_PORT_DEFAULT; Builder builder = new Builder(); builder.setMtu(VPN_MTU); - builder.addAddress(virtualGateway,8); + builder.addAddress(virtualGateway,28); builder.setSession(vpnName); - builder.addRoute("0.0.0.0",0); - builder.addRoute(virtualRoute,8); + builder.addRoute("0.0.0.0",0); - //builder.addDnsServer("8.8.8.8"); // Create a new interface using the builder and save the parameters. mInterface = builder.setSession(mSessionName)