Fix handling of multiple possible default networks

Old code assumed only 2 choices but now we have more.

bug:3328196
Change-Id: I92a02b31fae6c53f73b3684581230fad5cb1b82a
This commit is contained in:
Robert Greenwalt
2011-01-06 15:41:07 -08:00
parent f444f50b79
commit 9256485b0b

View File

@@ -1132,11 +1132,13 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} }
} }
// returns null if no failover available // returns null if no failover available, otherwise returns the highest
// priority network we're trying
private NetworkStateTracker tryFailover(int prevNetType) { private NetworkStateTracker tryFailover(int prevNetType) {
/* /*
* If this is a default network, check if other defaults are available * If this is a default network, check if other defaults are available.
* or active * Try to reconnect on all available and let them hash it out when
* more than one connects.
*/ */
NetworkStateTracker newNet = null; NetworkStateTracker newNet = null;
if (mNetAttributes[prevNetType].isDefault()) { if (mNetAttributes[prevNetType].isDefault()) {
@@ -1149,54 +1151,30 @@ public class ConnectivityService extends IConnectivityManager.Stub {
for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) { for (int checkType=0; checkType <= ConnectivityManager.MAX_NETWORK_TYPE; checkType++) {
if (checkType == prevNetType) continue; if (checkType == prevNetType) continue;
if (mNetAttributes[checkType] == null) continue; if (mNetAttributes[checkType] == null) continue;
if (mNetAttributes[checkType].isDefault()) { if (!mNetAttributes[checkType].isDefault()) continue;
/* TODO - if we have multiple nets we could use if (!mNetTrackers[checkType].isAvailable()) continue;
* we may want to put more thought into which we choose
*/ NetworkStateTracker tracker = mNetTrackers[checkType];
NetworkInfo info = tracker.getNetworkInfo();
if (!info.isConnectedOrConnecting() ||
tracker.isTeardownRequested()) {
info.setFailover(true);
tracker.reconnect();
}
if (DBG) log("Attempting to switch to " + info.getTypeName());
// figure out if this is the highest priority network
// so we send an appropriate return value
if (checkType == mNetworkPreference) { if (checkType == mNetworkPreference) {
newType = checkType; newType = checkType;
break;
} }
if (mNetAttributes[checkType].mPriority > newPriority) { if (mNetAttributes[checkType].mPriority > newPriority &&
newType != mNetworkPreference) {
newType = checkType; newType = checkType;
newPriority = mNetAttributes[newType].mPriority; newPriority = mNetAttributes[newType].mPriority;
} }
} }
} }
if (newType != -1) {
newNet = mNetTrackers[newType];
/**
* See if the other network is available to fail over to.
* If is not available, we enable it anyway, so that it
* will be able to connect when it does become available,
* but we report a total loss of connectivity rather than
* report that we are attempting to fail over.
*/
if (newNet.isAvailable()) {
NetworkInfo switchTo = newNet.getNetworkInfo();
switchTo.setFailover(true);
if (!switchTo.isConnectedOrConnecting() ||
newNet.isTeardownRequested()) {
newNet.reconnect();
}
if (DBG) {
if (switchTo.isConnected()) {
log("Switching to already connected " + switchTo.getTypeName());
} else {
log("Attempting to switch to " + switchTo.getTypeName());
}
}
} else {
newNet.reconnect();
newNet = null; // not officially avail.. try anyway, but
// report no failover
}
} else {
loge("Network failover failing.");
}
}
return newNet; return newNet;
} }