Clean up when we switch networks.

Need to unhitch mNetworkForRequestId when a network is no longer
satisfying a request.

Change-Id: I3b3cde7dd92ec87a76ae7a0825ad22e892fa8fd5
This commit is contained in:
Robert Greenwalt
2014-05-16 08:54:07 -07:00
parent 00a2f34c9a
commit 09f5803344
2 changed files with 5 additions and 0 deletions

View File

@@ -66,6 +66,7 @@ public abstract class NetworkAgent extends Handler {
private AsyncChannel mAsyncChannel; private AsyncChannel mAsyncChannel;
private final String LOG_TAG; private final String LOG_TAG;
private static final boolean DBG = true; private static final boolean DBG = true;
private static final boolean VDBG = true;
// TODO - this class shouldn't cache data or it runs the risk of getting out of sync // TODO - this class shouldn't cache data or it runs the risk of getting out of sync
// Make the API require each of these when any is updated so we have the data we need, // Make the API require each of these when any is updated so we have the data we need,
// without caching. // without caching.
@@ -266,11 +267,14 @@ public abstract class NetworkAgent extends Handler {
*/ */
private void evalScores() { private void evalScores() {
if (mConnectionRequested) { if (mConnectionRequested) {
if (VDBG) log("evalScores - already trying - size=" + mNetworkRequests.size());
// already trying // already trying
return; return;
} }
if (VDBG) log("evalScores!");
for (int i=0; i < mNetworkRequests.size(); i++) { for (int i=0; i < mNetworkRequests.size(); i++) {
int score = mNetworkRequests.valueAt(i).score; int score = mNetworkRequests.valueAt(i).score;
if (VDBG) log(" checking request Min " + score + " vs my score " + mNetworkScore);
if (score < mNetworkScore) { if (score < mNetworkScore) {
// have a request that has a lower scored network servicing it // have a request that has a lower scored network servicing it
// (or no network) than we could provide, so lets connect! // (or no network) than we could provide, so lets connect!

View File

@@ -3216,6 +3216,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
// tell the network currently servicing this that it's no longer interested // tell the network currently servicing this that it's no longer interested
NetworkAgentInfo affectedNetwork = mNetworkForRequestId.get(nri.request.requestId); NetworkAgentInfo affectedNetwork = mNetworkForRequestId.get(nri.request.requestId);
if (affectedNetwork != null) { if (affectedNetwork != null) {
mNetworkForRequestId.remove(nri.request.requestId);
affectedNetwork.networkRequests.remove(nri.request.requestId); affectedNetwork.networkRequests.remove(nri.request.requestId);
if (VDBG) { if (VDBG) {
log(" Removing from current network " + affectedNetwork.name() + ", leaving " + log(" Removing from current network " + affectedNetwork.name() + ", leaving " +