Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14c2d1da authored by Chalard Jean's avatar Chalard Jean
Browse files

[NS B01] Move the computation loop to a separate function

Bug: 113554781
Test: FrameworksNetTests
Change-Id: I6c28c7af5c600d35aa1e9328b6c988dadb921f51
parent 5f8010bf
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -6656,7 +6656,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
    // @param now the time the rematch starts, as returned by SystemClock.elapsedRealtime();
    private void rematchNetworkAndRequests(@NonNull final NetworkReassignment changes,
            @NonNull final NetworkAgentInfo newNetwork) {
        ensureRunningOnConnectivityServiceThread();
        if (!newNetwork.everConnected) return;

        changes.addRematchedNetwork(new NetworkReassignment.NetworkBgStatePair(newNetwork,
@@ -6696,6 +6695,22 @@ public class ConnectivityService extends IConnectivityManager.Stub
        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
     * being disconnected.
@@ -6709,16 +6724,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
        final long now = SystemClock.elapsedRealtime();
        final NetworkAgentInfo oldDefaultNetwork = getDefaultNetwork();

        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);
        }
        final NetworkReassignment changes = computeNetworkReassignment();

        // 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
@@ -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
        // 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
@@ -6849,7 +6857,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
    private void updateLegacyTypeTrackerAndVpnLockdownForRematch(
            @Nullable final NetworkAgentInfo oldDefaultNetwork,
            @Nullable final NetworkAgentInfo newDefaultNetwork,
            @NonNull final NetworkAgentInfo[] nais) {
            @NonNull final Collection<NetworkAgentInfo> nais) {
        if (oldDefaultNetwork != newDefaultNetwork) {
            // 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