[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
This commit is contained in:
@@ -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<NetworkRequestInfo, NetworkAgentInfo> reassignedRequests = new ArrayMap<>();
|
||||
|
||||
// Find and migrate to this Network any NetworkRequests for
|
||||
// which this network is now the best.
|
||||
ArrayList<NetworkAgentInfo> affectedNetworks = new ArrayList<>();
|
||||
ArrayList<NetworkRequestInfo> addedRequests = new ArrayList<>();
|
||||
final ArrayList<NetworkAgentInfo> removedRequests = new ArrayList<>();
|
||||
final ArrayList<NetworkRequestInfo> 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
|
||||
|
||||
Reference in New Issue
Block a user