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

Commit 12fcce53 authored by James Mattis's avatar James Mattis
Browse files

Update to unneeded for multilayered requests

Update to ConnectivityService.unneeded in order to support multilayered
requests.

Bug: 173432311
Bug: 171991028
Test: atest FrameworksNetTests
atest FrameworksNetIntegrationTests
atest CtsNetTestCasesLatestSdk

Change-Id: If040d61e33d86a9f9bbc7d50ead596d210a4f82c
parent e80c5b33
Loading
Loading
Loading
Loading
+46 −14
Original line number Diff line number Diff line
@@ -3560,15 +3560,42 @@ public class ConnectivityService extends IConnectivityManager.Stub
            return false;
        }
        for (NetworkRequestInfo nri : mNetworkRequests.values()) {
            if (reason == UnneededFor.LINGER && nri.request.isBackgroundRequest()) {
            if (reason == UnneededFor.LINGER
                    && !nri.isMultilayerRequest()
                    && nri.mRequests.get(0).isBackgroundRequest()) {
                // Background requests don't affect lingering.
                continue;
            }

            if (isNetworkPotentialSatisfier(nai, nri)) {
                return false;
            }
        }
        return true;
    }

    private boolean isNetworkPotentialSatisfier(
            @NonNull final NetworkAgentInfo candidate, @NonNull final NetworkRequestInfo nri) {
        // listen requests won't keep up a network satisfying it. If this is not a multilayer
        // request, we can return immediately. For multilayer requests, we have to check to see if
        // any of the multilayer requests may have a potential satisfier.
        if (!nri.isMultilayerRequest() && nri.mRequests.get(0).isListen()) {
            return false;
        }
        for (final NetworkRequest req : nri.mRequests) {
            // As non-multilayer listen requests have already returned, the below would only happen
            // for a multilayer request therefore continue to the next request if available.
            if (req.isListen()) {
                continue;
            }
            // If this Network is already the highest scoring Network for a request, or if
            // there is hope for it to become one if it validated, then it is needed.
            if (nri.request.isRequest() && nai.satisfies(nri.request) &&
                    (nai.isSatisfyingRequest(nri.request.requestId) ||
            if (candidate.satisfies(req)) {
                // As soon as a network is found that satisfies a request, return. Specifically for
                // multilayer requests, returning as soon as a NetworkAgentInfo satisfies a request
                // is important so as to not evaluate lower priority requests further in
                // nri.mRequests.
                final boolean isNetworkNeeded = candidate.isSatisfyingRequest(req.requestId)
                        // Note that this catches two important cases:
                        // 1. Unvalidated cellular will not be reaped when unvalidated WiFi
                        //    is currently satisfying the request.  This is desirable when
@@ -3576,12 +3603,13 @@ public class ConnectivityService extends IConnectivityManager.Stub
                        // 2. Unvalidated WiFi will not be reaped when validated cellular
                        //    is currently satisfying the request.  This is desirable when
                        //    WiFi ends up validating and out scoring cellular.
                    nri.mSatisfier.getCurrentScore()
                            < nai.getCurrentScoreAsValidated())) {
                return false;
                        || nri.mSatisfier.getCurrentScore()
                        < candidate.getCurrentScoreAsValidated();
                return isNetworkNeeded;
            }
        }
        return true;

        return false;
    }

    private NetworkRequestInfo getNriForAppRequest(
@@ -5451,6 +5479,10 @@ public class ConnectivityService extends IConnectivityManager.Stub
            this(r, null);
        }

        boolean isMultilayerRequest() {
            return mRequests.size() > 1;
        }

        private List<NetworkRequest> initializeRequests(NetworkRequest r) {
            final ArrayList<NetworkRequest> tempRequests = new ArrayList<>();
            tempRequests.add(new NetworkRequest(r));