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);
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)

View File

@ -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;
}
//is this a change in state?
if (mConnectivity != newConnectivityState)
{
if (netInfo!=null)
newNetType = netInfo.getType();
isChanged = ((mNetworkType != newNetType)||(mConnectivity != newConnectivityState));
//is this a change in state?
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;
}

View File

@ -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,20 +228,22 @@ public class OrbotVpnService extends VpnService implements Handler.Callback {
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.
ParcelFileDescriptor newInterface = builder.setSession(mSessionName)
.setConfigureIntent(mConfigureIntent)
.establish();
if (mInterface != null)
{
isRestart = true;
Tun2Socks.Stop();
mInterface.close();
}
mInterface = newInterface;