[NS A40] Read current reassignment state instead of global state

The reassignment state has the future value, but is transient
instead of global. With this, the reassignment loop does not
read from global state any more, so it's not affected by the
side effects from the loop.

This means future patches will be able to move the side effects
out of the computation.

Test: atest ConnectivityServiceTest
Change-Id: I43499f19730bcd94b691cfea83aa1ca1d3de75db
This commit is contained in:
Chalard Jean
2019-12-03 23:16:10 +09:00
parent 933ebfa503
commit 7e416aa19e

View File

@@ -6511,6 +6511,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
} }
private ArrayMap<NetworkRequestInfo, NetworkAgentInfo> computeRequestReassignmentForNetwork( private ArrayMap<NetworkRequestInfo, NetworkAgentInfo> computeRequestReassignmentForNetwork(
@NonNull final NetworkReassignment changes,
@NonNull final NetworkAgentInfo newNetwork) { @NonNull final NetworkAgentInfo newNetwork) {
final int score = newNetwork.getCurrentScore(); final int score = newNetwork.getCurrentScore();
final ArrayMap<NetworkRequestInfo, NetworkAgentInfo> reassignedRequests = new ArrayMap<>(); final ArrayMap<NetworkRequestInfo, NetworkAgentInfo> reassignedRequests = new ArrayMap<>();
@@ -6521,7 +6522,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
// requests or not, and doesn't affect the network's score. // requests or not, and doesn't affect the network's score.
if (nri.request.isListen()) continue; if (nri.request.isListen()) continue;
final NetworkAgentInfo currentNetwork = nri.mSatisfier; // The reassignment has been seeded with the initial assignment, therefore
// getReassignment can't be null and mNewNetwork is only null if there was no
// satisfier in the first place or there was an explicit reassignment to null.
final NetworkAgentInfo currentNetwork = changes.getReassignment(nri).mNewNetwork;
final boolean satisfies = newNetwork.satisfies(nri.request); final boolean satisfies = newNetwork.satisfies(nri.request);
if (newNetwork == currentNetwork && satisfies) continue; if (newNetwork == currentNetwork && satisfies) continue;
@@ -6571,7 +6575,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
if (VDBG || DDBG) log("rematching " + newNetwork.name()); if (VDBG || DDBG) log("rematching " + newNetwork.name());
final ArrayMap<NetworkRequestInfo, NetworkAgentInfo> reassignedRequests = final ArrayMap<NetworkRequestInfo, NetworkAgentInfo> reassignedRequests =
computeRequestReassignmentForNetwork(newNetwork); computeRequestReassignmentForNetwork(changes, newNetwork);
// Find and migrate to this Network any NetworkRequests for // Find and migrate to this Network any NetworkRequests for
// which this network is now the best. // which this network is now the best.