fix handling of network connectivity state management

This commit is contained in:
Nathan Freitas 2015-04-08 16:46:40 -04:00
parent 02a42e425e
commit 384fe1c21e
1 changed files with 24 additions and 23 deletions

View File

@ -2105,35 +2105,38 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
isChanged = ((mNetworkType != newNetType)||(mConnectivity != newConnectivityState)); isChanged = ((mNetworkType != newNetType)||(mConnectivity != newConnectivityState));
//is this a change in state? mNetworkType = newNetType;
if (isChanged) mConnectivity = newConnectivityState;
if (doNetworKSleep)
{ {
mNetworkType = newNetType; setTorNetworkEnabled (mConnectivity);
mConnectivity = newConnectivityState;
if (!mConnectivity)
if (doNetworKSleep) {
logNotice(context.getString(R.string.no_network_connectivity_putting_tor_to_sleep_));
showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off);
}
else
{
logNotice(context.getString(R.string.network_connectivity_is_good_waking_tor_up_));
showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor);
}
//is this a change in state?
if (isChanged)
{ {
try { try {
setTorNetworkEnabled (mConnectivity);
if (mCurrentStatus != STATUS_OFF) if (mCurrentStatus != STATUS_OFF)
{ {
if (!mConnectivity) if (mConnectivity)
{ {
logNotice(context.getString(R.string.no_network_connectivity_putting_tor_to_sleep_));
showToolbarNotification(getString(R.string.no_internet_connection_tor),NOTIFY_ID,R.drawable.ic_stat_tor_off);
}
else
{
logNotice(context.getString(R.string.network_connectivity_is_good_waking_tor_up_));
showToolbarNotification(getString(R.string.status_activated),NOTIFY_ID,R.drawable.ic_stat_tor);
if (mHasRoot && mEnableTransparentProxy && mTransProxyNetworkRefresh) if (mHasRoot && mEnableTransparentProxy && mTransProxyNetworkRefresh)
{ {
Shell shell = Shell.startRootShell(); Shell shell = Shell.startRootShell();
disableTransparentProxy(shell); disableTransparentProxy(shell);
enableTransparentProxy(shell); enableTransparentProxy(shell);
@ -2144,7 +2147,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
if (mUseVPN) //we need to turn on VPN here so the proxy is running if (mUseVPN) //we need to turn on VPN here so the proxy is running
refreshVpnProxy(); refreshVpnProxy();
} }
} }
@ -2153,9 +2155,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
} catch (Exception e) { } catch (Exception e) {
logException ("error updating state after network restart",e); logException ("error updating state after network restart",e);
} }
} }
} }
@ -2467,7 +2468,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
updateConfiguration("DNSListenAddress","10.0.0.1:" + TorServiceConstants.TOR_DNS_PORT_DEFAULT,false); updateConfiguration("DNSListenAddress","10.0.0.1:" + TorServiceConstants.TOR_DNS_PORT_DEFAULT,false);
} }
// updateConfiguration("DisableNetwork","0", false); updateConfiguration("DisableNetwork","0", false);
saveConfiguration(); saveConfiguration();