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

Commit 0747b739 authored by Chalard Jean's avatar Chalard Jean Committed by Android (Google) Code Review
Browse files

Merge changes Ib5cd2c27,I4448a354 into sc-dev

* changes:
  [NS10] Fix a bug where registerIgnoringScore is broken
  [NS09] Implement the new ranking code
parents 733c4088 b4dea027
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ public final class NetworkScore implements Parcelable {

    @Override
    public String toString() {
        return "Score(" + mLegacyInt + ")";
        return "Score(" + mLegacyInt + " ; Policies : " + mPolicies + ")";
    }

    @Override
+0 −1
Original line number Diff line number Diff line
@@ -225,7 +225,6 @@ filegroup {
        "java/com/android/server/NetIdManager.java",
        "java/com/android/server/TestNetworkService.java",
        "java/com/android/server/connectivity/AutodestructReference.java",
        "java/com/android/server/connectivity/ConnectivityConstants.java",
        "java/com/android/server/connectivity/DnsManager.java",
        "java/com/android/server/connectivity/FullScore.java",
        "java/com/android/server/connectivity/KeepaliveTracker.java",
+2 −3
Original line number Diff line number Diff line
@@ -7748,7 +7748,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
            NetworkAgentInfo bestNetwork = null;
            NetworkRequest bestRequest = null;
            for (final NetworkRequest req : nri.mRequests) {
                bestNetwork = mNetworkRanker.getBestNetwork(req, nais);
                bestNetwork = mNetworkRanker.getBestNetwork(req, nais, nri.getSatisfier());
                // Stop evaluating as the highest possible priority request is satisfied.
                if (null != bestNetwork) {
                    bestRequest = req;
@@ -8001,7 +8001,6 @@ public class ConnectivityService extends IConnectivityManager.Stub
            @NonNull final NetworkOffer offer, @NonNull final NetworkRanker networkRanker) {
        final NetworkRequest activeRequest = nri.isBeingSatisfied() ? nri.getActiveRequest() : null;
        final NetworkAgentInfo satisfier = null != activeRequest ? nri.getSatisfier() : null;
        final FullScore satisfierScore = null != satisfier ? satisfier.getScore() : null;

        // Multi-layer requests have a currently active request, the one being satisfied.
        // Since the system will try to bring up a better network than is currently satisfying
@@ -8040,7 +8039,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
                    && satisfier.factorySerialNumber == offer.providerId;
            final boolean newNeeded = (currentlyServing
                    || (activeRequest.canBeSatisfiedBy(offer.caps)
                            && networkRanker.mightBeat(activeRequest, satisfierScore, offer)));
                            && networkRanker.mightBeat(activeRequest, satisfier, offer)));
            if (newNeeded != oldNeeded) {
                if (newNeeded) {
                    offer.onNetworkNeeded(activeRequest);
+0 −28
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.connectivity;

/**
 * A class encapsulating various constants used by Connectivity.
 * TODO : remove this class.
 * @hide
 */
public class ConnectivityConstants {
    // VPNs typically have priority over other networks. Give them a score that will
    // let them win every single time.
    public static final int VPN_DEFAULT_SCORE = 101;
}
+21 −7
Original line number Diff line number Diff line
@@ -86,9 +86,14 @@ public class FullScore {
    /** @hide */
    public static final int POLICY_IS_UNMETERED = 59;

    // This network is invincible. This is useful for offers until there is an API to listen
    // to requests.
    /** @hide */
    public static final int POLICY_IS_INVINCIBLE = 58;

    // To help iterate when printing
    @VisibleForTesting
    static final int MIN_CS_MANAGED_POLICY = POLICY_IS_UNMETERED;
    static final int MIN_CS_MANAGED_POLICY = POLICY_IS_INVINCIBLE;
    @VisibleForTesting
    static final int MAX_CS_MANAGED_POLICY = POLICY_IS_VALIDATED;

@@ -109,6 +114,7 @@ public class FullScore {
            case POLICY_YIELD_TO_BAD_WIFI: return "YIELD_TO_BAD_WIFI";
            case POLICY_TRANSPORT_PRIMARY: return "TRANSPORT_PRIMARY";
            case POLICY_EXITING: return "EXITING";
            case POLICY_IS_INVINCIBLE: return "INVINCIBLE";
        }
        throw new IllegalArgumentException("Unknown policy : " + policy);
    }
@@ -147,7 +153,8 @@ public class FullScore {
                caps.hasCapability(NET_CAPABILITY_NOT_METERED),
                config.explicitlySelected,
                config.acceptUnvalidated,
                yieldToBadWiFi);
                yieldToBadWiFi,
                false /* invincible */); // only prospective scores can be invincible
    }

    /**
@@ -178,8 +185,12 @@ public class FullScore {
        final boolean acceptUnvalidated = false;
        // Don't assume clinging to bad wifi
        final boolean yieldToBadWiFi = false;
        // A prospective score is invincible if the legacy int in the filter is over the maximum
        // score.
        final boolean invincible = score.getLegacyInt() > NetworkRanker.LEGACY_INT_MAX;
        return withPolicies(score.getLegacyInt(), score.getPolicies(), KEEP_CONNECTED_NONE,
                mayValidate, vpn, unmetered, everUserSelected, acceptUnvalidated, yieldToBadWiFi);
                mayValidate, vpn, unmetered, everUserSelected, acceptUnvalidated, yieldToBadWiFi,
                invincible);
    }

    /**
@@ -193,14 +204,15 @@ public class FullScore {
    // telephony factory, so that it depends on the carrier. For now this is handled by
    // connectivity for backward compatibility.
    public FullScore mixInScore(@NonNull final NetworkCapabilities caps,
            @NonNull final NetworkAgentConfig config, final boolean avoidBadWiFi) {
            @NonNull final NetworkAgentConfig config, final boolean yieldToBadWifi) {
        return withPolicies(mLegacyInt, mPolicies, mKeepConnectedReason,
                caps.hasCapability(NET_CAPABILITY_VALIDATED),
                caps.hasTransport(TRANSPORT_VPN),
                caps.hasCapability(NET_CAPABILITY_NOT_METERED),
                config.explicitlySelected,
                config.acceptUnvalidated,
                avoidBadWiFi);
                yieldToBadWifi,
                false /* invincible */); // only prospective scores can be invincible
    }

    // TODO : this shouldn't manage bad wifi avoidance – instead this should be done by the
@@ -214,14 +226,16 @@ public class FullScore {
            final boolean isUnmetered,
            final boolean everUserSelected,
            final boolean acceptUnvalidated,
            final boolean yieldToBadWiFi) {
            final boolean yieldToBadWiFi,
            final boolean invincible) {
        return new FullScore(legacyInt, (externalPolicies & EXTERNAL_POLICIES_MASK)
                | (isValidated       ? 1L << POLICY_IS_VALIDATED : 0)
                | (isVpn             ? 1L << POLICY_IS_VPN : 0)
                | (isUnmetered       ? 1L << POLICY_IS_UNMETERED : 0)
                | (everUserSelected  ? 1L << POLICY_EVER_USER_SELECTED : 0)
                | (acceptUnvalidated ? 1L << POLICY_ACCEPT_UNVALIDATED : 0)
                | (yieldToBadWiFi    ? 1L << POLICY_YIELD_TO_BAD_WIFI : 0),
                | (yieldToBadWiFi    ? 1L << POLICY_YIELD_TO_BAD_WIFI : 0)
                | (invincible        ? 1L << POLICY_IS_INVINCIBLE : 0),
                keepConnectedReason);
    }

Loading