From 9fe3ecafc4f63870d7e56f48c558b97180241dd5 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Thu, 7 Nov 2019 17:39:53 +0900 Subject: [PATCH] [NS A04] Store changes in rematchNetworkAndRequests in a map This is a preliminary change to move the code that chooses what network gets assigned to what request out of ConnectivityService. By storing the list of changes first, it becomes possible to move the changes with side-effects to a later part of the code, after the decisions have been made. This move is implemented in a later change. Bug: 113554781 Test: ConnectivityServiceTest Change-Id: I60fe318a8eabf13d1c07b144367ca92cf07e734e --- .../com/android/server/ConnectivityService.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index 1a86239c40..b614462af3 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -146,6 +146,7 @@ import android.security.Credentials; import android.security.KeyStore; import android.telephony.TelephonyManager; import android.text.TextUtils; +import android.util.ArrayMap; import android.util.ArraySet; import android.util.LocalLog; import android.util.Log; @@ -6333,10 +6334,12 @@ public class ConnectivityService extends IConnectivityManager.Stub if (VDBG || DDBG) log("rematching " + newNetwork.name()); + final ArrayMap reassignedRequests = new ArrayMap<>(); + // Find and migrate to this Network any NetworkRequests for // which this network is now the best. - ArrayList affectedNetworks = new ArrayList<>(); - ArrayList addedRequests = new ArrayList<>(); + final ArrayList removedRequests = new ArrayList<>(); + final ArrayList addedRequests = new ArrayList<>(); NetworkCapabilities nc = newNetwork.networkCapabilities; if (VDBG) log(" network has: " + nc); for (NetworkRequestInfo nri : mNetworkRequests.values()) { @@ -6369,6 +6372,7 @@ public class ConnectivityService extends IConnectivityManager.Stub ", newScore = " + score); } if (currentNetwork == null || currentNetwork.getCurrentScore() < score) { + reassignedRequests.put(nri, newNetwork); if (VDBG) log("rematch for " + newNetwork.name()); if (currentNetwork != null) { if (VDBG || DDBG){ @@ -6376,7 +6380,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } currentNetwork.removeRequest(nri.request.requestId); currentNetwork.lingerRequest(nri.request, now, mLingerDelayMs); - affectedNetworks.add(currentNetwork); + removedRequests.add(currentNetwork); } else { if (VDBG || DDBG) log(" accepting network in place of null"); } @@ -6402,6 +6406,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } } } else if (newNetwork.isSatisfyingRequest(nri.request.requestId)) { + reassignedRequests.put(nri, null); // If "newNetwork" is listed as satisfying "nri" but no longer satisfies "nri", // mark it as no longer satisfying "nri". Because networks are processed by // rematchAllNetworksAndRequests() in descending score order, "currentNetwork" will @@ -6472,7 +6477,7 @@ public class ConnectivityService extends IConnectivityManager.Stub // Linger any networks that are no longer needed. This should be done after sending the // available callback for newNetwork. - for (NetworkAgentInfo nai : affectedNetworks) { + for (NetworkAgentInfo nai : removedRequests) { updateLingerState(nai, now); } // Possibly unlinger newNetwork. Unlingering a network does not send any callbacks so it