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

Commit ee22e0d5 authored by Benedict Wong's avatar Benedict Wong
Browse files

Add minimum required bandwidth to network templates

This change adds a minimum required bandwidth to the VCN network
templates, ensuring that a minimum bar of throughput can be required of
underlying networks.

Bug: 211008106
Test: atest FrameworksVcnTests
Change-Id: I929428f75e5e543966a03061d13f300dd8b0956f
parent 179826ef
Loading
Loading
Loading
Loading
+124 −25
Original line number Diff line number Diff line
@@ -63,13 +63,22 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
    private final int mOpportunisticMatchCriteria;

    private VcnCellUnderlyingNetworkTemplate(
            int networkQuality,
            int meteredMatchCriteria,
            int minEntryUpstreamBandwidthKbps,
            int minExitUpstreamBandwidthKbps,
            int minEntryDownstreamBandwidthKbps,
            int minExitDownstreamBandwidthKbps,
            Set<String> allowedNetworkPlmnIds,
            Set<Integer> allowedSpecificCarrierIds,
            int roamingMatchCriteria,
            int opportunisticMatchCriteria) {
        super(NETWORK_PRIORITY_TYPE_CELL, networkQuality, meteredMatchCriteria);
        super(
                NETWORK_PRIORITY_TYPE_CELL,
                meteredMatchCriteria,
                minEntryUpstreamBandwidthKbps,
                minExitUpstreamBandwidthKbps,
                minEntryDownstreamBandwidthKbps,
                minExitDownstreamBandwidthKbps);
        mAllowedNetworkPlmnIds = new ArraySet<>(allowedNetworkPlmnIds);
        mAllowedSpecificCarrierIds = new ArraySet<>(allowedSpecificCarrierIds);
        mRoamingMatchCriteria = roamingMatchCriteria;
@@ -109,9 +118,17 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
            @NonNull PersistableBundle in) {
        Objects.requireNonNull(in, "PersistableBundle is null");

        final int networkQuality = in.getInt(NETWORK_QUALITY_KEY);
        final int meteredMatchCriteria = in.getInt(METERED_MATCH_KEY);

        final int minEntryUpstreamBandwidthKbps =
                in.getInt(MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS_KEY, DEFAULT_MIN_BANDWIDTH_KBPS);
        final int minExitUpstreamBandwidthKbps =
                in.getInt(MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS_KEY, DEFAULT_MIN_BANDWIDTH_KBPS);
        final int minEntryDownstreamBandwidthKbps =
                in.getInt(MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS_KEY, DEFAULT_MIN_BANDWIDTH_KBPS);
        final int minExitDownstreamBandwidthKbps =
                in.getInt(MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS_KEY, DEFAULT_MIN_BANDWIDTH_KBPS);

        final PersistableBundle plmnIdsBundle =
                in.getPersistableBundle(ALLOWED_NETWORK_PLMN_IDS_KEY);
        Objects.requireNonNull(plmnIdsBundle, "plmnIdsBundle is null");
@@ -131,8 +148,11 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
        final int opportunisticMatchCriteria = in.getInt(OPPORTUNISTIC_MATCH_KEY);

        return new VcnCellUnderlyingNetworkTemplate(
                networkQuality,
                meteredMatchCriteria,
                minEntryUpstreamBandwidthKbps,
                minExitUpstreamBandwidthKbps,
                minEntryDownstreamBandwidthKbps,
                minExitDownstreamBandwidthKbps,
                allowedNetworkPlmnIds,
                allowedSpecificCarrierIds,
                roamingMatchCriteria,
@@ -243,7 +263,6 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork

    /** This class is used to incrementally build VcnCellUnderlyingNetworkTemplate objects. */
    public static final class Builder {
        private int mNetworkQuality = NETWORK_QUALITY_ANY;
        private int mMeteredMatchCriteria = MATCH_ANY;

        @NonNull private final Set<String> mAllowedNetworkPlmnIds = new ArraySet<>();
@@ -252,28 +271,14 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
        private int mRoamingMatchCriteria = MATCH_ANY;
        private int mOpportunisticMatchCriteria = MATCH_ANY;

        private int mMinEntryUpstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;
        private int mMinExitUpstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;
        private int mMinEntryDownstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;
        private int mMinExitDownstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;

        /** Construct a Builder object. */
        public Builder() {}

        /**
         * Set the required network quality to match this template.
         *
         * <p>Network quality is a aggregation of multiple signals that reflect the network link
         * metrics. For example, the network validation bit (see {@link
         * NetworkCapabilities#NET_CAPABILITY_VALIDATED}), estimated first hop transport bandwidth
         * and signal strength.
         *
         * @param networkQuality the required network quality. Defaults to NETWORK_QUALITY_ANY
         * @hide
         */
        @NonNull
        public Builder setNetworkQuality(@NetworkQuality int networkQuality) {
            validateNetworkQuality(networkQuality);

            mNetworkQuality = networkQuality;
            return this;
        }

        /**
         * Set the matching criteria for metered networks.
         *
@@ -369,12 +374,106 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
            return this;
        }

        /**
         * Set the minimum accepted entry and exit upstream bandwidth allowed by this template.
         *
         * <p>The minimum upstream bandwidth condition allows for separate entry and exit
         * thresholds, allowing for a margin of confidence before matching a network, while
         * requiring a minimum bandwidth to continue being matching. In order to match this
         * template, a network must fulfill one of the following two cases, depending on whether the
         * network being evaluated is the Gateway Connection's underlying network:
         *
         * <ul>
         *   <li>Network IS selected, AND the Network's estimated upstream bandwidth is greater than
         *       or equal to the minExitUpstreamBandwidthKbps provided.
         *   <li>Network IS NOT selected, AND the Network's estimated upstream bandwidth is greater
         *       than or equal to the minEntryUpstreamBandwidthKbps provided.
         * </ul>
         *
         * <p>To prevent a network from being selected (fulfilling the entry criteria), and yet be
         * unable to meet the conditions for staying selected (exit criteria), the entry criteria
         * MUST be greater than, or equal to the exit criteria.
         *
         * <p>Estimated bandwidth of a network is provided by the transport layer, and reported in
         * {@link NetworkCapabilities}. The provided estimates will be used without modification.
         *
         * @param minEntryUpstreamBandwidthKbps the minimum accepted upstream bandwidth for a
         *     network that IS NOT an already-selected underlying network, or {@code 0} to disable
         *     this requirement. MUST be greater than, or equal to minExitUpstreamBandwidthKbps.
         *     Defaults to {@code 0}
         * @param minExitUpstreamBandwidthKbps the minimum accepted upstream bandwidth for a network
         *     that IS the already-selected underlying network, or {@code 0} to disable this
         *     requirement. MUST be less than, or equal to minEntryUpstreamBandwidthKbps. Defaults
         *     to {@code 0}
         * @return this {@link Builder} instance, for chaining
         * @hide
         */
        @NonNull
        public Builder setMinUpstreamBandwidthKbps(
                int minEntryUpstreamBandwidthKbps, int minExitUpstreamBandwidthKbps) {
            validateMinBandwidthKbps(minEntryUpstreamBandwidthKbps, minExitUpstreamBandwidthKbps);

            mMinEntryUpstreamBandwidthKbps = minEntryUpstreamBandwidthKbps;
            mMinExitUpstreamBandwidthKbps = minExitUpstreamBandwidthKbps;

            return this;
        }

        /**
         * Set the minimum acceptable downstream bandwidths allowed by this template.
         *
         * <p>The minimum downstream bandwidth condition allows for separate entry and exit
         * thresholds, allowing for a margin of confidence before matching a network, while
         * requiring a minimum bandwidth to continue being matching. In order to match this
         * template, a network must fulfill one of the following two cases, depending on whether the
         * network being evaluated is the Gateway Connection's underlying network:
         *
         * <ul>
         *   <li>Network IS selected, AND the Network's estimated downstream bandwidth is greater
         *       than or equal to the minExitDownstreamBandwidthKbps provided.
         *   <li>Network IS NOT selected, AND the Network's estimated downstream bandwidth is
         *       greater than or equal to the minEntryDownstreamBandwidthKbps provided.
         * </ul>
         *
         * <p>To prevent a network from being selected (fulfilling the entry criteria), and yet be
         * unable to meet the conditions for staying selected (exit criteria), the entry criteria
         * MUST be greater than, or equal to the exit criteria.
         *
         * <p>Estimated bandwidth of a network is provided by the transport layer, and reported in
         * {@link NetworkCapabilities}. The provided estimates will be used without modification.
         *
         * @param minEntryDownstreamBandwidthKbps the minimum accepted downstream bandwidth for a
         *     network that IS NOT an already-selected underlying network, or {@code 0} to disable
         *     this requirement. MUST be greater than, or equal to minExitDownstreamBandwidthKbps.
         *     Defaults to {@code 0}
         * @param minExitDownstreamBandwidthKbps the minimum accepted downstream bandwidth for a
         *     network that IS the already-selected underlying network, or {@code 0} to disable this
         *     requirement. MUST be less than, or equal to minEntryDownstreamBandwidthKbps. Defaults
         *     to {@code 0}
         * @return this {@link Builder} instance, for chaining
         * @hide
         */
        @NonNull
        public Builder setMinDownstreamBandwidthKbps(
                int minEntryDownstreamBandwidthKbps, int minExitDownstreamBandwidthKbps) {
            validateMinBandwidthKbps(
                    minEntryDownstreamBandwidthKbps, minExitDownstreamBandwidthKbps);

            mMinEntryDownstreamBandwidthKbps = minEntryDownstreamBandwidthKbps;
            mMinExitDownstreamBandwidthKbps = minExitDownstreamBandwidthKbps;

            return this;
        }

        /** Build the VcnCellUnderlyingNetworkTemplate. */
        @NonNull
        public VcnCellUnderlyingNetworkTemplate build() {
            return new VcnCellUnderlyingNetworkTemplate(
                    mNetworkQuality,
                    mMeteredMatchCriteria,
                    mMinEntryUpstreamBandwidthKbps,
                    mMinExitUpstreamBandwidthKbps,
                    mMinEntryDownstreamBandwidthKbps,
                    mMinExitDownstreamBandwidthKbps,
                    mAllowedNetworkPlmnIds,
                    mAllowedSpecificCarrierIds,
                    mRoamingMatchCriteria,
+0 −4
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@ package android.net.vcn;

import static android.net.ipsec.ike.IkeSessionParams.IKE_OPTION_MOBIKE;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK;

import static com.android.internal.annotations.VisibleForTesting.Visibility;

@@ -169,18 +168,15 @@ public final class VcnGatewayConnectionConfig {
    static {
        DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
                new VcnCellUnderlyingNetworkTemplate.Builder()
                        .setNetworkQuality(NETWORK_QUALITY_OK)
                        .setOpportunistic(MATCH_REQUIRED)
                        .build());

        DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
                new VcnWifiUnderlyingNetworkTemplate.Builder()
                        .setNetworkQuality(NETWORK_QUALITY_OK)
                        .build());

        DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
                new VcnCellUnderlyingNetworkTemplate.Builder()
                        .setNetworkQuality(NETWORK_QUALITY_OK)
                        .build());
    }

+110 −53
Original line number Diff line number Diff line
@@ -48,23 +48,6 @@ public abstract class VcnUnderlyingNetworkTemplate {
    /** @hide */
    static final int NETWORK_PRIORITY_TYPE_CELL = 2;

    /** Denotes that any network quality is acceptable. @hide */
    public static final int NETWORK_QUALITY_ANY = 0;
    /** Denotes that network quality needs to be OK. @hide */
    public static final int NETWORK_QUALITY_OK = 100000;

    private static final SparseArray<String> NETWORK_QUALITY_TO_STRING_MAP = new SparseArray<>();

    static {
        NETWORK_QUALITY_TO_STRING_MAP.put(NETWORK_QUALITY_ANY, "NETWORK_QUALITY_ANY");
        NETWORK_QUALITY_TO_STRING_MAP.put(NETWORK_QUALITY_OK, "NETWORK_QUALITY_OK");
    }

    /** @hide */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({NETWORK_QUALITY_OK, NETWORK_QUALITY_ANY})
    public @interface NetworkQuality {}

    /**
     * Used to configure the matching criteria of a network characteristic. This may include network
     * capabilities, or cellular subscription information. Denotes that networks with or without the
@@ -103,44 +86,73 @@ public abstract class VcnUnderlyingNetworkTemplate {
    private final int mNetworkPriorityType;

    /** @hide */
    static final String NETWORK_QUALITY_KEY = "mNetworkQuality";
    static final String METERED_MATCH_KEY = "mMeteredMatchCriteria";

    private final int mNetworkQuality;
    private final int mMeteredMatchCriteria;

    /** @hide */
    static final String METERED_MATCH_KEY = "mMeteredMatchCriteria";
    public static final int DEFAULT_MIN_BANDWIDTH_KBPS = 0;

    private final int mMeteredMatchCriteria;
    /** @hide */
    static final String MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS_KEY = "mMinEntryUpstreamBandwidthKbps";

    private final int mMinEntryUpstreamBandwidthKbps;

    /** @hide */
    static final String MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS_KEY = "mMinExitUpstreamBandwidthKbps";

    private final int mMinExitUpstreamBandwidthKbps;

    /** @hide */
    static final String MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS_KEY =
            "mMinEntryDownstreamBandwidthKbps";

    private final int mMinEntryDownstreamBandwidthKbps;

    /** @hide */
    static final String MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS_KEY = "mMinExitDownstreamBandwidthKbps";

    private final int mMinExitDownstreamBandwidthKbps;

    /** @hide */
    VcnUnderlyingNetworkTemplate(
            int networkPriorityType, int networkQuality, int meteredMatchCriteria) {
            int networkPriorityType,
            int meteredMatchCriteria,
            int minEntryUpstreamBandwidthKbps,
            int minExitUpstreamBandwidthKbps,
            int minEntryDownstreamBandwidthKbps,
            int minExitDownstreamBandwidthKbps) {
        mNetworkPriorityType = networkPriorityType;
        mNetworkQuality = networkQuality;
        mMeteredMatchCriteria = meteredMatchCriteria;
        mMinEntryUpstreamBandwidthKbps = minEntryUpstreamBandwidthKbps;
        mMinExitUpstreamBandwidthKbps = minExitUpstreamBandwidthKbps;
        mMinEntryDownstreamBandwidthKbps = minEntryDownstreamBandwidthKbps;
        mMinExitDownstreamBandwidthKbps = minExitDownstreamBandwidthKbps;
    }

    /** @hide */
    static void validateNetworkQuality(int networkQuality) {
    static void validateMatchCriteria(int matchCriteria, String matchingCapability) {
        Preconditions.checkArgument(
                networkQuality == NETWORK_QUALITY_ANY || networkQuality == NETWORK_QUALITY_OK,
                "Invalid networkQuality:" + networkQuality);
                MATCH_CRITERIA_TO_STRING_MAP.contains(matchCriteria),
                "Invalid matching criteria: " + matchCriteria + " for " + matchingCapability);
    }

    /** @hide */
    static void validateMatchCriteria(int meteredMatchCriteria, String matchingCapability) {
    static void validateMinBandwidthKbps(int minEntryBandwidth, int minExitBandwidth) {
        Preconditions.checkArgument(
                minEntryBandwidth >= 0, "Invalid minEntryBandwidth, must be >= 0");
        Preconditions.checkArgument(
                MATCH_CRITERIA_TO_STRING_MAP.contains(meteredMatchCriteria),
                "Invalid matching criteria: "
                        + meteredMatchCriteria
                        + " for "
                        + matchingCapability);
                minExitBandwidth >= 0, "Invalid minExitBandwidth, must be >= 0");
        Preconditions.checkArgument(
                minEntryBandwidth >= minExitBandwidth,
                "Minimum entry bandwidth must be >= exit bandwidth");
    }

    /** @hide */
    protected void validate() {
        validateNetworkQuality(mNetworkQuality);
        validateMatchCriteria(mMeteredMatchCriteria, "mMeteredMatchCriteria");
        validateMinBandwidthKbps(mMinEntryUpstreamBandwidthKbps, mMinExitUpstreamBandwidthKbps);
        validateMinBandwidthKbps(mMinEntryDownstreamBandwidthKbps, mMinExitDownstreamBandwidthKbps);
    }

    /** @hide */
@@ -168,15 +180,24 @@ public abstract class VcnUnderlyingNetworkTemplate {
        final PersistableBundle result = new PersistableBundle();

        result.putInt(NETWORK_PRIORITY_TYPE_KEY, mNetworkPriorityType);
        result.putInt(NETWORK_QUALITY_KEY, mNetworkQuality);
        result.putInt(METERED_MATCH_KEY, mMeteredMatchCriteria);
        result.putInt(MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS_KEY, mMinEntryUpstreamBandwidthKbps);
        result.putInt(MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS_KEY, mMinExitUpstreamBandwidthKbps);
        result.putInt(MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS_KEY, mMinEntryDownstreamBandwidthKbps);
        result.putInt(MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS_KEY, mMinExitDownstreamBandwidthKbps);

        return result;
    }

    @Override
    public int hashCode() {
        return Objects.hash(mNetworkPriorityType, mNetworkQuality, mMeteredMatchCriteria);
        return Objects.hash(
                mNetworkPriorityType,
                mMeteredMatchCriteria,
                mMinEntryUpstreamBandwidthKbps,
                mMinExitUpstreamBandwidthKbps,
                mMinEntryDownstreamBandwidthKbps,
                mMinExitDownstreamBandwidthKbps);
    }

    @Override
@@ -187,8 +208,11 @@ public abstract class VcnUnderlyingNetworkTemplate {

        final VcnUnderlyingNetworkTemplate rhs = (VcnUnderlyingNetworkTemplate) other;
        return mNetworkPriorityType == rhs.mNetworkPriorityType
                && mNetworkQuality == rhs.mNetworkQuality
                && mMeteredMatchCriteria == rhs.mMeteredMatchCriteria;
                && mMeteredMatchCriteria == rhs.mMeteredMatchCriteria
                && mMinEntryUpstreamBandwidthKbps == rhs.mMinEntryUpstreamBandwidthKbps
                && mMinExitUpstreamBandwidthKbps == rhs.mMinExitUpstreamBandwidthKbps
                && mMinEntryDownstreamBandwidthKbps == rhs.mMinEntryDownstreamBandwidthKbps
                && mMinExitDownstreamBandwidthKbps == rhs.mMinExitDownstreamBandwidthKbps;
    }

    /** @hide */
@@ -197,8 +221,8 @@ public abstract class VcnUnderlyingNetworkTemplate {
    }

    /** @hide */
    static String getMatchCriteriaString(int meteredMatchCriteria) {
        return getNameString(MATCH_CRITERIA_TO_STRING_MAP, meteredMatchCriteria);
    static String getMatchCriteriaString(int matchCriteria) {
        return getNameString(MATCH_CRITERIA_TO_STRING_MAP, matchCriteria);
    }

    /** @hide */
@@ -213,34 +237,67 @@ public abstract class VcnUnderlyingNetworkTemplate {
        pw.println(this.getClass().getSimpleName() + ":");
        pw.increaseIndent();

        pw.println(
                "mNetworkQuality: "
                        + getNameString(NETWORK_QUALITY_TO_STRING_MAP, mNetworkQuality));
        pw.println("mMeteredMatchCriteria: " + getMatchCriteriaString(mMeteredMatchCriteria));
        pw.println("mMinEntryUpstreamBandwidthKbps: " + mMinEntryUpstreamBandwidthKbps);
        pw.println("mMinExitUpstreamBandwidthKbps: " + mMinExitUpstreamBandwidthKbps);
        pw.println("mMinEntryDownstreamBandwidthKbps: " + mMinEntryDownstreamBandwidthKbps);
        pw.println("mMinExitDownstreamBandwidthKbps: " + mMinExitDownstreamBandwidthKbps);
        dumpTransportSpecificFields(pw);

        pw.decreaseIndent();
    }

    /**
     * Retrieve the required network quality to match this template.
     * Return the matching criteria for metered networks.
     *
     * @see Builder#setNetworkQuality(int)
     * @see VcnWifiUnderlyingNetworkTemplate.Builder#setMetered(int)
     * @see VcnCellUnderlyingNetworkTemplate.Builder#setMetered(int)
     */
    public int getMetered() {
        return mMeteredMatchCriteria;
    }

    /**
     * Returns the minimum entry upstream bandwidth allowed by this template.
     *
     * @see VcnWifiUnderlyingNetworkTemplate.Builder#setMinUpstreamBandwidthKbps(int, int)
     * @see VcnCellUnderlyingNetworkTemplate.Builder#setMinUpstreamBandwidthKbps(int, int)
     * @hide
     */
    @NetworkQuality
    public int getNetworkQuality() {
        return mNetworkQuality;
    public int getMinEntryUpstreamBandwidthKbps() {
        return mMinEntryUpstreamBandwidthKbps;
    }

    /**
     * Return the matching criteria for metered networks.
     * Returns the minimum exit upstream bandwidth allowed by this template.
     *
     * @see VcnWifiUnderlyingNetworkTemplate.Builder#setMetered(int)
     * @see VcnCellUnderlyingNetworkTemplate.Builder#setMetered(int)
     * @see VcnWifiUnderlyingNetworkTemplate.Builder#setMinUpstreamBandwidthKbps(int, int)
     * @see VcnCellUnderlyingNetworkTemplate.Builder#setMinUpstreamBandwidthKbps(int, int)
     * @hide
     */
    @MatchCriteria
    public int getMetered() {
        return mMeteredMatchCriteria;
    public int getMinExitUpstreamBandwidthKbps() {
        return mMinExitUpstreamBandwidthKbps;
    }

    /**
     * Returns the minimum entry downstream bandwidth allowed by this template.
     *
     * @see VcnWifiUnderlyingNetworkTemplate.Builder#setMinDownstreamBandwidthKbps(int, int)
     * @see VcnCellUnderlyingNetworkTemplate.Builder#setMinDownstreamBandwidthKbps(int, int)
     * @hide
     */
    public int getMinEntryDownstreamBandwidthKbps() {
        return mMinEntryDownstreamBandwidthKbps;
    }

    /**
     * Returns the minimum exit downstream bandwidth allowed by this template.
     *
     * @see VcnWifiUnderlyingNetworkTemplate.Builder#setMinDownstreamBandwidthKbps(int, int)
     * @see VcnCellUnderlyingNetworkTemplate.Builder#setMinDownstreamBandwidthKbps(int, int)
     * @hide
     */
    public int getMinExitDownstreamBandwidthKbps() {
        return mMinExitDownstreamBandwidthKbps;
    }
}
+131 −25

File changed.

Preview size limit exceeded, changes collapsed.

+26 −10
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ import static android.net.NetworkCapabilities.TRANSPORT_TEST;
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_ANY;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK;

import static com.android.server.VcnManagementService.LOCAL_LOG;

@@ -47,6 +45,7 @@ import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscription
import com.android.server.vcn.VcnContext;

import java.util.List;
import java.util.Objects;
import java.util.Set;

/** @hide */
@@ -121,9 +120,10 @@ class NetworkPriorityClassifier {
            TelephonySubscriptionSnapshot snapshot,
            UnderlyingNetworkRecord currentlySelected,
            PersistableBundle carrierConfig) {
        // TODO: Check Network Quality reported by metric monitors/probers.

        final NetworkCapabilities caps = networkRecord.networkCapabilities;
        final boolean isSelectedUnderlyingNetwork =
                currentlySelected != null
                        && Objects.equals(currentlySelected.network, networkRecord.network);

        final int meteredMatch = networkPriority.getMetered();
        final boolean isMetered = !caps.hasCapability(NET_CAPABILITY_NOT_METERED);
@@ -132,6 +132,23 @@ class NetworkPriorityClassifier {
            return false;
        }

        // Fails bandwidth requirements if either (a) less than exit threshold, or (b), not
        // selected, but less than entry threshold
        if (caps.getLinkUpstreamBandwidthKbps() < networkPriority.getMinExitUpstreamBandwidthKbps()
                || (caps.getLinkUpstreamBandwidthKbps()
                                < networkPriority.getMinEntryUpstreamBandwidthKbps()
                        && !isSelectedUnderlyingNetwork)) {
            return false;
        }

        if (caps.getLinkDownstreamBandwidthKbps()
                        < networkPriority.getMinExitDownstreamBandwidthKbps()
                || (caps.getLinkDownstreamBandwidthKbps()
                                < networkPriority.getMinEntryDownstreamBandwidthKbps()
                        && !isSelectedUnderlyingNetwork)) {
            return false;
        }

        if (vcnContext.isInTestMode() && caps.hasTransport(TRANSPORT_TEST)) {
            return true;
        }
@@ -172,8 +189,7 @@ class NetworkPriorityClassifier {
        }

        // TODO: Move the Network Quality check to the network metric monitor framework.
        if (networkPriority.getNetworkQuality()
                > getWifiQuality(networkRecord, currentlySelected, carrierConfig)) {
        if (!isWifiRssiAcceptable(networkRecord, currentlySelected, carrierConfig)) {
            return false;
        }

@@ -185,7 +201,7 @@ class NetworkPriorityClassifier {
        return true;
    }

    private static int getWifiQuality(
    private static boolean isWifiRssiAcceptable(
            UnderlyingNetworkRecord networkRecord,
            UnderlyingNetworkRecord currentlySelected,
            PersistableBundle carrierConfig) {
@@ -196,14 +212,14 @@ class NetworkPriorityClassifier {

        if (isSelectedNetwork
                && caps.getSignalStrength() >= getWifiExitRssiThreshold(carrierConfig)) {
            return NETWORK_QUALITY_OK;
            return true;
        }

        if (caps.getSignalStrength() >= getWifiEntryRssiThreshold(carrierConfig)) {
            return NETWORK_QUALITY_OK;
            return true;
        }

        return NETWORK_QUALITY_ANY;
        return false;
    }

    @VisibleForTesting(visibility = Visibility.PRIVATE)
Loading