Reset connections AFTER we take down the network.

If you do it before you have a race condition and some apps will
manage to reconnect on the dieing network before it goes and then
get no notification when it goes.

bug: 3408025
Change-Id: I5386ff313c759b3f687bc38731454ab43dbe76b8
This commit is contained in:
Robert Greenwalt
2011-06-15 12:22:07 -07:00
parent f17deff97b
commit 36ea869426

View File

@@ -1129,8 +1129,30 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
} }
intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished); intent.putExtra(ConnectivityManager.EXTRA_INET_CONDITION, mDefaultInetConditionPublished);
// Reset interface if no other connections are using the same interface
boolean doReset = true;
LinkProperties linkProperties = mNetTrackers[prevNetType].getLinkProperties();
if (linkProperties != null) {
String oldIface = linkProperties.getInterfaceName();
if (TextUtils.isEmpty(oldIface) == false) {
for (NetworkStateTracker networkStateTracker : mNetTrackers) {
if (networkStateTracker == null) continue;
NetworkInfo networkInfo = networkStateTracker.getNetworkInfo();
if (networkInfo.isConnected() && networkInfo.getType() != prevNetType) {
LinkProperties l = networkStateTracker.getLinkProperties();
if (l == null) continue;
if (oldIface.equals(l.getInterfaceName())) {
doReset = false;
break;
}
}
}
}
}
// do this before we broadcast the change // do this before we broadcast the change
handleConnectivityChange(prevNetType); handleConnectivityChange(prevNetType, doReset);
sendStickyBroadcast(intent); sendStickyBroadcast(intent);
/* /*
@@ -1354,7 +1376,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
thisNet.setTeardownRequested(false); thisNet.setTeardownRequested(false);
updateNetworkSettings(thisNet); updateNetworkSettings(thisNet);
handleConnectivityChange(type); handleConnectivityChange(type, false);
sendConnectedBroadcast(info); sendConnectedBroadcast(info);
} }
@@ -1364,7 +1386,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
* according to which networks are connected, and ensuring that the * according to which networks are connected, and ensuring that the
* right routing table entries exist. * right routing table entries exist.
*/ */
private void handleConnectivityChange(int netType) { private void handleConnectivityChange(int netType, boolean doReset) {
/* /*
* If a non-default network is enabled, add the host routes that * If a non-default network is enabled, add the host routes that
* will allow it's DNS servers to be accessed. * will allow it's DNS servers to be accessed.
@@ -1391,6 +1413,17 @@ public class ConnectivityService extends IConnectivityManager.Stub {
removePrivateDnsRoutes(mNetTrackers[netType]); removePrivateDnsRoutes(mNetTrackers[netType]);
} }
} }
if (doReset) {
LinkProperties linkProperties = mNetTrackers[netType].getLinkProperties();
if (linkProperties != null) {
String iface = linkProperties.getInterfaceName();
if (TextUtils.isEmpty(iface) == false) {
if (DBG) log("resetConnections(" + iface + ")");
NetworkUtils.resetConnections(iface);
}
}
}
} }
private void addPrivateDnsRoutes(NetworkStateTracker nt) { private void addPrivateDnsRoutes(NetworkStateTracker nt) {
@@ -1833,7 +1866,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
break; break;
case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED: case NetworkStateTracker.EVENT_CONFIGURATION_CHANGED:
info = (NetworkInfo) msg.obj; info = (NetworkInfo) msg.obj;
handleConnectivityChange(info.getType()); handleConnectivityChange(info.getType(), true);
break; break;
case EVENT_CLEAR_NET_TRANSITION_WAKELOCK: case EVENT_CLEAR_NET_TRANSITION_WAKELOCK:
String causedBy = null; String causedBy = null;