commit d6eb1dca5727c57f2b14650ef846d2f8fe22a856
Author: Nathan Freitas <nathan(a)freitas.net>
Date: Sat Apr 4 00:36:24 2015 -0400
fixes for network switching with VPN enabled
---
src/org/torproject/android/OrbotMainActivity.java | 10 +++----
src/org/torproject/android/service/TorService.java | 31 ++++++++++++--------
.../torproject/android/vpn/OrbotVpnService.java | 30 +++++++++++--------
3 files changed, 41 insertions(+), 30 deletions(-)
diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java
index 7e211e5..405e930 100644
--- a/src/org/torproject/android/OrbotMainActivity.java
+++ b/src/org/torproject/android/OrbotMainActivity.java
@@ -688,11 +688,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
boolean isTransProxy = mPrefs.getBoolean("pref_transparent", false);
- if (isOrwebInstalled)
- {
- startIntent("info.guardianproject.browser",Intent.ACTION_VIEW,Uri.parse(browserLaunchUrl));
- }
- else if (mBtnVPN.isChecked())
+ if (mBtnVPN.isChecked())
{
//use the system browser since VPN is on
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl));
@@ -705,6 +701,10 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
+ else if (isOrwebInstalled)
+ {
+ startIntent("info.guardianproject.browser",Intent.ACTION_VIEW,Uri.parse(browserLaunchUrl));
+ }
else
{
AlertDialog aDialog = new AlertDialog.Builder(OrbotMainActivity.this)
diff --git a/src/org/torproject/android/service/TorService.java b/src/org/torproject/android/service/TorService.java
index cae1697..03c7ebb 100644
--- a/src/org/torproject/android/service/TorService.java
+++ b/src/org/torproject/android/service/TorService.java
@@ -128,6 +128,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private long mTotalTrafficWritten = 0;
private long mTotalTrafficRead = 0;
private boolean mConnectivity = true;
+ private int mNetworkType = -1;
private long lastRead = -1;
private long lastWritten = -1;
@@ -2086,6 +2087,9 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
final NetworkInfo netInfo = cm.getActiveNetworkInfo();
boolean newConnectivityState = false;
+ int newNetType = -1;
+
+ boolean isChanged = false;
if(netInfo != null && netInfo.isConnected()) {
// WE ARE CONNECTED: DO SOMETHING
@@ -2096,10 +2100,17 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
newConnectivityState = false;
}
+ if (netInfo!=null)
+ newNetType = netInfo.getType();
+
+ isChanged = ((mNetworkType != newNetType)||(mConnectivity != newConnectivityState));
+
//is this a change in state?
- if (mConnectivity != newConnectivityState)
+ if (isChanged)
{
-
+ mNetworkType = newNetType;
+ mConnectivity = newConnectivityState;
+
if (doNetworKSleep)
{
try {
@@ -2130,6 +2141,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
shell.close();
}
+ if (mUseVPN) //we need to turn on VPN here so the proxy is running
+ refreshVpnProxy();
+
+
}
}
@@ -2140,18 +2155,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
}
}
- if (mUseVPN && mConnectivity && (mCurrentStatus != STATUS_OFF)) //we need to turn on VPN here so the proxy is running
- {
- setTorNetworkEnabled (false);
- refreshVpnProxy();
- setTorNetworkEnabled (true);
-
-
- }
+
}
-
- mConnectivity = newConnectivityState;
-
}
diff --git a/src/org/torproject/android/vpn/OrbotVpnService.java b/src/org/torproject/android/vpn/OrbotVpnService.java
index b495937..f2a0e96 100644
--- a/src/org/torproject/android/vpn/OrbotVpnService.java
+++ b/src/org/torproject/android/vpn/OrbotVpnService.java
@@ -89,14 +89,18 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
}
else if (action.equals("stop"))
{
+ Log.d(TAG,"stop OrbotVPNService service!");
+
stopVPN();
if (mHandler != null)
mHandler.postDelayed(new Runnable () { public void run () { stopSelf(); }}, 1000);
}
else if (action.equals("refresh"))
{
- if (!isLollipop)
- startSocksBypass();
+ Log.d(TAG,"refresh OrbotVPNService service!");
+
+ // if (!isLollipop)
+ // startSocksBypass();
setupTun2Socks();
}
@@ -201,13 +205,13 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
// (i.e., Farsi and Arabic).^M
Locale.setDefault(new Locale("en"));
- //String localhost = InetAddress.getLocalHost().getHostAddress();
+ String localhost = InetAddress.getLocalHost().getHostAddress();
String vpnName = "OrbotVPN";
String virtualGateway = "10.0.0.1";
String virtualIP = "10.0.0.2";
String virtualNetMask = "255.255.255.0";
- String localSocks = "127.0.0.1" + ':' + TorServiceConstants.PORT_SOCKS_DEFAULT;
+ String localSocks = localhost + ':' + TorServiceConstants.PORT_SOCKS_DEFAULT;//+ "127.0.0.1"
String localDNS = "10.0.0.1" + ':' + TorServiceConstants.TOR_DNS_PORT_DEFAULT;
@@ -224,21 +228,23 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
doLollipopAppRouting(builder);
}
- // Create a new interface using the builder and save the parameters.
- ParcelFileDescriptor newInterface = builder.setSession(mSessionName)
- .setConfigureIntent(mConfigureIntent)
- .establish();
-
if (mInterface != null)
{
+ Log.d(TAG,"Stopping existing VPN interface");
isRestart = true;
-
- Tun2Socks.Stop();
mInterface.close();
-
+ mInterface = null;
+
+ Tun2Socks.Stop();
}
+ // Create a new interface using the builder and save the parameters.
+ ParcelFileDescriptor newInterface = builder.setSession(mSessionName)
+ .setConfigureIntent(mConfigureIntent)
+ .establish();
+
+
mInterface = newInterface;
Tun2Socks.Start(mInterface, VPN_MTU, virtualIP, virtualNetMask, localSocks , localDNS , true);