Merge "Don't break things if a network goes back to CONNECTED."

This commit is contained in:
Lorenzo Colitti
2014-05-29 12:25:45 +00:00
committed by Android (Google) Code Review

View File

@@ -5606,16 +5606,23 @@ public class ConnectivityService extends IConnectivityManager.Stub {
boolean isNewDefault = false; boolean isNewDefault = false;
if (DBG) log("handleConnectionValidated for "+newNetwork.name()); if (DBG) log("handleConnectionValidated for "+newNetwork.name());
// check if any NetworkRequest wants this NetworkAgent // check if any NetworkRequest wants this NetworkAgent
// first check if it satisfies the NetworkCapabilities
ArrayList<NetworkAgentInfo> affectedNetworks = new ArrayList<NetworkAgentInfo>(); ArrayList<NetworkAgentInfo> affectedNetworks = new ArrayList<NetworkAgentInfo>();
if (VDBG) log(" new Network has: " + newNetwork.networkCapabilities); if (VDBG) log(" new Network has: " + newNetwork.networkCapabilities);
for (NetworkRequestInfo nri : mNetworkRequests.values()) { for (NetworkRequestInfo nri : mNetworkRequests.values()) {
NetworkAgentInfo currentNetwork = mNetworkForRequestId.get(nri.request.requestId);
if (newNetwork == currentNetwork) {
if (VDBG) log("Network " + newNetwork.name() + " was already satisfying" +
" request " + nri.request.requestId + ". No change.");
keep = true;
continue;
}
// check if it satisfies the NetworkCapabilities
if (VDBG) log(" checking if request is satisfied: " + nri.request); if (VDBG) log(" checking if request is satisfied: " + nri.request);
if (nri.request.networkCapabilities.satisfiedByNetworkCapabilities( if (nri.request.networkCapabilities.satisfiedByNetworkCapabilities(
newNetwork.networkCapabilities)) { newNetwork.networkCapabilities)) {
// next check if it's better than any current network we're using for // next check if it's better than any current network we're using for
// this request // this request
NetworkAgentInfo currentNetwork = mNetworkForRequestId.get(nri.request.requestId);
if (VDBG) { if (VDBG) {
log("currentScore = " + log("currentScore = " +
(currentNetwork != null ? currentNetwork.currentScore : 0) + (currentNetwork != null ? currentNetwork.currentScore : 0) +
@@ -5744,12 +5751,19 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
if (state == NetworkInfo.State.CONNECTED) { if (state == NetworkInfo.State.CONNECTED) {
// TODO - check if we want it (optimization)
try { try {
// This is likely caused by the fact that this network already
// exists. An example is when a network goes from CONNECTED to
// CONNECTING and back (like wifi on DHCP renew).
// TODO: keep track of which networks we've created, or ask netd
// to tell us whether we've already created this network or not.
mNetd.createNetwork(networkAgent.network.netId); mNetd.createNetwork(networkAgent.network.netId);
} catch (Exception e) { } catch (Exception e) {
loge("Error creating Network " + networkAgent.network.netId); loge("Error creating network " + networkAgent.network.netId + ": "
+ e.getMessage());
return;
} }
updateLinkProperties(networkAgent, null); updateLinkProperties(networkAgent, null);
notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_PRECHECK); notifyNetworkCallbacks(networkAgent, ConnectivityManager.CALLBACK_PRECHECK);
networkAgent.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_CONNECTED); networkAgent.networkMonitor.sendMessage(NetworkMonitor.CMD_NETWORK_CONNECTED);