[NS B01] Move the computation loop to a separate function
Bug: 113554781 Test: FrameworksNetTests Change-Id: I6c28c7af5c600d35aa1e9328b6c988dadb921f51
This commit is contained in:
@@ -6656,7 +6656,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
// @param now the time the rematch starts, as returned by SystemClock.elapsedRealtime();
|
// @param now the time the rematch starts, as returned by SystemClock.elapsedRealtime();
|
||||||
private void rematchNetworkAndRequests(@NonNull final NetworkReassignment changes,
|
private void rematchNetworkAndRequests(@NonNull final NetworkReassignment changes,
|
||||||
@NonNull final NetworkAgentInfo newNetwork) {
|
@NonNull final NetworkAgentInfo newNetwork) {
|
||||||
ensureRunningOnConnectivityServiceThread();
|
|
||||||
if (!newNetwork.everConnected) return;
|
if (!newNetwork.everConnected) return;
|
||||||
|
|
||||||
changes.addRematchedNetwork(new NetworkReassignment.NetworkBgStatePair(newNetwork,
|
changes.addRematchedNetwork(new NetworkReassignment.NetworkBgStatePair(newNetwork,
|
||||||
@@ -6696,6 +6695,22 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
nri.mSatisfier = newSatisfier;
|
nri.mSatisfier = newSatisfier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private NetworkReassignment computeNetworkReassignment() {
|
||||||
|
ensureRunningOnConnectivityServiceThread();
|
||||||
|
final NetworkAgentInfo[] nais = mNetworkAgentInfos.values().toArray(
|
||||||
|
new NetworkAgentInfo[mNetworkAgentInfos.size()]);
|
||||||
|
// Rematch higher scoring networks first to prevent requests first matching a lower
|
||||||
|
// scoring network and then a higher scoring network, which could produce multiple
|
||||||
|
// callbacks.
|
||||||
|
Arrays.sort(nais);
|
||||||
|
final NetworkReassignment changes = computeInitialReassignment();
|
||||||
|
for (final NetworkAgentInfo nai : nais) {
|
||||||
|
rematchNetworkAndRequests(changes, nai);
|
||||||
|
}
|
||||||
|
return changes;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to rematch all Networks with NetworkRequests. This may result in Networks
|
* Attempt to rematch all Networks with NetworkRequests. This may result in Networks
|
||||||
* being disconnected.
|
* being disconnected.
|
||||||
@@ -6709,16 +6724,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
final long now = SystemClock.elapsedRealtime();
|
final long now = SystemClock.elapsedRealtime();
|
||||||
final NetworkAgentInfo oldDefaultNetwork = getDefaultNetwork();
|
final NetworkAgentInfo oldDefaultNetwork = getDefaultNetwork();
|
||||||
|
|
||||||
final NetworkAgentInfo[] nais = mNetworkAgentInfos.values().toArray(
|
final NetworkReassignment changes = computeNetworkReassignment();
|
||||||
new NetworkAgentInfo[mNetworkAgentInfos.size()]);
|
|
||||||
// Rematch higher scoring networks first to prevent requests first matching a lower
|
|
||||||
// scoring network and then a higher scoring network, which could produce multiple
|
|
||||||
// callbacks.
|
|
||||||
Arrays.sort(nais);
|
|
||||||
final NetworkReassignment changes = computeInitialReassignment();
|
|
||||||
for (final NetworkAgentInfo nai : nais) {
|
|
||||||
rematchNetworkAndRequests(changes, nai);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now that the entire rematch is computed, update the lists of satisfied requests in
|
// Now that the entire rematch is computed, update the lists of satisfied requests in
|
||||||
// the network agents. This is necessary because some code later depends on this state
|
// the network agents. This is necessary because some code later depends on this state
|
||||||
@@ -6773,6 +6779,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Collection<NetworkAgentInfo> nais = mNetworkAgentInfos.values();
|
||||||
|
|
||||||
// Update the linger state before processing listen callbacks, because the background
|
// Update the linger state before processing listen callbacks, because the background
|
||||||
// computation depends on whether the network is lingering. Don't send the LOSING callbacks
|
// computation depends on whether the network is lingering. Don't send the LOSING callbacks
|
||||||
// just yet though, because they have to be sent after the listens are processed to keep
|
// just yet though, because they have to be sent after the listens are processed to keep
|
||||||
@@ -6849,7 +6857,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
|||||||
private void updateLegacyTypeTrackerAndVpnLockdownForRematch(
|
private void updateLegacyTypeTrackerAndVpnLockdownForRematch(
|
||||||
@Nullable final NetworkAgentInfo oldDefaultNetwork,
|
@Nullable final NetworkAgentInfo oldDefaultNetwork,
|
||||||
@Nullable final NetworkAgentInfo newDefaultNetwork,
|
@Nullable final NetworkAgentInfo newDefaultNetwork,
|
||||||
@NonNull final NetworkAgentInfo[] nais) {
|
@NonNull final Collection<NetworkAgentInfo> nais) {
|
||||||
if (oldDefaultNetwork != newDefaultNetwork) {
|
if (oldDefaultNetwork != newDefaultNetwork) {
|
||||||
// Maintain the illusion : since the legacy API only understands one network at a time,
|
// Maintain the illusion : since the legacy API only understands one network at a time,
|
||||||
// if the default network changed, apps should see a disconnected broadcast for the
|
// if the default network changed, apps should see a disconnected broadcast for the
|
||||||
|
|||||||
Reference in New Issue
Block a user