Merge changes I61c84693,I929428f7
* changes: Expose entry/exit bandwidth criteria APIs for VCN templates Add minimum required bandwidth to network templates
This commit is contained in:
@@ -27290,6 +27290,8 @@ package android.net.vcn {
|
|||||||
ctor public VcnCellUnderlyingNetworkTemplate.Builder();
|
ctor public VcnCellUnderlyingNetworkTemplate.Builder();
|
||||||
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate build();
|
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate build();
|
||||||
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMetered(int);
|
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMetered(int);
|
||||||
|
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMinDownstreamBandwidthKbps(int, int);
|
||||||
|
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMinUpstreamBandwidthKbps(int, int);
|
||||||
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setOperatorPlmnIds(@NonNull java.util.Set<java.lang.String>);
|
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setOperatorPlmnIds(@NonNull java.util.Set<java.lang.String>);
|
||||||
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setOpportunistic(int);
|
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setOpportunistic(int);
|
||||||
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setRoaming(int);
|
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setRoaming(int);
|
||||||
@@ -27350,6 +27352,10 @@ package android.net.vcn {
|
|||||||
|
|
||||||
public abstract class VcnUnderlyingNetworkTemplate {
|
public abstract class VcnUnderlyingNetworkTemplate {
|
||||||
method public int getMetered();
|
method public int getMetered();
|
||||||
|
method public int getMinEntryDownstreamBandwidthKbps();
|
||||||
|
method public int getMinEntryUpstreamBandwidthKbps();
|
||||||
|
method public int getMinExitDownstreamBandwidthKbps();
|
||||||
|
method public int getMinExitUpstreamBandwidthKbps();
|
||||||
field public static final int MATCH_ANY = 0; // 0x0
|
field public static final int MATCH_ANY = 0; // 0x0
|
||||||
field public static final int MATCH_FORBIDDEN = 2; // 0x2
|
field public static final int MATCH_FORBIDDEN = 2; // 0x2
|
||||||
field public static final int MATCH_REQUIRED = 1; // 0x1
|
field public static final int MATCH_REQUIRED = 1; // 0x1
|
||||||
@@ -27363,6 +27369,8 @@ package android.net.vcn {
|
|||||||
ctor public VcnWifiUnderlyingNetworkTemplate.Builder();
|
ctor public VcnWifiUnderlyingNetworkTemplate.Builder();
|
||||||
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate build();
|
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate build();
|
||||||
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setMetered(int);
|
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setMetered(int);
|
||||||
|
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setMinDownstreamBandwidthKbps(int, int);
|
||||||
|
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setMinUpstreamBandwidthKbps(int, int);
|
||||||
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setSsids(@NonNull java.util.Set<java.lang.String>);
|
method @NonNull public android.net.vcn.VcnWifiUnderlyingNetworkTemplate.Builder setSsids(@NonNull java.util.Set<java.lang.String>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,13 +63,22 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
private final int mOpportunisticMatchCriteria;
|
private final int mOpportunisticMatchCriteria;
|
||||||
|
|
||||||
private VcnCellUnderlyingNetworkTemplate(
|
private VcnCellUnderlyingNetworkTemplate(
|
||||||
int networkQuality,
|
|
||||||
int meteredMatchCriteria,
|
int meteredMatchCriteria,
|
||||||
|
int minEntryUpstreamBandwidthKbps,
|
||||||
|
int minExitUpstreamBandwidthKbps,
|
||||||
|
int minEntryDownstreamBandwidthKbps,
|
||||||
|
int minExitDownstreamBandwidthKbps,
|
||||||
Set<String> allowedNetworkPlmnIds,
|
Set<String> allowedNetworkPlmnIds,
|
||||||
Set<Integer> allowedSpecificCarrierIds,
|
Set<Integer> allowedSpecificCarrierIds,
|
||||||
int roamingMatchCriteria,
|
int roamingMatchCriteria,
|
||||||
int opportunisticMatchCriteria) {
|
int opportunisticMatchCriteria) {
|
||||||
super(NETWORK_PRIORITY_TYPE_CELL, networkQuality, meteredMatchCriteria);
|
super(
|
||||||
|
NETWORK_PRIORITY_TYPE_CELL,
|
||||||
|
meteredMatchCriteria,
|
||||||
|
minEntryUpstreamBandwidthKbps,
|
||||||
|
minExitUpstreamBandwidthKbps,
|
||||||
|
minEntryDownstreamBandwidthKbps,
|
||||||
|
minExitDownstreamBandwidthKbps);
|
||||||
mAllowedNetworkPlmnIds = new ArraySet<>(allowedNetworkPlmnIds);
|
mAllowedNetworkPlmnIds = new ArraySet<>(allowedNetworkPlmnIds);
|
||||||
mAllowedSpecificCarrierIds = new ArraySet<>(allowedSpecificCarrierIds);
|
mAllowedSpecificCarrierIds = new ArraySet<>(allowedSpecificCarrierIds);
|
||||||
mRoamingMatchCriteria = roamingMatchCriteria;
|
mRoamingMatchCriteria = roamingMatchCriteria;
|
||||||
@@ -109,9 +118,17 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
@NonNull PersistableBundle in) {
|
@NonNull PersistableBundle in) {
|
||||||
Objects.requireNonNull(in, "PersistableBundle is null");
|
Objects.requireNonNull(in, "PersistableBundle is null");
|
||||||
|
|
||||||
final int networkQuality = in.getInt(NETWORK_QUALITY_KEY);
|
|
||||||
final int meteredMatchCriteria = in.getInt(METERED_MATCH_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 =
|
final PersistableBundle plmnIdsBundle =
|
||||||
in.getPersistableBundle(ALLOWED_NETWORK_PLMN_IDS_KEY);
|
in.getPersistableBundle(ALLOWED_NETWORK_PLMN_IDS_KEY);
|
||||||
Objects.requireNonNull(plmnIdsBundle, "plmnIdsBundle is null");
|
Objects.requireNonNull(plmnIdsBundle, "plmnIdsBundle is null");
|
||||||
@@ -131,8 +148,11 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
final int opportunisticMatchCriteria = in.getInt(OPPORTUNISTIC_MATCH_KEY);
|
final int opportunisticMatchCriteria = in.getInt(OPPORTUNISTIC_MATCH_KEY);
|
||||||
|
|
||||||
return new VcnCellUnderlyingNetworkTemplate(
|
return new VcnCellUnderlyingNetworkTemplate(
|
||||||
networkQuality,
|
|
||||||
meteredMatchCriteria,
|
meteredMatchCriteria,
|
||||||
|
minEntryUpstreamBandwidthKbps,
|
||||||
|
minExitUpstreamBandwidthKbps,
|
||||||
|
minEntryDownstreamBandwidthKbps,
|
||||||
|
minExitDownstreamBandwidthKbps,
|
||||||
allowedNetworkPlmnIds,
|
allowedNetworkPlmnIds,
|
||||||
allowedSpecificCarrierIds,
|
allowedSpecificCarrierIds,
|
||||||
roamingMatchCriteria,
|
roamingMatchCriteria,
|
||||||
@@ -243,7 +263,6 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
|
|
||||||
/** This class is used to incrementally build VcnCellUnderlyingNetworkTemplate objects. */
|
/** This class is used to incrementally build VcnCellUnderlyingNetworkTemplate objects. */
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private int mNetworkQuality = NETWORK_QUALITY_ANY;
|
|
||||||
private int mMeteredMatchCriteria = MATCH_ANY;
|
private int mMeteredMatchCriteria = MATCH_ANY;
|
||||||
|
|
||||||
@NonNull private final Set<String> mAllowedNetworkPlmnIds = new ArraySet<>();
|
@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 mRoamingMatchCriteria = MATCH_ANY;
|
||||||
private int mOpportunisticMatchCriteria = 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. */
|
/** Construct a Builder object. */
|
||||||
public Builder() {}
|
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.
|
* Set the matching criteria for metered networks.
|
||||||
*
|
*
|
||||||
@@ -369,12 +374,92 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the minimum upstream bandwidths that this template will match.
|
||||||
|
*
|
||||||
|
* <p>This template will not match a network that does not provide at least the bandwidth
|
||||||
|
* passed as the entry bandwidth, except in the case that the network is selected as the VCN
|
||||||
|
* Gateway Connection's underlying network, where it will continue to match until the
|
||||||
|
* bandwidth drops under the exit bandwidth.
|
||||||
|
*
|
||||||
|
* <p>The entry criteria MUST be greater than, or equal to the exit criteria to avoid the
|
||||||
|
* invalid case where a network fulfills the entry criteria, but at the same time fails 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 networks
|
||||||
|
* that ARE NOT the already-selected underlying network, or {@code 0} to disable this
|
||||||
|
* requirement. Disabled by default.
|
||||||
|
* @param minExitUpstreamBandwidthKbps the minimum accepted upstream bandwidth for a network
|
||||||
|
* that IS the already-selected underlying network, or {@code 0} to disable this
|
||||||
|
* requirement. Disabled by default.
|
||||||
|
* @return this {@link Builder} instance, for chaining
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
// The getter for the two integers are separated, and in the superclass. Please see {@link
|
||||||
|
// VcnUnderlyingNetworkTemplate#getMinEntryUpstreamBandwidthKbps()} and {@link
|
||||||
|
// VcnUnderlyingNetworkTemplate#getMinExitUpstreamBandwidthKbps()}
|
||||||
|
@SuppressLint("MissingGetterMatchingBuilder")
|
||||||
|
public Builder setMinUpstreamBandwidthKbps(
|
||||||
|
int minEntryUpstreamBandwidthKbps, int minExitUpstreamBandwidthKbps) {
|
||||||
|
validateMinBandwidthKbps(minEntryUpstreamBandwidthKbps, minExitUpstreamBandwidthKbps);
|
||||||
|
|
||||||
|
mMinEntryUpstreamBandwidthKbps = minEntryUpstreamBandwidthKbps;
|
||||||
|
mMinExitUpstreamBandwidthKbps = minExitUpstreamBandwidthKbps;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the minimum upstream bandwidths that this template will match.
|
||||||
|
*
|
||||||
|
* <p>This template will not match a network that does not provide at least the bandwidth
|
||||||
|
* passed as the entry bandwidth, except in the case that the network is selected as the VCN
|
||||||
|
* Gateway Connection's underlying network, where it will continue to match until the
|
||||||
|
* bandwidth drops under the exit bandwidth.
|
||||||
|
*
|
||||||
|
* <p>The entry criteria MUST be greater than, or equal to the exit criteria to avoid the
|
||||||
|
* invalid case where a network fulfills the entry criteria, but at the same time fails 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
|
||||||
|
* networks that ARE NOT the already-selected underlying network, or {@code 0} to
|
||||||
|
* disable this requirement. Disabled by default.
|
||||||
|
* @param minExitDownstreamBandwidthKbps the minimum accepted downstream bandwidth for a
|
||||||
|
* network that IS the already-selected underlying network, or {@code 0} to disable this
|
||||||
|
* requirement. Disabled by default.
|
||||||
|
* @return this {@link Builder} instance, for chaining
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
// The getter for the two integers are separated, and in the superclass. Please see {@link
|
||||||
|
// VcnUnderlyingNetworkTemplate#getMinEntryDownstreamBandwidthKbps()} and {@link
|
||||||
|
// VcnUnderlyingNetworkTemplate#getMinExitDownstreamBandwidthKbps()}
|
||||||
|
@SuppressLint("MissingGetterMatchingBuilder")
|
||||||
|
public Builder setMinDownstreamBandwidthKbps(
|
||||||
|
int minEntryDownstreamBandwidthKbps, int minExitDownstreamBandwidthKbps) {
|
||||||
|
validateMinBandwidthKbps(
|
||||||
|
minEntryDownstreamBandwidthKbps, minExitDownstreamBandwidthKbps);
|
||||||
|
|
||||||
|
mMinEntryDownstreamBandwidthKbps = minEntryDownstreamBandwidthKbps;
|
||||||
|
mMinExitDownstreamBandwidthKbps = minExitDownstreamBandwidthKbps;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** Build the VcnCellUnderlyingNetworkTemplate. */
|
/** Build the VcnCellUnderlyingNetworkTemplate. */
|
||||||
@NonNull
|
@NonNull
|
||||||
public VcnCellUnderlyingNetworkTemplate build() {
|
public VcnCellUnderlyingNetworkTemplate build() {
|
||||||
return new VcnCellUnderlyingNetworkTemplate(
|
return new VcnCellUnderlyingNetworkTemplate(
|
||||||
mNetworkQuality,
|
|
||||||
mMeteredMatchCriteria,
|
mMeteredMatchCriteria,
|
||||||
|
mMinEntryUpstreamBandwidthKbps,
|
||||||
|
mMinExitUpstreamBandwidthKbps,
|
||||||
|
mMinEntryDownstreamBandwidthKbps,
|
||||||
|
mMinExitDownstreamBandwidthKbps,
|
||||||
mAllowedNetworkPlmnIds,
|
mAllowedNetworkPlmnIds,
|
||||||
mAllowedSpecificCarrierIds,
|
mAllowedSpecificCarrierIds,
|
||||||
mRoamingMatchCriteria,
|
mRoamingMatchCriteria,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ package android.net.vcn;
|
|||||||
|
|
||||||
import static android.net.ipsec.ike.IkeSessionParams.IKE_OPTION_MOBIKE;
|
import static android.net.ipsec.ike.IkeSessionParams.IKE_OPTION_MOBIKE;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
|
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;
|
import static com.android.internal.annotations.VisibleForTesting.Visibility;
|
||||||
|
|
||||||
@@ -169,18 +168,15 @@ public final class VcnGatewayConnectionConfig {
|
|||||||
static {
|
static {
|
||||||
DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
|
DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
|
||||||
new VcnCellUnderlyingNetworkTemplate.Builder()
|
new VcnCellUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(NETWORK_QUALITY_OK)
|
|
||||||
.setOpportunistic(MATCH_REQUIRED)
|
.setOpportunistic(MATCH_REQUIRED)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
|
DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
|
||||||
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(NETWORK_QUALITY_OK)
|
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
|
DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
|
||||||
new VcnCellUnderlyingNetworkTemplate.Builder()
|
new VcnCellUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(NETWORK_QUALITY_OK)
|
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,23 +48,6 @@ public abstract class VcnUnderlyingNetworkTemplate {
|
|||||||
/** @hide */
|
/** @hide */
|
||||||
static final int NETWORK_PRIORITY_TYPE_CELL = 2;
|
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
|
* 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
|
* capabilities, or cellular subscription information. Denotes that networks with or without the
|
||||||
@@ -102,45 +85,74 @@ public abstract class VcnUnderlyingNetworkTemplate {
|
|||||||
private static final String NETWORK_PRIORITY_TYPE_KEY = "mNetworkPriorityType";
|
private static final String NETWORK_PRIORITY_TYPE_KEY = "mNetworkPriorityType";
|
||||||
private final int mNetworkPriorityType;
|
private final int mNetworkPriorityType;
|
||||||
|
|
||||||
/** @hide */
|
|
||||||
static final String NETWORK_QUALITY_KEY = "mNetworkQuality";
|
|
||||||
|
|
||||||
private final int mNetworkQuality;
|
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
static final String METERED_MATCH_KEY = "mMeteredMatchCriteria";
|
static final String METERED_MATCH_KEY = "mMeteredMatchCriteria";
|
||||||
|
|
||||||
private final int mMeteredMatchCriteria;
|
private final int mMeteredMatchCriteria;
|
||||||
|
|
||||||
|
/** @hide */
|
||||||
|
public static final int DEFAULT_MIN_BANDWIDTH_KBPS = 0;
|
||||||
|
|
||||||
|
/** @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 */
|
/** @hide */
|
||||||
VcnUnderlyingNetworkTemplate(
|
VcnUnderlyingNetworkTemplate(
|
||||||
int networkPriorityType, int networkQuality, int meteredMatchCriteria) {
|
int networkPriorityType,
|
||||||
|
int meteredMatchCriteria,
|
||||||
|
int minEntryUpstreamBandwidthKbps,
|
||||||
|
int minExitUpstreamBandwidthKbps,
|
||||||
|
int minEntryDownstreamBandwidthKbps,
|
||||||
|
int minExitDownstreamBandwidthKbps) {
|
||||||
mNetworkPriorityType = networkPriorityType;
|
mNetworkPriorityType = networkPriorityType;
|
||||||
mNetworkQuality = networkQuality;
|
|
||||||
mMeteredMatchCriteria = meteredMatchCriteria;
|
mMeteredMatchCriteria = meteredMatchCriteria;
|
||||||
|
mMinEntryUpstreamBandwidthKbps = minEntryUpstreamBandwidthKbps;
|
||||||
|
mMinExitUpstreamBandwidthKbps = minExitUpstreamBandwidthKbps;
|
||||||
|
mMinEntryDownstreamBandwidthKbps = minEntryDownstreamBandwidthKbps;
|
||||||
|
mMinExitDownstreamBandwidthKbps = minExitDownstreamBandwidthKbps;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
static void validateNetworkQuality(int networkQuality) {
|
static void validateMatchCriteria(int matchCriteria, String matchingCapability) {
|
||||||
Preconditions.checkArgument(
|
Preconditions.checkArgument(
|
||||||
networkQuality == NETWORK_QUALITY_ANY || networkQuality == NETWORK_QUALITY_OK,
|
MATCH_CRITERIA_TO_STRING_MAP.contains(matchCriteria),
|
||||||
"Invalid networkQuality:" + networkQuality);
|
"Invalid matching criteria: " + matchCriteria + " for " + matchingCapability);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
static void validateMatchCriteria(int meteredMatchCriteria, String matchingCapability) {
|
static void validateMinBandwidthKbps(int minEntryBandwidth, int minExitBandwidth) {
|
||||||
Preconditions.checkArgument(
|
Preconditions.checkArgument(
|
||||||
MATCH_CRITERIA_TO_STRING_MAP.contains(meteredMatchCriteria),
|
minEntryBandwidth >= 0, "Invalid minEntryBandwidth, must be >= 0");
|
||||||
"Invalid matching criteria: "
|
Preconditions.checkArgument(
|
||||||
+ meteredMatchCriteria
|
minExitBandwidth >= 0, "Invalid minExitBandwidth, must be >= 0");
|
||||||
+ " for "
|
Preconditions.checkArgument(
|
||||||
+ matchingCapability);
|
minEntryBandwidth >= minExitBandwidth,
|
||||||
|
"Minimum entry bandwidth must be >= exit bandwidth");
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
protected void validate() {
|
protected void validate() {
|
||||||
validateNetworkQuality(mNetworkQuality);
|
|
||||||
validateMatchCriteria(mMeteredMatchCriteria, "mMeteredMatchCriteria");
|
validateMatchCriteria(mMeteredMatchCriteria, "mMeteredMatchCriteria");
|
||||||
|
validateMinBandwidthKbps(mMinEntryUpstreamBandwidthKbps, mMinExitUpstreamBandwidthKbps);
|
||||||
|
validateMinBandwidthKbps(mMinEntryDownstreamBandwidthKbps, mMinExitDownstreamBandwidthKbps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -168,15 +180,24 @@ public abstract class VcnUnderlyingNetworkTemplate {
|
|||||||
final PersistableBundle result = new PersistableBundle();
|
final PersistableBundle result = new PersistableBundle();
|
||||||
|
|
||||||
result.putInt(NETWORK_PRIORITY_TYPE_KEY, mNetworkPriorityType);
|
result.putInt(NETWORK_PRIORITY_TYPE_KEY, mNetworkPriorityType);
|
||||||
result.putInt(NETWORK_QUALITY_KEY, mNetworkQuality);
|
|
||||||
result.putInt(METERED_MATCH_KEY, mMeteredMatchCriteria);
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(mNetworkPriorityType, mNetworkQuality, mMeteredMatchCriteria);
|
return Objects.hash(
|
||||||
|
mNetworkPriorityType,
|
||||||
|
mMeteredMatchCriteria,
|
||||||
|
mMinEntryUpstreamBandwidthKbps,
|
||||||
|
mMinExitUpstreamBandwidthKbps,
|
||||||
|
mMinEntryDownstreamBandwidthKbps,
|
||||||
|
mMinExitDownstreamBandwidthKbps);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -187,8 +208,11 @@ public abstract class VcnUnderlyingNetworkTemplate {
|
|||||||
|
|
||||||
final VcnUnderlyingNetworkTemplate rhs = (VcnUnderlyingNetworkTemplate) other;
|
final VcnUnderlyingNetworkTemplate rhs = (VcnUnderlyingNetworkTemplate) other;
|
||||||
return mNetworkPriorityType == rhs.mNetworkPriorityType
|
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 */
|
/** @hide */
|
||||||
@@ -197,8 +221,8 @@ public abstract class VcnUnderlyingNetworkTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
static String getMatchCriteriaString(int meteredMatchCriteria) {
|
static String getMatchCriteriaString(int matchCriteria) {
|
||||||
return getNameString(MATCH_CRITERIA_TO_STRING_MAP, meteredMatchCriteria);
|
return getNameString(MATCH_CRITERIA_TO_STRING_MAP, matchCriteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -213,34 +237,63 @@ public abstract class VcnUnderlyingNetworkTemplate {
|
|||||||
pw.println(this.getClass().getSimpleName() + ":");
|
pw.println(this.getClass().getSimpleName() + ":");
|
||||||
pw.increaseIndent();
|
pw.increaseIndent();
|
||||||
|
|
||||||
pw.println(
|
|
||||||
"mNetworkQuality: "
|
|
||||||
+ getNameString(NETWORK_QUALITY_TO_STRING_MAP, mNetworkQuality));
|
|
||||||
pw.println("mMeteredMatchCriteria: " + getMatchCriteriaString(mMeteredMatchCriteria));
|
pw.println("mMeteredMatchCriteria: " + getMatchCriteriaString(mMeteredMatchCriteria));
|
||||||
|
pw.println("mMinEntryUpstreamBandwidthKbps: " + mMinEntryUpstreamBandwidthKbps);
|
||||||
|
pw.println("mMinExitUpstreamBandwidthKbps: " + mMinExitUpstreamBandwidthKbps);
|
||||||
|
pw.println("mMinEntryDownstreamBandwidthKbps: " + mMinEntryDownstreamBandwidthKbps);
|
||||||
|
pw.println("mMinExitDownstreamBandwidthKbps: " + mMinExitDownstreamBandwidthKbps);
|
||||||
dumpTransportSpecificFields(pw);
|
dumpTransportSpecificFields(pw);
|
||||||
|
|
||||||
pw.decreaseIndent();
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve the required network quality to match this template.
|
|
||||||
*
|
|
||||||
* @see Builder#setNetworkQuality(int)
|
|
||||||
* @hide
|
|
||||||
*/
|
|
||||||
@NetworkQuality
|
|
||||||
public int getNetworkQuality() {
|
|
||||||
return mNetworkQuality;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the matching criteria for metered networks.
|
* Return the matching criteria for metered networks.
|
||||||
*
|
*
|
||||||
* @see VcnWifiUnderlyingNetworkTemplate.Builder#setMetered(int)
|
* @see VcnWifiUnderlyingNetworkTemplate.Builder#setMetered(int)
|
||||||
* @see VcnCellUnderlyingNetworkTemplate.Builder#setMetered(int)
|
* @see VcnCellUnderlyingNetworkTemplate.Builder#setMetered(int)
|
||||||
*/
|
*/
|
||||||
@MatchCriteria
|
|
||||||
public int getMetered() {
|
public int getMetered() {
|
||||||
return mMeteredMatchCriteria;
|
return mMeteredMatchCriteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the minimum entry upstream bandwidth allowed by this template.
|
||||||
|
*
|
||||||
|
* @see VcnWifiUnderlyingNetworkTemplate.Builder#setMinUpstreamBandwidthKbps(int, int)
|
||||||
|
* @see VcnCellUnderlyingNetworkTemplate.Builder#setMinUpstreamBandwidthKbps(int, int)
|
||||||
|
*/
|
||||||
|
public int getMinEntryUpstreamBandwidthKbps() {
|
||||||
|
return mMinEntryUpstreamBandwidthKbps;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the minimum exit upstream bandwidth allowed by this template.
|
||||||
|
*
|
||||||
|
* @see VcnWifiUnderlyingNetworkTemplate.Builder#setMinUpstreamBandwidthKbps(int, int)
|
||||||
|
* @see VcnCellUnderlyingNetworkTemplate.Builder#setMinUpstreamBandwidthKbps(int, int)
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
*/
|
||||||
|
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)
|
||||||
|
*/
|
||||||
|
public int getMinExitDownstreamBandwidthKbps() {
|
||||||
|
return mMinExitDownstreamBandwidthKbps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,19 @@ public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
@Nullable private final Set<String> mSsids;
|
@Nullable private final Set<String> mSsids;
|
||||||
|
|
||||||
private VcnWifiUnderlyingNetworkTemplate(
|
private VcnWifiUnderlyingNetworkTemplate(
|
||||||
int networkQuality, int meteredMatchCriteria, Set<String> ssids) {
|
int meteredMatchCriteria,
|
||||||
super(NETWORK_PRIORITY_TYPE_WIFI, networkQuality, meteredMatchCriteria);
|
int minEntryUpstreamBandwidthKbps,
|
||||||
|
int minExitUpstreamBandwidthKbps,
|
||||||
|
int minEntryDownstreamBandwidthKbps,
|
||||||
|
int minExitDownstreamBandwidthKbps,
|
||||||
|
Set<String> ssids) {
|
||||||
|
super(
|
||||||
|
NETWORK_PRIORITY_TYPE_WIFI,
|
||||||
|
meteredMatchCriteria,
|
||||||
|
minEntryUpstreamBandwidthKbps,
|
||||||
|
minExitUpstreamBandwidthKbps,
|
||||||
|
minEntryDownstreamBandwidthKbps,
|
||||||
|
minExitDownstreamBandwidthKbps);
|
||||||
mSsids = new ArraySet<>(ssids);
|
mSsids = new ArraySet<>(ssids);
|
||||||
|
|
||||||
validate();
|
validate();
|
||||||
@@ -75,15 +86,29 @@ public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
@NonNull PersistableBundle in) {
|
@NonNull PersistableBundle in) {
|
||||||
Objects.requireNonNull(in, "PersistableBundle is null");
|
Objects.requireNonNull(in, "PersistableBundle is null");
|
||||||
|
|
||||||
final int networkQuality = in.getInt(NETWORK_QUALITY_KEY);
|
|
||||||
final int meteredMatchCriteria = in.getInt(METERED_MATCH_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 ssidsBundle = in.getPersistableBundle(SSIDS_KEY);
|
final PersistableBundle ssidsBundle = in.getPersistableBundle(SSIDS_KEY);
|
||||||
Objects.requireNonNull(ssidsBundle, "ssidsBundle is null");
|
Objects.requireNonNull(ssidsBundle, "ssidsBundle is null");
|
||||||
final Set<String> ssids =
|
final Set<String> ssids =
|
||||||
new ArraySet<String>(
|
new ArraySet<String>(
|
||||||
PersistableBundleUtils.toList(ssidsBundle, STRING_DESERIALIZER));
|
PersistableBundleUtils.toList(ssidsBundle, STRING_DESERIALIZER));
|
||||||
return new VcnWifiUnderlyingNetworkTemplate(networkQuality, meteredMatchCriteria, ssids);
|
return new VcnWifiUnderlyingNetworkTemplate(
|
||||||
|
meteredMatchCriteria,
|
||||||
|
minEntryUpstreamBandwidthKbps,
|
||||||
|
minExitUpstreamBandwidthKbps,
|
||||||
|
minEntryDownstreamBandwidthKbps,
|
||||||
|
minExitDownstreamBandwidthKbps,
|
||||||
|
ssids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -137,32 +162,17 @@ public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
|
|
||||||
/** This class is used to incrementally build VcnWifiUnderlyingNetworkTemplate objects. */
|
/** This class is used to incrementally build VcnWifiUnderlyingNetworkTemplate objects. */
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private int mNetworkQuality = NETWORK_QUALITY_ANY;
|
|
||||||
private int mMeteredMatchCriteria = MATCH_ANY;
|
private int mMeteredMatchCriteria = MATCH_ANY;
|
||||||
@NonNull private final Set<String> mSsids = new ArraySet<>();
|
@NonNull private final Set<String> mSsids = new ArraySet<>();
|
||||||
|
|
||||||
|
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. */
|
/** Construct a Builder object. */
|
||||||
public Builder() {}
|
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.
|
* Set the matching criteria for metered networks.
|
||||||
*
|
*
|
||||||
@@ -200,11 +210,93 @@ public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the minimum upstream bandwidths that this template will match.
|
||||||
|
*
|
||||||
|
* <p>This template will not match a network that does not provide at least the bandwidth
|
||||||
|
* passed as the entry bandwidth, except in the case that the network is selected as the VCN
|
||||||
|
* Gateway Connection's underlying network, where it will continue to match until the
|
||||||
|
* bandwidth drops under the exit bandwidth.
|
||||||
|
*
|
||||||
|
* <p>The entry criteria MUST be greater than, or equal to the exit criteria to avoid the
|
||||||
|
* invalid case where a network fulfills the entry criteria, but at the same time fails 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 networks
|
||||||
|
* that ARE NOT the already-selected underlying network, or {@code 0} to disable this
|
||||||
|
* requirement. Disabled by default.
|
||||||
|
* @param minExitUpstreamBandwidthKbps the minimum accepted upstream bandwidth for a network
|
||||||
|
* that IS the already-selected underlying network, or {@code 0} to disable this
|
||||||
|
* requirement. Disabled by default.
|
||||||
|
* @return this {@link Builder} instance, for chaining
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
// The getter for the two integers are separated, and in the superclass. Please see {@link
|
||||||
|
// VcnUnderlyingNetworkTemplate#getMinEntryUpstreamBandwidthKbps()} and {@link
|
||||||
|
// VcnUnderlyingNetworkTemplate#getMinExitUpstreamBandwidthKbps()}
|
||||||
|
@SuppressLint("MissingGetterMatchingBuilder")
|
||||||
|
public Builder setMinUpstreamBandwidthKbps(
|
||||||
|
int minEntryUpstreamBandwidthKbps, int minExitUpstreamBandwidthKbps) {
|
||||||
|
validateMinBandwidthKbps(minEntryUpstreamBandwidthKbps, minExitUpstreamBandwidthKbps);
|
||||||
|
|
||||||
|
mMinEntryUpstreamBandwidthKbps = minEntryUpstreamBandwidthKbps;
|
||||||
|
mMinExitUpstreamBandwidthKbps = minExitUpstreamBandwidthKbps;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the minimum upstream bandwidths that this template will match.
|
||||||
|
*
|
||||||
|
* <p>This template will not match a network that does not provide at least the bandwidth
|
||||||
|
* passed as the entry bandwidth, except in the case that the network is selected as the VCN
|
||||||
|
* Gateway Connection's underlying network, where it will continue to match until the
|
||||||
|
* bandwidth drops under the exit bandwidth.
|
||||||
|
*
|
||||||
|
* <p>The entry criteria MUST be greater than, or equal to the exit criteria to avoid the
|
||||||
|
* invalid case where a network fulfills the entry criteria, but at the same time fails 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
|
||||||
|
* networks that ARE NOT the already-selected underlying network, or {@code 0} to
|
||||||
|
* disable this requirement. Disabled by default.
|
||||||
|
* @param minExitDownstreamBandwidthKbps the minimum accepted downstream bandwidth for a
|
||||||
|
* network that IS the already-selected underlying network, or {@code 0} to disable this
|
||||||
|
* requirement. Disabled by default.
|
||||||
|
* @return this {@link Builder} instance, for chaining
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
// The getter for the two integers are separated, and in the superclass. Please see {@link
|
||||||
|
// VcnUnderlyingNetworkTemplate#getMinEntryDownstreamBandwidthKbps()} and {@link
|
||||||
|
// VcnUnderlyingNetworkTemplate#getMinExitDownstreamBandwidthKbps()}
|
||||||
|
@SuppressLint("MissingGetterMatchingBuilder")
|
||||||
|
public Builder setMinDownstreamBandwidthKbps(
|
||||||
|
int minEntryDownstreamBandwidthKbps, int minExitDownstreamBandwidthKbps) {
|
||||||
|
validateMinBandwidthKbps(
|
||||||
|
minEntryDownstreamBandwidthKbps, minExitDownstreamBandwidthKbps);
|
||||||
|
|
||||||
|
mMinEntryDownstreamBandwidthKbps = minEntryDownstreamBandwidthKbps;
|
||||||
|
mMinExitDownstreamBandwidthKbps = minExitDownstreamBandwidthKbps;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** Build the VcnWifiUnderlyingNetworkTemplate. */
|
/** Build the VcnWifiUnderlyingNetworkTemplate. */
|
||||||
@NonNull
|
@NonNull
|
||||||
public VcnWifiUnderlyingNetworkTemplate build() {
|
public VcnWifiUnderlyingNetworkTemplate build() {
|
||||||
return new VcnWifiUnderlyingNetworkTemplate(
|
return new VcnWifiUnderlyingNetworkTemplate(
|
||||||
mNetworkQuality, mMeteredMatchCriteria, mSsids);
|
mMeteredMatchCriteria,
|
||||||
|
mMinEntryUpstreamBandwidthKbps,
|
||||||
|
mMinExitUpstreamBandwidthKbps,
|
||||||
|
mMinEntryDownstreamBandwidthKbps,
|
||||||
|
mMinExitDownstreamBandwidthKbps,
|
||||||
|
mSsids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import static android.net.NetworkCapabilities.TRANSPORT_TEST;
|
|||||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
|
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
|
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;
|
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 com.android.server.vcn.VcnContext;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/** @hide */
|
/** @hide */
|
||||||
@@ -121,9 +120,10 @@ class NetworkPriorityClassifier {
|
|||||||
TelephonySubscriptionSnapshot snapshot,
|
TelephonySubscriptionSnapshot snapshot,
|
||||||
UnderlyingNetworkRecord currentlySelected,
|
UnderlyingNetworkRecord currentlySelected,
|
||||||
PersistableBundle carrierConfig) {
|
PersistableBundle carrierConfig) {
|
||||||
// TODO: Check Network Quality reported by metric monitors/probers.
|
|
||||||
|
|
||||||
final NetworkCapabilities caps = networkRecord.networkCapabilities;
|
final NetworkCapabilities caps = networkRecord.networkCapabilities;
|
||||||
|
final boolean isSelectedUnderlyingNetwork =
|
||||||
|
currentlySelected != null
|
||||||
|
&& Objects.equals(currentlySelected.network, networkRecord.network);
|
||||||
|
|
||||||
final int meteredMatch = networkPriority.getMetered();
|
final int meteredMatch = networkPriority.getMetered();
|
||||||
final boolean isMetered = !caps.hasCapability(NET_CAPABILITY_NOT_METERED);
|
final boolean isMetered = !caps.hasCapability(NET_CAPABILITY_NOT_METERED);
|
||||||
@@ -132,6 +132,23 @@ class NetworkPriorityClassifier {
|
|||||||
return false;
|
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)) {
|
if (vcnContext.isInTestMode() && caps.hasTransport(TRANSPORT_TEST)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -172,8 +189,7 @@ class NetworkPriorityClassifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move the Network Quality check to the network metric monitor framework.
|
// TODO: Move the Network Quality check to the network metric monitor framework.
|
||||||
if (networkPriority.getNetworkQuality()
|
if (!isWifiRssiAcceptable(networkRecord, currentlySelected, carrierConfig)) {
|
||||||
> getWifiQuality(networkRecord, currentlySelected, carrierConfig)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +201,7 @@ class NetworkPriorityClassifier {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getWifiQuality(
|
private static boolean isWifiRssiAcceptable(
|
||||||
UnderlyingNetworkRecord networkRecord,
|
UnderlyingNetworkRecord networkRecord,
|
||||||
UnderlyingNetworkRecord currentlySelected,
|
UnderlyingNetworkRecord currentlySelected,
|
||||||
PersistableBundle carrierConfig) {
|
PersistableBundle carrierConfig) {
|
||||||
@@ -196,14 +212,14 @@ class NetworkPriorityClassifier {
|
|||||||
|
|
||||||
if (isSelectedNetwork
|
if (isSelectedNetwork
|
||||||
&& caps.getSignalStrength() >= getWifiExitRssiThreshold(carrierConfig)) {
|
&& caps.getSignalStrength() >= getWifiExitRssiThreshold(carrierConfig)) {
|
||||||
return NETWORK_QUALITY_OK;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (caps.getSignalStrength() >= getWifiEntryRssiThreshold(carrierConfig)) {
|
if (caps.getSignalStrength() >= getWifiEntryRssiThreshold(carrierConfig)) {
|
||||||
return NETWORK_QUALITY_OK;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NETWORK_QUALITY_ANY;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting(visibility = Visibility.PRIVATE)
|
@VisibleForTesting(visibility = Visibility.PRIVATE)
|
||||||
|
|||||||
@@ -18,25 +18,29 @@ package android.net.vcn;
|
|||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
|
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
|
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
|
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 org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class VcnCellUnderlyingNetworkTemplateTest {
|
public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTemplateTestBase {
|
||||||
private static final Set<String> ALLOWED_PLMN_IDS = new HashSet<>();
|
private static final Set<String> ALLOWED_PLMN_IDS = new HashSet<>();
|
||||||
private static final Set<Integer> ALLOWED_CARRIER_IDS = new HashSet<>();
|
private static final Set<Integer> ALLOWED_CARRIER_IDS = new HashSet<>();
|
||||||
|
|
||||||
// Package private for use in VcnGatewayConnectionConfigTest
|
// Package private for use in VcnGatewayConnectionConfigTest
|
||||||
static VcnCellUnderlyingNetworkTemplate getTestNetworkTemplate() {
|
static VcnCellUnderlyingNetworkTemplate getTestNetworkTemplate() {
|
||||||
return new VcnCellUnderlyingNetworkTemplate.Builder()
|
return new VcnCellUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(NETWORK_QUALITY_OK)
|
|
||||||
.setMetered(MATCH_FORBIDDEN)
|
.setMetered(MATCH_FORBIDDEN)
|
||||||
|
.setMinUpstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS)
|
||||||
|
.setMinDownstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS)
|
||||||
.setOperatorPlmnIds(ALLOWED_PLMN_IDS)
|
.setOperatorPlmnIds(ALLOWED_PLMN_IDS)
|
||||||
.setSimSpecificCarrierIds(ALLOWED_CARRIER_IDS)
|
.setSimSpecificCarrierIds(ALLOWED_CARRIER_IDS)
|
||||||
.setRoaming(MATCH_FORBIDDEN)
|
.setRoaming(MATCH_FORBIDDEN)
|
||||||
@@ -47,8 +51,19 @@ public class VcnCellUnderlyingNetworkTemplateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBuilderAndGetters() {
|
public void testBuilderAndGetters() {
|
||||||
final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
|
final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
|
||||||
assertEquals(NETWORK_QUALITY_OK, networkPriority.getNetworkQuality());
|
|
||||||
assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered());
|
assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered());
|
||||||
|
assertEquals(
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
networkPriority.getMinEntryUpstreamBandwidthKbps());
|
||||||
|
assertEquals(
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
networkPriority.getMinExitUpstreamBandwidthKbps());
|
||||||
|
assertEquals(
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
networkPriority.getMinEntryDownstreamBandwidthKbps());
|
||||||
|
assertEquals(
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
networkPriority.getMinExitDownstreamBandwidthKbps());
|
||||||
assertEquals(ALLOWED_PLMN_IDS, networkPriority.getOperatorPlmnIds());
|
assertEquals(ALLOWED_PLMN_IDS, networkPriority.getOperatorPlmnIds());
|
||||||
assertEquals(ALLOWED_CARRIER_IDS, networkPriority.getSimSpecificCarrierIds());
|
assertEquals(ALLOWED_CARRIER_IDS, networkPriority.getSimSpecificCarrierIds());
|
||||||
assertEquals(MATCH_FORBIDDEN, networkPriority.getRoaming());
|
assertEquals(MATCH_FORBIDDEN, networkPriority.getRoaming());
|
||||||
@@ -59,14 +74,43 @@ public class VcnCellUnderlyingNetworkTemplateTest {
|
|||||||
public void testBuilderAndGettersForDefaultValues() {
|
public void testBuilderAndGettersForDefaultValues() {
|
||||||
final VcnCellUnderlyingNetworkTemplate networkPriority =
|
final VcnCellUnderlyingNetworkTemplate networkPriority =
|
||||||
new VcnCellUnderlyingNetworkTemplate.Builder().build();
|
new VcnCellUnderlyingNetworkTemplate.Builder().build();
|
||||||
assertEquals(NETWORK_QUALITY_ANY, networkPriority.getNetworkQuality());
|
|
||||||
assertEquals(MATCH_ANY, networkPriority.getMetered());
|
assertEquals(MATCH_ANY, networkPriority.getMetered());
|
||||||
|
|
||||||
|
// Explicitly expect 0, as documented in Javadoc on setter methods.
|
||||||
|
assertEquals(0, networkPriority.getMinEntryUpstreamBandwidthKbps());
|
||||||
|
assertEquals(0, networkPriority.getMinExitUpstreamBandwidthKbps());
|
||||||
|
assertEquals(0, networkPriority.getMinEntryDownstreamBandwidthKbps());
|
||||||
|
assertEquals(0, networkPriority.getMinExitDownstreamBandwidthKbps());
|
||||||
|
|
||||||
assertEquals(new HashSet<String>(), networkPriority.getOperatorPlmnIds());
|
assertEquals(new HashSet<String>(), networkPriority.getOperatorPlmnIds());
|
||||||
assertEquals(new HashSet<Integer>(), networkPriority.getSimSpecificCarrierIds());
|
assertEquals(new HashSet<Integer>(), networkPriority.getSimSpecificCarrierIds());
|
||||||
assertEquals(MATCH_ANY, networkPriority.getRoaming());
|
assertEquals(MATCH_ANY, networkPriority.getRoaming());
|
||||||
assertEquals(MATCH_ANY, networkPriority.getOpportunistic());
|
assertEquals(MATCH_ANY, networkPriority.getOpportunistic());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuilderRequiresStricterEntryCriteria() {
|
||||||
|
try {
|
||||||
|
new VcnCellUnderlyingNetworkTemplate.Builder()
|
||||||
|
.setMinUpstreamBandwidthKbps(
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS);
|
||||||
|
|
||||||
|
fail("Expected IAE for exit threshold > entry threshold");
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
new VcnCellUnderlyingNetworkTemplate.Builder()
|
||||||
|
.setMinDownstreamBandwidthKbps(
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS);
|
||||||
|
|
||||||
|
fail("Expected IAE for exit threshold > entry threshold");
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPersistableBundle() {
|
public void testPersistableBundle() {
|
||||||
final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
|
final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2021 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 android.net.vcn;
|
||||||
|
|
||||||
|
public class VcnUnderlyingNetworkTemplateTestBase {
|
||||||
|
// Public for use in NetworkPriorityClassifierTest
|
||||||
|
public static final int TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS = 200;
|
||||||
|
public static final int TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS = 100;
|
||||||
|
public static final int TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS = 400;
|
||||||
|
public static final int TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS = 300;
|
||||||
|
}
|
||||||
@@ -17,8 +17,6 @@ package android.net.vcn;
|
|||||||
|
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
|
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
|
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_ANY;
|
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -28,15 +26,19 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class VcnWifiUnderlyingNetworkTemplateTest {
|
public class VcnWifiUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTemplateTestBase {
|
||||||
private static final String SSID = "TestWifi";
|
private static final String SSID = "TestWifi";
|
||||||
private static final int INVALID_NETWORK_QUALITY = -1;
|
|
||||||
|
|
||||||
// Package private for use in VcnGatewayConnectionConfigTest
|
// Package private for use in VcnGatewayConnectionConfigTest
|
||||||
static VcnWifiUnderlyingNetworkTemplate getTestNetworkTemplate() {
|
static VcnWifiUnderlyingNetworkTemplate getTestNetworkTemplate() {
|
||||||
return new VcnWifiUnderlyingNetworkTemplate.Builder()
|
return new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(NETWORK_QUALITY_OK)
|
|
||||||
.setMetered(MATCH_FORBIDDEN)
|
.setMetered(MATCH_FORBIDDEN)
|
||||||
|
.setMinUpstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS)
|
||||||
|
.setMinDownstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS)
|
||||||
.setSsids(Set.of(SSID))
|
.setSsids(Set.of(SSID))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
@@ -44,8 +46,19 @@ public class VcnWifiUnderlyingNetworkTemplateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testBuilderAndGetters() {
|
public void testBuilderAndGetters() {
|
||||||
final VcnWifiUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
|
final VcnWifiUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
|
||||||
assertEquals(NETWORK_QUALITY_OK, networkPriority.getNetworkQuality());
|
|
||||||
assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered());
|
assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered());
|
||||||
|
assertEquals(
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
networkPriority.getMinEntryUpstreamBandwidthKbps());
|
||||||
|
assertEquals(
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
networkPriority.getMinExitUpstreamBandwidthKbps());
|
||||||
|
assertEquals(
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
networkPriority.getMinEntryDownstreamBandwidthKbps());
|
||||||
|
assertEquals(
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
networkPriority.getMinExitDownstreamBandwidthKbps());
|
||||||
assertEquals(Set.of(SSID), networkPriority.getSsids());
|
assertEquals(Set.of(SSID), networkPriority.getSsids());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,18 +66,37 @@ public class VcnWifiUnderlyingNetworkTemplateTest {
|
|||||||
public void testBuilderAndGettersForDefaultValues() {
|
public void testBuilderAndGettersForDefaultValues() {
|
||||||
final VcnWifiUnderlyingNetworkTemplate networkPriority =
|
final VcnWifiUnderlyingNetworkTemplate networkPriority =
|
||||||
new VcnWifiUnderlyingNetworkTemplate.Builder().build();
|
new VcnWifiUnderlyingNetworkTemplate.Builder().build();
|
||||||
assertEquals(NETWORK_QUALITY_ANY, networkPriority.getNetworkQuality());
|
|
||||||
assertEquals(MATCH_ANY, networkPriority.getMetered());
|
assertEquals(MATCH_ANY, networkPriority.getMetered());
|
||||||
|
|
||||||
|
// Explicitly expect 0, as documented in Javadoc on setter methods..
|
||||||
|
assertEquals(0, networkPriority.getMinEntryUpstreamBandwidthKbps());
|
||||||
|
assertEquals(0, networkPriority.getMinExitUpstreamBandwidthKbps());
|
||||||
|
assertEquals(0, networkPriority.getMinEntryDownstreamBandwidthKbps());
|
||||||
|
assertEquals(0, networkPriority.getMinExitDownstreamBandwidthKbps());
|
||||||
|
|
||||||
assertTrue(networkPriority.getSsids().isEmpty());
|
assertTrue(networkPriority.getSsids().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBuildWithInvalidNetworkQuality() {
|
public void testBuilderRequiresStricterEntryCriteria() {
|
||||||
try {
|
try {
|
||||||
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(INVALID_NETWORK_QUALITY);
|
.setMinUpstreamBandwidthKbps(
|
||||||
fail("Expected to fail due to the invalid network quality");
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
} catch (Exception expected) {
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS);
|
||||||
|
|
||||||
|
fail("Expected IAE for exit threshold > entry threshold");
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
|
.setMinDownstreamBandwidthKbps(
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS);
|
||||||
|
|
||||||
|
fail("Expected IAE for exit threshold > entry threshold");
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ package com.android.server.vcn.routeselection;
|
|||||||
|
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
|
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
|
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
|
||||||
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK;
|
import static android.net.vcn.VcnUnderlyingNetworkTemplateTestBase.TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS;
|
||||||
|
import static android.net.vcn.VcnUnderlyingNetworkTemplateTestBase.TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS;
|
||||||
|
import static android.net.vcn.VcnUnderlyingNetworkTemplateTestBase.TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS;
|
||||||
|
import static android.net.vcn.VcnUnderlyingNetworkTemplateTestBase.TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS;
|
||||||
|
|
||||||
import static com.android.server.vcn.VcnTestUtils.setupSystemService;
|
import static com.android.server.vcn.VcnTestUtils.setupSystemService;
|
||||||
import static com.android.server.vcn.routeselection.NetworkPriorityClassifier.PRIORITY_ANY;
|
import static com.android.server.vcn.routeselection.NetworkPriorityClassifier.PRIORITY_ANY;
|
||||||
@@ -76,6 +79,12 @@ public class NetworkPriorityClassifierTest {
|
|||||||
private static final int CARRIER_ID = 1;
|
private static final int CARRIER_ID = 1;
|
||||||
private static final int CARRIER_ID_OTHER = 2;
|
private static final int CARRIER_ID_OTHER = 2;
|
||||||
|
|
||||||
|
private static final int LINK_UPSTREAM_BANDWIDTH_KBPS = 1024;
|
||||||
|
private static final int LINK_DOWNSTREAM_BANDWIDTH_KBPS = 2048;
|
||||||
|
|
||||||
|
private static final int TEST_MIN_UPSTREAM_BANDWIDTH_KBPS = 100;
|
||||||
|
private static final int TEST_MIN_DOWNSTREAM_BANDWIDTH_KBPS = 200;
|
||||||
|
|
||||||
private static final ParcelUuid SUB_GROUP = new ParcelUuid(new UUID(0, 0));
|
private static final ParcelUuid SUB_GROUP = new ParcelUuid(new UUID(0, 0));
|
||||||
|
|
||||||
private static final NetworkCapabilities WIFI_NETWORK_CAPABILITIES =
|
private static final NetworkCapabilities WIFI_NETWORK_CAPABILITIES =
|
||||||
@@ -83,6 +92,8 @@ public class NetworkPriorityClassifierTest {
|
|||||||
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
|
||||||
.setSignalStrength(WIFI_RSSI)
|
.setSignalStrength(WIFI_RSSI)
|
||||||
.setSsid(SSID)
|
.setSsid(SSID)
|
||||||
|
.setLinkUpstreamBandwidthKbps(LINK_UPSTREAM_BANDWIDTH_KBPS)
|
||||||
|
.setLinkDownstreamBandwidthKbps(LINK_DOWNSTREAM_BANDWIDTH_KBPS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private static final TelephonyNetworkSpecifier TEL_NETWORK_SPECIFIER =
|
private static final TelephonyNetworkSpecifier TEL_NETWORK_SPECIFIER =
|
||||||
@@ -93,6 +104,8 @@ public class NetworkPriorityClassifierTest {
|
|||||||
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
|
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
|
||||||
.setSubscriptionIds(Set.of(SUB_ID))
|
.setSubscriptionIds(Set.of(SUB_ID))
|
||||||
.setNetworkSpecifier(TEL_NETWORK_SPECIFIER)
|
.setNetworkSpecifier(TEL_NETWORK_SPECIFIER)
|
||||||
|
.setLinkUpstreamBandwidthKbps(LINK_UPSTREAM_BANDWIDTH_KBPS)
|
||||||
|
.setLinkDownstreamBandwidthKbps(LINK_DOWNSTREAM_BANDWIDTH_KBPS)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
private static final LinkProperties LINK_PROPERTIES = getLinkPropertiesWithName("test_iface");
|
private static final LinkProperties LINK_PROPERTIES = getLinkPropertiesWithName("test_iface");
|
||||||
@@ -146,7 +159,6 @@ public class NetworkPriorityClassifierTest {
|
|||||||
public void testMatchWithoutNotMeteredBit() {
|
public void testMatchWithoutNotMeteredBit() {
|
||||||
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
|
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
|
||||||
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(NETWORK_QUALITY_OK)
|
|
||||||
.setMetered(MATCH_FORBIDDEN)
|
.setMetered(MATCH_FORBIDDEN)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -161,11 +173,133 @@ public class NetworkPriorityClassifierTest {
|
|||||||
null /* carrierConfig */));
|
null /* carrierConfig */));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void verifyMatchesPriorityRuleForUpstreamBandwidth(
|
||||||
|
int entryUpstreamBandwidth,
|
||||||
|
int exitUpstreamBandwidth,
|
||||||
|
UnderlyingNetworkRecord currentlySelected,
|
||||||
|
boolean expectMatch) {
|
||||||
|
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
|
||||||
|
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
|
.setMinUpstreamBandwidthKbps(entryUpstreamBandwidth, exitUpstreamBandwidth)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
expectMatch,
|
||||||
|
checkMatchesPriorityRule(
|
||||||
|
mVcnContext,
|
||||||
|
wifiNetworkPriority,
|
||||||
|
mWifiNetworkRecord,
|
||||||
|
SUB_GROUP,
|
||||||
|
mSubscriptionSnapshot,
|
||||||
|
currentlySelected,
|
||||||
|
null /* carrierConfig */));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyMatchesPriorityRuleForDownstreamBandwidth(
|
||||||
|
int entryDownstreamBandwidth,
|
||||||
|
int exitDownstreamBandwidth,
|
||||||
|
UnderlyingNetworkRecord currentlySelected,
|
||||||
|
boolean expectMatch) {
|
||||||
|
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
|
||||||
|
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
|
.setMinDownstreamBandwidthKbps(
|
||||||
|
entryDownstreamBandwidth, exitDownstreamBandwidth)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
expectMatch,
|
||||||
|
checkMatchesPriorityRule(
|
||||||
|
mVcnContext,
|
||||||
|
wifiNetworkPriority,
|
||||||
|
mWifiNetworkRecord,
|
||||||
|
SUB_GROUP,
|
||||||
|
mSubscriptionSnapshot,
|
||||||
|
currentlySelected,
|
||||||
|
null /* carrierConfig */));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchWithEntryUpstreamBandwidthEquals() {
|
||||||
|
verifyMatchesPriorityRuleForUpstreamBandwidth(
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
null /* currentlySelected */,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchWithEntryUpstreamBandwidthTooLow() {
|
||||||
|
verifyMatchesPriorityRuleForUpstreamBandwidth(
|
||||||
|
LINK_UPSTREAM_BANDWIDTH_KBPS + 1,
|
||||||
|
LINK_UPSTREAM_BANDWIDTH_KBPS + 1,
|
||||||
|
null /* currentlySelected */,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchWithEntryDownstreamBandwidthEquals() {
|
||||||
|
verifyMatchesPriorityRuleForDownstreamBandwidth(
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
null /* currentlySelected */,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchWithEntryDownstreamBandwidthTooLow() {
|
||||||
|
verifyMatchesPriorityRuleForDownstreamBandwidth(
|
||||||
|
LINK_DOWNSTREAM_BANDWIDTH_KBPS + 1,
|
||||||
|
LINK_DOWNSTREAM_BANDWIDTH_KBPS + 1,
|
||||||
|
null /* currentlySelected */,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchWithExitUpstreamBandwidthEquals() {
|
||||||
|
verifyMatchesPriorityRuleForUpstreamBandwidth(
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
mWifiNetworkRecord,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchWithExitUpstreamBandwidthTooLow() {
|
||||||
|
verifyMatchesPriorityRuleForUpstreamBandwidth(
|
||||||
|
LINK_UPSTREAM_BANDWIDTH_KBPS + 1,
|
||||||
|
LINK_UPSTREAM_BANDWIDTH_KBPS + 1,
|
||||||
|
mWifiNetworkRecord,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchWithExitDownstreamBandwidthEquals() {
|
||||||
|
verifyMatchesPriorityRuleForDownstreamBandwidth(
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
mWifiNetworkRecord,
|
||||||
|
true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMatchWithExitDownstreamBandwidthTooLow() {
|
||||||
|
verifyMatchesPriorityRuleForDownstreamBandwidth(
|
||||||
|
LINK_DOWNSTREAM_BANDWIDTH_KBPS + 1,
|
||||||
|
LINK_DOWNSTREAM_BANDWIDTH_KBPS + 1,
|
||||||
|
mWifiNetworkRecord,
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
|
||||||
private void verifyMatchWifi(
|
private void verifyMatchWifi(
|
||||||
boolean isSelectedNetwork, PersistableBundle carrierConfig, boolean expectMatch) {
|
boolean isSelectedNetwork, PersistableBundle carrierConfig, boolean expectMatch) {
|
||||||
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
|
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
|
||||||
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(NETWORK_QUALITY_OK)
|
.setMinUpstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS)
|
||||||
|
.setMinDownstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS)
|
||||||
.build();
|
.build();
|
||||||
final UnderlyingNetworkRecord selectedNetworkRecord =
|
final UnderlyingNetworkRecord selectedNetworkRecord =
|
||||||
isSelectedNetwork ? mWifiNetworkRecord : null;
|
isSelectedNetwork ? mWifiNetworkRecord : null;
|
||||||
@@ -214,7 +348,12 @@ public class NetworkPriorityClassifierTest {
|
|||||||
final String nwPrioritySsid = useMatchedSsid ? SSID : SSID_OTHER;
|
final String nwPrioritySsid = useMatchedSsid ? SSID : SSID_OTHER;
|
||||||
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
|
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
|
||||||
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
new VcnWifiUnderlyingNetworkTemplate.Builder()
|
||||||
.setNetworkQuality(NETWORK_QUALITY_OK)
|
.setMinUpstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS)
|
||||||
|
.setMinDownstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS)
|
||||||
.setSsids(Set.of(nwPrioritySsid))
|
.setSsids(Set.of(nwPrioritySsid))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -238,7 +377,13 @@ public class NetworkPriorityClassifierTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static VcnCellUnderlyingNetworkTemplate.Builder getCellNetworkPriorityBuilder() {
|
private static VcnCellUnderlyingNetworkTemplate.Builder getCellNetworkPriorityBuilder() {
|
||||||
return new VcnCellUnderlyingNetworkTemplate.Builder().setNetworkQuality(NETWORK_QUALITY_OK);
|
return new VcnCellUnderlyingNetworkTemplate.Builder()
|
||||||
|
.setMinUpstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_UPSTREAM_BANDWIDTH_KBPS)
|
||||||
|
.setMinDownstreamBandwidthKbps(
|
||||||
|
TEST_MIN_ENTRY_DOWNSTREAM_BANDWIDTH_KBPS,
|
||||||
|
TEST_MIN_EXIT_DOWNSTREAM_BANDWIDTH_KBPS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user