fixes for network switching with VPN enabled

This commit is contained in:
Nathan Freitas 2015-04-04 00:36:24 -04:00
parent f37b935529
commit d6eb1dca57
3 changed files with 43 additions and 32 deletions

View File

@ -688,11 +688,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon
boolean isTransProxy = mPrefs.getBoolean("pref_transparent", false); boolean isTransProxy = mPrefs.getBoolean("pref_transparent", false);
if (isOrwebInstalled) if (mBtnVPN.isChecked())
{
startIntent("info.guardianproject.browser",Intent.ACTION_VIEW,Uri.parse(browserLaunchUrl));
}
else if (mBtnVPN.isChecked())
{ {
//use the system browser since VPN is on //use the system browser since VPN is on
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(browserLaunchUrl)); 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); intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent); startActivity(intent);
} }
else if (isOrwebInstalled)
{
startIntent("info.guardianproject.browser",Intent.ACTION_VIEW,Uri.parse(browserLaunchUrl));
}
else else
{ {
AlertDialog aDialog = new AlertDialog.Builder(OrbotMainActivity.this) AlertDialog aDialog = new AlertDialog.Builder(OrbotMainActivity.this)

View File

@ -128,6 +128,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private long mTotalTrafficWritten = 0; private long mTotalTrafficWritten = 0;
private long mTotalTrafficRead = 0; private long mTotalTrafficRead = 0;
private boolean mConnectivity = true; private boolean mConnectivity = true;
private int mNetworkType = -1;
private long lastRead = -1; private long lastRead = -1;
private long lastWritten = -1; private long lastWritten = -1;
@ -2086,6 +2087,9 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
final NetworkInfo netInfo = cm.getActiveNetworkInfo(); final NetworkInfo netInfo = cm.getActiveNetworkInfo();
boolean newConnectivityState = false; boolean newConnectivityState = false;
int newNetType = -1;
boolean isChanged = false;
if(netInfo != null && netInfo.isConnected()) { if(netInfo != null && netInfo.isConnected()) {
// WE ARE CONNECTED: DO SOMETHING // WE ARE CONNECTED: DO SOMETHING
@ -2096,10 +2100,17 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
newConnectivityState = false; newConnectivityState = false;
} }
//is this a change in state? if (netInfo!=null)
if (mConnectivity != newConnectivityState) newNetType = netInfo.getType();
{
isChanged = ((mNetworkType != newNetType)||(mConnectivity != newConnectivityState));
//is this a change in state?
if (isChanged)
{
mNetworkType = newNetType;
mConnectivity = newConnectivityState;
if (doNetworKSleep) if (doNetworKSleep)
{ {
try { try {
@ -2130,6 +2141,10 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
shell.close(); 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;
} }

View File

@ -89,14 +89,18 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
} }
else if (action.equals("stop")) else if (action.equals("stop"))
{ {
Log.d(TAG,"stop OrbotVPNService service!");
stopVPN(); stopVPN();
if (mHandler != null) if (mHandler != null)
mHandler.postDelayed(new Runnable () { public void run () { stopSelf(); }}, 1000); mHandler.postDelayed(new Runnable () { public void run () { stopSelf(); }}, 1000);
} }
else if (action.equals("refresh")) else if (action.equals("refresh"))
{ {
if (!isLollipop) Log.d(TAG,"refresh OrbotVPNService service!");
startSocksBypass();
// if (!isLollipop)
// startSocksBypass();
setupTun2Socks(); setupTun2Socks();
} }
@ -201,13 +205,13 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
// (i.e., Farsi and Arabic).^M // (i.e., Farsi and Arabic).^M
Locale.setDefault(new Locale("en")); Locale.setDefault(new Locale("en"));
//String localhost = InetAddress.getLocalHost().getHostAddress(); String localhost = InetAddress.getLocalHost().getHostAddress();
String vpnName = "OrbotVPN"; String vpnName = "OrbotVPN";
String virtualGateway = "10.0.0.1"; String virtualGateway = "10.0.0.1";
String virtualIP = "10.0.0.2"; String virtualIP = "10.0.0.2";
String virtualNetMask = "255.255.255.0"; 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; String localDNS = "10.0.0.1" + ':' + TorServiceConstants.TOR_DNS_PORT_DEFAULT;
@ -224,20 +228,22 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
doLollipopAppRouting(builder); doLollipopAppRouting(builder);
} }
if (mInterface != null)
{
Log.d(TAG,"Stopping existing VPN interface");
isRestart = true;
mInterface.close();
mInterface = null;
Tun2Socks.Stop();
}
// Create a new interface using the builder and save the parameters. // Create a new interface using the builder and save the parameters.
ParcelFileDescriptor newInterface = builder.setSession(mSessionName) ParcelFileDescriptor newInterface = builder.setSession(mSessionName)
.setConfigureIntent(mConfigureIntent) .setConfigureIntent(mConfigureIntent)
.establish(); .establish();
if (mInterface != null)
{
isRestart = true;
Tun2Socks.Stop();
mInterface.close();
}
mInterface = newInterface; mInterface = newInterface;