Merge changes Ib7d51cf1,I92bd2831

* changes:
  Expose APIs to configure underlying network priority
  Update setter/getters to configure underlying network priority
This commit is contained in:
Benedict Wong
2022-01-12 05:21:03 +00:00
committed by Gerrit Code Review
11 changed files with 591 additions and 331 deletions

View File

@@ -27277,6 +27277,23 @@ package android.net.sip {
package android.net.vcn { package android.net.vcn {
public final class VcnCellUnderlyingNetworkTemplate extends android.net.vcn.VcnUnderlyingNetworkTemplate {
method @NonNull public java.util.Set<java.lang.String> getOperatorPlmnIds();
method public int getOpportunistic();
method public int getRoaming();
method @NonNull public java.util.Set<java.lang.Integer> getSimSpecificCarrierIds();
}
public static final class VcnCellUnderlyingNetworkTemplate.Builder {
ctor public VcnCellUnderlyingNetworkTemplate.Builder();
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 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 setRoaming(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setSimSpecificCarrierIds(@NonNull java.util.Set<java.lang.Integer>);
}
public final class VcnConfig implements android.os.Parcelable { public final class VcnConfig implements android.os.Parcelable {
method public int describeContents(); method public int describeContents();
method @NonNull public java.util.Set<android.net.vcn.VcnGatewayConnectionConfig> getGatewayConnectionConfigs(); method @NonNull public java.util.Set<android.net.vcn.VcnGatewayConnectionConfig> getGatewayConnectionConfigs();
@@ -27295,6 +27312,7 @@ package android.net.vcn {
method @NonNull public String getGatewayConnectionName(); method @NonNull public String getGatewayConnectionName();
method @IntRange(from=0x500) public int getMaxMtu(); method @IntRange(from=0x500) public int getMaxMtu();
method @NonNull public long[] getRetryIntervalsMillis(); method @NonNull public long[] getRetryIntervalsMillis();
method @NonNull public java.util.List<android.net.vcn.VcnUnderlyingNetworkTemplate> getVcnUnderlyingNetworkPriorities();
} }
public static final class VcnGatewayConnectionConfig.Builder { public static final class VcnGatewayConnectionConfig.Builder {
@@ -27304,6 +27322,7 @@ package android.net.vcn {
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeExposedCapability(int); method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder removeExposedCapability(int);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setMaxMtu(@IntRange(from=0x500) int); method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setMaxMtu(@IntRange(from=0x500) int);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setRetryIntervalsMillis(@NonNull long[]); method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setRetryIntervalsMillis(@NonNull long[]);
method @NonNull public android.net.vcn.VcnGatewayConnectionConfig.Builder setVcnUnderlyingNetworkPriorities(@NonNull java.util.List<android.net.vcn.VcnUnderlyingNetworkTemplate>);
} }
public class VcnManager { public class VcnManager {
@@ -27327,6 +27346,24 @@ package android.net.vcn {
method public abstract void onStatusChanged(int); method public abstract void onStatusChanged(int);
} }
public abstract class VcnUnderlyingNetworkTemplate {
method public int getMetered();
field public static final int MATCH_ANY = 0; // 0x0
field public static final int MATCH_FORBIDDEN = 2; // 0x2
field public static final int MATCH_REQUIRED = 1; // 0x1
}
public final class VcnWifiUnderlyingNetworkTemplate extends android.net.vcn.VcnUnderlyingNetworkTemplate {
method @NonNull public java.util.Set<java.lang.String> getSsids();
}
public static final class VcnWifiUnderlyingNetworkTemplate.Builder {
ctor public VcnWifiUnderlyingNetworkTemplate.Builder();
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 setSsids(@NonNull java.util.Set<java.lang.String>);
}
} }
package android.nfc { package android.nfc {

View File

@@ -15,6 +15,9 @@
*/ */
package android.net.vcn; package android.net.vcn;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.getMatchCriteriaString;
import static com.android.internal.annotations.VisibleForTesting.Visibility; import static com.android.internal.annotations.VisibleForTesting.Visibility;
import static com.android.server.vcn.util.PersistableBundleUtils.INTEGER_DESERIALIZER; import static com.android.server.vcn.util.PersistableBundleUtils.INTEGER_DESERIALIZER;
import static com.android.server.vcn.util.PersistableBundleUtils.INTEGER_SERIALIZER; import static com.android.server.vcn.util.PersistableBundleUtils.INTEGER_SERIALIZER;
@@ -23,8 +26,12 @@ import static com.android.server.vcn.util.PersistableBundleUtils.STRING_SERIALIZ
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.net.NetworkCapabilities;
import android.net.vcn.VcnUnderlyingNetworkTemplate.MatchCriteria;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.ArraySet; import android.util.ArraySet;
@@ -37,32 +44,36 @@ import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
// TODO: Add documents /**
/** @hide */ * This class represents a configuration for a network template class of underlying cellular
* networks.
*
* <p>See {@link VcnUnderlyingNetworkTemplate}
*/
public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetworkTemplate { public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetworkTemplate {
private static final String ALLOWED_NETWORK_PLMN_IDS_KEY = "mAllowedNetworkPlmnIds"; private static final String ALLOWED_NETWORK_PLMN_IDS_KEY = "mAllowedNetworkPlmnIds";
@NonNull private final Set<String> mAllowedNetworkPlmnIds; @NonNull private final Set<String> mAllowedNetworkPlmnIds;
private static final String ALLOWED_SPECIFIC_CARRIER_IDS_KEY = "mAllowedSpecificCarrierIds"; private static final String ALLOWED_SPECIFIC_CARRIER_IDS_KEY = "mAllowedSpecificCarrierIds";
@NonNull private final Set<Integer> mAllowedSpecificCarrierIds; @NonNull private final Set<Integer> mAllowedSpecificCarrierIds;
private static final String ALLOW_ROAMING_KEY = "mAllowRoaming"; private static final String ROAMING_MATCH_KEY = "mRoamingMatchCriteria";
private final boolean mAllowRoaming; private final int mRoamingMatchCriteria;
private static final String REQUIRE_OPPORTUNISTIC_KEY = "mRequireOpportunistic"; private static final String OPPORTUNISTIC_MATCH_KEY = "mOpportunisticMatchCriteria";
private final boolean mRequireOpportunistic; private final int mOpportunisticMatchCriteria;
private VcnCellUnderlyingNetworkTemplate( private VcnCellUnderlyingNetworkTemplate(
int networkQuality, int networkQuality,
boolean allowMetered, int meteredMatchCriteria,
Set<String> allowedNetworkPlmnIds, Set<String> allowedNetworkPlmnIds,
Set<Integer> allowedSpecificCarrierIds, Set<Integer> allowedSpecificCarrierIds,
boolean allowRoaming, int roamingMatchCriteria,
boolean requireOpportunistic) { int opportunisticMatchCriteria) {
super(NETWORK_PRIORITY_TYPE_CELL, networkQuality, allowMetered); super(NETWORK_PRIORITY_TYPE_CELL, networkQuality, meteredMatchCriteria);
mAllowedNetworkPlmnIds = new ArraySet<>(allowedNetworkPlmnIds); mAllowedNetworkPlmnIds = new ArraySet<>(allowedNetworkPlmnIds);
mAllowedSpecificCarrierIds = new ArraySet<>(allowedSpecificCarrierIds); mAllowedSpecificCarrierIds = new ArraySet<>(allowedSpecificCarrierIds);
mAllowRoaming = allowRoaming; mRoamingMatchCriteria = roamingMatchCriteria;
mRequireOpportunistic = requireOpportunistic; mOpportunisticMatchCriteria = opportunisticMatchCriteria;
validate(); validate();
} }
@@ -72,15 +83,17 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
protected void validate() { protected void validate() {
super.validate(); super.validate();
validatePlmnIds(mAllowedNetworkPlmnIds); validatePlmnIds(mAllowedNetworkPlmnIds);
Objects.requireNonNull(mAllowedSpecificCarrierIds, "allowedCarrierIds is null"); Objects.requireNonNull(mAllowedSpecificCarrierIds, "matchingCarrierIds is null");
validateMatchCriteria(mRoamingMatchCriteria, "mRoamingMatchCriteria");
validateMatchCriteria(mOpportunisticMatchCriteria, "mOpportunisticMatchCriteria");
} }
private static void validatePlmnIds(Set<String> allowedNetworkPlmnIds) { private static void validatePlmnIds(Set<String> matchingOperatorPlmnIds) {
Objects.requireNonNull(allowedNetworkPlmnIds, "allowedNetworkPlmnIds is null"); Objects.requireNonNull(matchingOperatorPlmnIds, "matchingOperatorPlmnIds is null");
// A valid PLMN is a concatenation of MNC and MCC, and thus consists of 5 or 6 decimal // A valid PLMN is a concatenation of MNC and MCC, and thus consists of 5 or 6 decimal
// digits. // digits.
for (String id : allowedNetworkPlmnIds) { for (String id : matchingOperatorPlmnIds) {
if ((id.length() == 5 || id.length() == 6) && id.matches("[0-9]+")) { if ((id.length() == 5 || id.length() == 6) && id.matches("[0-9]+")) {
continue; continue;
} else { } else {
@@ -97,7 +110,7 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
Objects.requireNonNull(in, "PersistableBundle is null"); Objects.requireNonNull(in, "PersistableBundle is null");
final int networkQuality = in.getInt(NETWORK_QUALITY_KEY); final int networkQuality = in.getInt(NETWORK_QUALITY_KEY);
final boolean allowMetered = in.getBoolean(ALLOW_METERED_KEY); final int meteredMatchCriteria = in.getInt(METERED_MATCH_KEY);
final PersistableBundle plmnIdsBundle = final PersistableBundle plmnIdsBundle =
in.getPersistableBundle(ALLOWED_NETWORK_PLMN_IDS_KEY); in.getPersistableBundle(ALLOWED_NETWORK_PLMN_IDS_KEY);
@@ -114,16 +127,16 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
PersistableBundleUtils.toList( PersistableBundleUtils.toList(
specificCarrierIdsBundle, INTEGER_DESERIALIZER)); specificCarrierIdsBundle, INTEGER_DESERIALIZER));
final boolean allowRoaming = in.getBoolean(ALLOW_ROAMING_KEY); final int roamingMatchCriteria = in.getInt(ROAMING_MATCH_KEY);
final boolean requireOpportunistic = in.getBoolean(REQUIRE_OPPORTUNISTIC_KEY); final int opportunisticMatchCriteria = in.getInt(OPPORTUNISTIC_MATCH_KEY);
return new VcnCellUnderlyingNetworkTemplate( return new VcnCellUnderlyingNetworkTemplate(
networkQuality, networkQuality,
allowMetered, meteredMatchCriteria,
allowedNetworkPlmnIds, allowedNetworkPlmnIds,
allowedSpecificCarrierIds, allowedSpecificCarrierIds,
allowRoaming, roamingMatchCriteria,
requireOpportunistic); opportunisticMatchCriteria);
} }
/** @hide */ /** @hide */
@@ -143,35 +156,51 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
new ArrayList<>(mAllowedSpecificCarrierIds), INTEGER_SERIALIZER); new ArrayList<>(mAllowedSpecificCarrierIds), INTEGER_SERIALIZER);
result.putPersistableBundle(ALLOWED_SPECIFIC_CARRIER_IDS_KEY, specificCarrierIdsBundle); result.putPersistableBundle(ALLOWED_SPECIFIC_CARRIER_IDS_KEY, specificCarrierIdsBundle);
result.putBoolean(ALLOW_ROAMING_KEY, mAllowRoaming); result.putInt(ROAMING_MATCH_KEY, mRoamingMatchCriteria);
result.putBoolean(REQUIRE_OPPORTUNISTIC_KEY, mRequireOpportunistic); result.putInt(OPPORTUNISTIC_MATCH_KEY, mOpportunisticMatchCriteria);
return result; return result;
} }
/** Retrieve the allowed PLMN IDs, or an empty set if any PLMN ID is acceptable. */ /**
* Retrieve the matching operator PLMN IDs, or an empty set if any PLMN ID is acceptable.
*
* @see Builder#setOperatorPlmnIds(Set)
*/
@NonNull @NonNull
public Set<String> getAllowedOperatorPlmnIds() { public Set<String> getOperatorPlmnIds() {
return Collections.unmodifiableSet(mAllowedNetworkPlmnIds); return Collections.unmodifiableSet(mAllowedNetworkPlmnIds);
} }
/** /**
* Retrieve the allowed specific carrier IDs, or an empty set if any specific carrier ID is * Retrieve the matching sim specific carrier IDs, or an empty set if any sim specific carrier
* acceptable. * ID is acceptable.
*
* @see Builder#setSimSpecificCarrierIds(Set)
*/ */
@NonNull @NonNull
public Set<Integer> getAllowedSpecificCarrierIds() { public Set<Integer> getSimSpecificCarrierIds() {
return Collections.unmodifiableSet(mAllowedSpecificCarrierIds); return Collections.unmodifiableSet(mAllowedSpecificCarrierIds);
} }
/** Return if roaming is allowed. */ /**
public boolean allowRoaming() { * Return the matching criteria for roaming networks.
return mAllowRoaming; *
* @see Builder#setRoaming(int)
*/
@MatchCriteria
public int getRoaming() {
return mRoamingMatchCriteria;
} }
/** Return if requiring an opportunistic network. */ /**
public boolean requireOpportunistic() { * Return the matching criteria for opportunistic cellular subscriptions.
return mRequireOpportunistic; *
* @see Builder#setOpportunistic(int)
*/
@MatchCriteria
public int getOpportunistic() {
return mOpportunisticMatchCriteria;
} }
@Override @Override
@@ -180,8 +209,8 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
super.hashCode(), super.hashCode(),
mAllowedNetworkPlmnIds, mAllowedNetworkPlmnIds,
mAllowedSpecificCarrierIds, mAllowedSpecificCarrierIds,
mAllowRoaming, mRoamingMatchCriteria,
mRequireOpportunistic); mOpportunisticMatchCriteria);
} }
@Override @Override
@@ -197,8 +226,8 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
final VcnCellUnderlyingNetworkTemplate rhs = (VcnCellUnderlyingNetworkTemplate) other; final VcnCellUnderlyingNetworkTemplate rhs = (VcnCellUnderlyingNetworkTemplate) other;
return Objects.equals(mAllowedNetworkPlmnIds, rhs.mAllowedNetworkPlmnIds) return Objects.equals(mAllowedNetworkPlmnIds, rhs.mAllowedNetworkPlmnIds)
&& Objects.equals(mAllowedSpecificCarrierIds, rhs.mAllowedSpecificCarrierIds) && Objects.equals(mAllowedSpecificCarrierIds, rhs.mAllowedSpecificCarrierIds)
&& mAllowRoaming == rhs.mAllowRoaming && mRoamingMatchCriteria == rhs.mRoamingMatchCriteria
&& mRequireOpportunistic == rhs.mRequireOpportunistic; && mOpportunisticMatchCriteria == rhs.mOpportunisticMatchCriteria;
} }
/** @hide */ /** @hide */
@@ -206,77 +235,137 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
void dumpTransportSpecificFields(IndentingPrintWriter pw) { void dumpTransportSpecificFields(IndentingPrintWriter pw) {
pw.println("mAllowedNetworkPlmnIds: " + mAllowedNetworkPlmnIds.toString()); pw.println("mAllowedNetworkPlmnIds: " + mAllowedNetworkPlmnIds.toString());
pw.println("mAllowedSpecificCarrierIds: " + mAllowedSpecificCarrierIds.toString()); pw.println("mAllowedSpecificCarrierIds: " + mAllowedSpecificCarrierIds.toString());
pw.println("mAllowRoaming: " + mAllowRoaming); pw.println("mRoamingMatchCriteria: " + getMatchCriteriaString(mRoamingMatchCriteria));
pw.println("mRequireOpportunistic: " + mRequireOpportunistic); pw.println(
"mOpportunisticMatchCriteria: "
+ getMatchCriteriaString(mOpportunisticMatchCriteria));
} }
/** This class is used to incrementally build WifiNetworkPriority objects. */ /** This class is used to incrementally build VcnCellUnderlyingNetworkTemplate objects. */
public static final class Builder extends VcnUnderlyingNetworkTemplate.Builder<Builder> { public static final class Builder {
private int mNetworkQuality = NETWORK_QUALITY_ANY;
private int mMeteredMatchCriteria = MATCH_ANY;
@NonNull private final Set<String> mAllowedNetworkPlmnIds = new ArraySet<>(); @NonNull private final Set<String> mAllowedNetworkPlmnIds = new ArraySet<>();
@NonNull private final Set<Integer> mAllowedSpecificCarrierIds = new ArraySet<>(); @NonNull private final Set<Integer> mAllowedSpecificCarrierIds = new ArraySet<>();
private boolean mAllowRoaming = false; private int mRoamingMatchCriteria = MATCH_ANY;
private boolean mRequireOpportunistic = false; private int mOpportunisticMatchCriteria = MATCH_ANY;
/** Construct a Builder object. */ /** Construct a Builder object. */
public Builder() {} public Builder() {}
/** /**
* Set allowed operator PLMN IDs. * 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.
*
* <p>A template where setMetered(MATCH_REQUIRED) will only match metered networks (one
* without NET_CAPABILITY_NOT_METERED). A template where setMetered(MATCH_FORBIDDEN) will
* only match a network that is not metered (one with NET_CAPABILITY_NOT_METERED).
*
* @param matchCriteria the matching criteria for metered networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_NOT_METERED
*/
// The matching getter is defined in the super class. Please see {@link
// VcnUnderlyingNetworkTemplate#getMetered()}
@SuppressLint("MissingGetterMatchingBuilder")
@NonNull
public Builder setMetered(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setMetered");
mMeteredMatchCriteria = matchCriteria;
return this;
}
/**
* Set operator PLMN IDs with which a network can match this template.
* *
* <p>This is used to distinguish cases where roaming agreements may dictate a different * <p>This is used to distinguish cases where roaming agreements may dictate a different
* priority from a partner's networks. * priority from a partner's networks.
* *
* @param allowedNetworkPlmnIds the allowed operator PLMN IDs in String. Defaults to an * @param operatorPlmnIds the matching operator PLMN IDs in String. Network with one of the
* empty set, allowing ANY PLMN ID. A valid PLMN is a concatenation of MNC and MCC, and * matching PLMN IDs can match this template. If the set is empty, any PLMN ID will
* thus consists of 5 or 6 decimal digits. See {@link SubscriptionInfo#getMccString()} * match. The default is an empty set. A valid PLMN is a concatenation of MNC and MCC,
* and {@link SubscriptionInfo#getMncString()}. * and thus consists of 5 or 6 decimal digits.
* @see SubscriptionInfo#getMccString()
* @see SubscriptionInfo#getMncString()
*/ */
@NonNull @NonNull
public Builder setAllowedOperatorPlmnIds(@NonNull Set<String> allowedNetworkPlmnIds) { public Builder setOperatorPlmnIds(@NonNull Set<String> operatorPlmnIds) {
validatePlmnIds(allowedNetworkPlmnIds); validatePlmnIds(operatorPlmnIds);
mAllowedNetworkPlmnIds.clear(); mAllowedNetworkPlmnIds.clear();
mAllowedNetworkPlmnIds.addAll(allowedNetworkPlmnIds); mAllowedNetworkPlmnIds.addAll(operatorPlmnIds);
return this; return this;
} }
/** /**
* Set allowed specific carrier IDs. * Set sim specific carrier IDs with which a network can match this template.
* *
* @param allowedSpecificCarrierIds the allowed specific carrier IDs. Defaults to an empty * @param simSpecificCarrierIds the matching sim specific carrier IDs. Network with one of
* set, allowing ANY carrier ID. See {@link TelephonyManager#getSimSpecificCarrierId()}. * the sim specific carrier IDs can match this template. If the set is empty, any
* carrier ID will match. The default is an empty set.
* @see TelephonyManager#getSimSpecificCarrierId()
*/ */
@NonNull @NonNull
public Builder setAllowedSpecificCarrierIds( public Builder setSimSpecificCarrierIds(@NonNull Set<Integer> simSpecificCarrierIds) {
@NonNull Set<Integer> allowedSpecificCarrierIds) { Objects.requireNonNull(simSpecificCarrierIds, "simSpecificCarrierIds is null");
Objects.requireNonNull(allowedSpecificCarrierIds, "allowedCarrierIds is null");
mAllowedSpecificCarrierIds.clear(); mAllowedSpecificCarrierIds.clear();
mAllowedSpecificCarrierIds.addAll(allowedSpecificCarrierIds); mAllowedSpecificCarrierIds.addAll(simSpecificCarrierIds);
return this; return this;
} }
/** /**
* Set if roaming is allowed. * Set the matching criteria for roaming networks.
* *
* @param allowRoaming the flag to indicate if roaming is allowed. Defaults to {@code * <p>A template where setRoaming(MATCH_REQUIRED) will only match roaming networks (one
* false}. * without NET_CAPABILITY_NOT_ROAMING). A template where setRoaming(MATCH_FORBIDDEN) will
* only match a network that is not roaming (one with NET_CAPABILITY_NOT_ROAMING).
*
* @param matchCriteria the matching criteria for roaming networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_NOT_ROAMING
*/ */
@NonNull @NonNull
public Builder setAllowRoaming(boolean allowRoaming) { public Builder setRoaming(@MatchCriteria int matchCriteria) {
mAllowRoaming = allowRoaming; validateMatchCriteria(matchCriteria, "setRoaming");
mRoamingMatchCriteria = matchCriteria;
return this; return this;
} }
/** /**
* Set if requiring an opportunistic network. * Set the matching criteria for opportunistic cellular subscriptions.
* *
* @param requireOpportunistic the flag to indicate if caller requires an opportunistic * @param matchCriteria the matching criteria for opportunistic cellular subscriptions.
* network. Defaults to {@code false}. * Defaults to {@link #MATCH_ANY}.
* @see SubscriptionManager#setOpportunistic(boolean, int)
*/ */
@NonNull @NonNull
public Builder setRequireOpportunistic(boolean requireOpportunistic) { public Builder setOpportunistic(@MatchCriteria int matchCriteria) {
mRequireOpportunistic = requireOpportunistic; validateMatchCriteria(matchCriteria, "setOpportunistic");
mOpportunisticMatchCriteria = matchCriteria;
return this; return this;
} }
@@ -285,17 +374,11 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
public VcnCellUnderlyingNetworkTemplate build() { public VcnCellUnderlyingNetworkTemplate build() {
return new VcnCellUnderlyingNetworkTemplate( return new VcnCellUnderlyingNetworkTemplate(
mNetworkQuality, mNetworkQuality,
mAllowMetered, mMeteredMatchCriteria,
mAllowedNetworkPlmnIds, mAllowedNetworkPlmnIds,
mAllowedSpecificCarrierIds, mAllowedSpecificCarrierIds,
mAllowRoaming, mRoamingMatchCriteria,
mRequireOpportunistic); mOpportunisticMatchCriteria);
}
/** @hide */
@Override
Builder self() {
return this;
} }
} }
} }

View File

@@ -16,6 +16,7 @@
package android.net.vcn; 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.NETWORK_QUALITY_OK; 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;
@@ -42,7 +43,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
@@ -162,30 +163,24 @@ public final class VcnGatewayConnectionConfig {
/** @hide */ /** @hide */
@VisibleForTesting(visibility = Visibility.PRIVATE) @VisibleForTesting(visibility = Visibility.PRIVATE)
public static final LinkedHashSet<VcnUnderlyingNetworkTemplate> public static final List<VcnUnderlyingNetworkTemplate> DEFAULT_UNDERLYING_NETWORK_TEMPLATES =
DEFAULT_UNDERLYING_NETWORK_PRIORITIES = new LinkedHashSet<>(); new ArrayList<>();
static { static {
DEFAULT_UNDERLYING_NETWORK_PRIORITIES.add( DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
new VcnCellUnderlyingNetworkTemplate.Builder() new VcnCellUnderlyingNetworkTemplate.Builder()
.setNetworkQuality(NETWORK_QUALITY_OK) .setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(true /* allowMetered */) .setOpportunistic(MATCH_REQUIRED)
.setAllowRoaming(true /* allowRoaming */)
.setRequireOpportunistic(true /* requireOpportunistic */)
.build()); .build());
DEFAULT_UNDERLYING_NETWORK_PRIORITIES.add( DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
new VcnWifiUnderlyingNetworkTemplate.Builder() new VcnWifiUnderlyingNetworkTemplate.Builder()
.setNetworkQuality(NETWORK_QUALITY_OK) .setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(true /* allowMetered */)
.build()); .build());
DEFAULT_UNDERLYING_NETWORK_PRIORITIES.add( DEFAULT_UNDERLYING_NETWORK_TEMPLATES.add(
new VcnCellUnderlyingNetworkTemplate.Builder() new VcnCellUnderlyingNetworkTemplate.Builder()
.setNetworkQuality(NETWORK_QUALITY_OK) .setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(true /* allowMetered */)
.setAllowRoaming(true /* allowRoaming */)
.setRequireOpportunistic(false /* requireOpportunistic */)
.build()); .build());
} }
@@ -200,9 +195,9 @@ public final class VcnGatewayConnectionConfig {
/** @hide */ /** @hide */
@VisibleForTesting(visibility = Visibility.PRIVATE) @VisibleForTesting(visibility = Visibility.PRIVATE)
public static final String UNDERLYING_NETWORK_PRIORITIES_KEY = "mUnderlyingNetworkPriorities"; public static final String UNDERLYING_NETWORK_TEMPLATES_KEY = "mUnderlyingNetworkTemplates";
@NonNull private final LinkedHashSet<VcnUnderlyingNetworkTemplate> mUnderlyingNetworkPriorities; @NonNull private final List<VcnUnderlyingNetworkTemplate> mUnderlyingNetworkTemplates;
private static final String MAX_MTU_KEY = "mMaxMtu"; private static final String MAX_MTU_KEY = "mMaxMtu";
private final int mMaxMtu; private final int mMaxMtu;
@@ -215,7 +210,7 @@ public final class VcnGatewayConnectionConfig {
@NonNull String gatewayConnectionName, @NonNull String gatewayConnectionName,
@NonNull IkeTunnelConnectionParams tunnelConnectionParams, @NonNull IkeTunnelConnectionParams tunnelConnectionParams,
@NonNull Set<Integer> exposedCapabilities, @NonNull Set<Integer> exposedCapabilities,
@NonNull LinkedHashSet<VcnUnderlyingNetworkTemplate> underlyingNetworkPriorities, @NonNull List<VcnUnderlyingNetworkTemplate> underlyingNetworkTemplates,
@NonNull long[] retryIntervalsMs, @NonNull long[] retryIntervalsMs,
@IntRange(from = MIN_MTU_V6) int maxMtu) { @IntRange(from = MIN_MTU_V6) int maxMtu) {
mGatewayConnectionName = gatewayConnectionName; mGatewayConnectionName = gatewayConnectionName;
@@ -224,9 +219,9 @@ public final class VcnGatewayConnectionConfig {
mRetryIntervalsMs = retryIntervalsMs; mRetryIntervalsMs = retryIntervalsMs;
mMaxMtu = maxMtu; mMaxMtu = maxMtu;
mUnderlyingNetworkPriorities = new LinkedHashSet<>(underlyingNetworkPriorities); mUnderlyingNetworkTemplates = new ArrayList<>(underlyingNetworkTemplates);
if (mUnderlyingNetworkPriorities.isEmpty()) { if (mUnderlyingNetworkTemplates.isEmpty()) {
mUnderlyingNetworkPriorities.addAll(DEFAULT_UNDERLYING_NETWORK_PRIORITIES); mUnderlyingNetworkTemplates.addAll(DEFAULT_UNDERLYING_NETWORK_TEMPLATES);
} }
validate(); validate();
@@ -250,22 +245,19 @@ public final class VcnGatewayConnectionConfig {
mExposedCapabilities = new TreeSet<>(PersistableBundleUtils.toList( mExposedCapabilities = new TreeSet<>(PersistableBundleUtils.toList(
exposedCapsBundle, PersistableBundleUtils.INTEGER_DESERIALIZER)); exposedCapsBundle, PersistableBundleUtils.INTEGER_DESERIALIZER));
final PersistableBundle networkPrioritiesBundle = final PersistableBundle networkTemplatesBundle =
in.getPersistableBundle(UNDERLYING_NETWORK_PRIORITIES_KEY); in.getPersistableBundle(UNDERLYING_NETWORK_TEMPLATES_KEY);
if (networkPrioritiesBundle == null) { if (networkTemplatesBundle == null) {
// UNDERLYING_NETWORK_PRIORITIES_KEY was added in Android T. Thus // UNDERLYING_NETWORK_TEMPLATES_KEY was added in Android T. Thus
// VcnGatewayConnectionConfig created on old platforms will not have this data and will // VcnGatewayConnectionConfig created on old platforms will not have this data and will
// be assigned with the default value // be assigned with the default value
mUnderlyingNetworkPriorities = mUnderlyingNetworkTemplates = new ArrayList<>(DEFAULT_UNDERLYING_NETWORK_TEMPLATES);
new LinkedHashSet<>(DEFAULT_UNDERLYING_NETWORK_PRIORITIES);
} else { } else {
mUnderlyingNetworkPriorities = mUnderlyingNetworkTemplates =
new LinkedHashSet<>( PersistableBundleUtils.toList(
PersistableBundleUtils.toList( networkTemplatesBundle,
networkPrioritiesBundle, VcnUnderlyingNetworkTemplate::fromPersistableBundle);
VcnUnderlyingNetworkTemplate::fromPersistableBundle));
} }
mRetryIntervalsMs = in.getLongArray(RETRY_INTERVAL_MS_KEY); mRetryIntervalsMs = in.getLongArray(RETRY_INTERVAL_MS_KEY);
@@ -285,7 +277,7 @@ public final class VcnGatewayConnectionConfig {
checkValidCapability(cap); checkValidCapability(cap);
} }
Objects.requireNonNull(mUnderlyingNetworkPriorities, "underlyingNetworkPriorities is null"); validateNetworkTemplateList(mUnderlyingNetworkTemplates);
Objects.requireNonNull(mRetryIntervalsMs, "retryIntervalsMs was null"); Objects.requireNonNull(mRetryIntervalsMs, "retryIntervalsMs was null");
validateRetryInterval(mRetryIntervalsMs); validateRetryInterval(mRetryIntervalsMs);
@@ -314,6 +306,19 @@ public final class VcnGatewayConnectionConfig {
} }
} }
private static void validateNetworkTemplateList(
List<VcnUnderlyingNetworkTemplate> networkPriorityRules) {
Objects.requireNonNull(networkPriorityRules, "networkPriorityRules is null");
Set<VcnUnderlyingNetworkTemplate> existingRules = new ArraySet<>();
for (VcnUnderlyingNetworkTemplate rule : networkPriorityRules) {
Objects.requireNonNull(rule, "Found null value VcnUnderlyingNetworkTemplate");
if (!existingRules.add(rule)) {
throw new IllegalArgumentException("Found duplicate VcnUnderlyingNetworkTemplate");
}
}
}
/** /**
* Returns the configured Gateway Connection name. * Returns the configured Gateway Connection name.
* *
@@ -368,15 +373,13 @@ public final class VcnGatewayConnectionConfig {
} }
/** /**
* Retrieve the configured VcnUnderlyingNetworkTemplate list, or a default list if it is not * Retrieve the VcnUnderlyingNetworkTemplate list, or a default list if it is not configured.
* configured.
* *
* @see Builder#setVcnUnderlyingNetworkPriorities(LinkedHashSet<VcnUnderlyingNetworkTemplate>) * @see Builder#setVcnUnderlyingNetworkPriorities(List)
* @hide
*/ */
@NonNull @NonNull
public LinkedHashSet<VcnUnderlyingNetworkTemplate> getVcnUnderlyingNetworkPriorities() { public List<VcnUnderlyingNetworkTemplate> getVcnUnderlyingNetworkPriorities() {
return new LinkedHashSet<>(mUnderlyingNetworkPriorities); return new ArrayList<>(mUnderlyingNetworkTemplates);
} }
/** /**
@@ -415,15 +418,15 @@ public final class VcnGatewayConnectionConfig {
PersistableBundleUtils.fromList( PersistableBundleUtils.fromList(
new ArrayList<>(mExposedCapabilities), new ArrayList<>(mExposedCapabilities),
PersistableBundleUtils.INTEGER_SERIALIZER); PersistableBundleUtils.INTEGER_SERIALIZER);
final PersistableBundle networkPrioritiesBundle = final PersistableBundle networkTemplatesBundle =
PersistableBundleUtils.fromList( PersistableBundleUtils.fromList(
new ArrayList<>(mUnderlyingNetworkPriorities), mUnderlyingNetworkTemplates,
VcnUnderlyingNetworkTemplate::toPersistableBundle); VcnUnderlyingNetworkTemplate::toPersistableBundle);
result.putString(GATEWAY_CONNECTION_NAME_KEY, mGatewayConnectionName); result.putString(GATEWAY_CONNECTION_NAME_KEY, mGatewayConnectionName);
result.putPersistableBundle(TUNNEL_CONNECTION_PARAMS_KEY, tunnelConnectionParamsBundle); result.putPersistableBundle(TUNNEL_CONNECTION_PARAMS_KEY, tunnelConnectionParamsBundle);
result.putPersistableBundle(EXPOSED_CAPABILITIES_KEY, exposedCapsBundle); result.putPersistableBundle(EXPOSED_CAPABILITIES_KEY, exposedCapsBundle);
result.putPersistableBundle(UNDERLYING_NETWORK_PRIORITIES_KEY, networkPrioritiesBundle); result.putPersistableBundle(UNDERLYING_NETWORK_TEMPLATES_KEY, networkTemplatesBundle);
result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs); result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs);
result.putInt(MAX_MTU_KEY, mMaxMtu); result.putInt(MAX_MTU_KEY, mMaxMtu);
@@ -436,7 +439,7 @@ public final class VcnGatewayConnectionConfig {
mGatewayConnectionName, mGatewayConnectionName,
mTunnelConnectionParams, mTunnelConnectionParams,
mExposedCapabilities, mExposedCapabilities,
mUnderlyingNetworkPriorities, mUnderlyingNetworkTemplates,
Arrays.hashCode(mRetryIntervalsMs), Arrays.hashCode(mRetryIntervalsMs),
mMaxMtu); mMaxMtu);
} }
@@ -451,7 +454,7 @@ public final class VcnGatewayConnectionConfig {
return mGatewayConnectionName.equals(rhs.mGatewayConnectionName) return mGatewayConnectionName.equals(rhs.mGatewayConnectionName)
&& mTunnelConnectionParams.equals(rhs.mTunnelConnectionParams) && mTunnelConnectionParams.equals(rhs.mTunnelConnectionParams)
&& mExposedCapabilities.equals(rhs.mExposedCapabilities) && mExposedCapabilities.equals(rhs.mExposedCapabilities)
&& mUnderlyingNetworkPriorities.equals(rhs.mUnderlyingNetworkPriorities) && mUnderlyingNetworkTemplates.equals(rhs.mUnderlyingNetworkTemplates)
&& Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs) && Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs)
&& mMaxMtu == rhs.mMaxMtu; && mMaxMtu == rhs.mMaxMtu;
} }
@@ -465,8 +468,8 @@ public final class VcnGatewayConnectionConfig {
@NonNull private final Set<Integer> mExposedCapabilities = new ArraySet(); @NonNull private final Set<Integer> mExposedCapabilities = new ArraySet();
@NonNull @NonNull
private final LinkedHashSet<VcnUnderlyingNetworkTemplate> mUnderlyingNetworkPriorities = private final List<VcnUnderlyingNetworkTemplate> mUnderlyingNetworkTemplates =
new LinkedHashSet<>(DEFAULT_UNDERLYING_NETWORK_PRIORITIES); new ArrayList<>(DEFAULT_UNDERLYING_NETWORK_TEMPLATES);
@NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS; @NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS;
private int mMaxMtu = DEFAULT_MAX_MTU; private int mMaxMtu = DEFAULT_MAX_MTU;
@@ -539,27 +542,37 @@ public final class VcnGatewayConnectionConfig {
} }
/** /**
* Set the VcnUnderlyingNetworkTemplate list. * Set the list of templates to match underlying networks against, in high-to-low priority
* order.
* *
* @param underlyingNetworkPriorities a list of unique VcnUnderlyingNetworkPriorities that * <p>To select the VCN underlying network, the VCN connection will go through all the
* are ordered from most to least preferred, or an empty list to use the default * network candidates and return a network matching the highest priority rule.
* prioritization. The default network prioritization is Opportunistic cellular, Carrier *
* WiFi and Macro cellular * <p>If multiple networks match the same rule, the VCN will prefer an already-selected
* @return * network as opposed to a new/unselected network. However, if both are new/unselected
* networks, a network will be chosen arbitrarily amongst the networks matching the highest
* priority rule.
*
* <p>If all networks fail to match the rules provided, an underlying network will still be
* selected (at random if necessary).
*
* @param underlyingNetworkTemplates a list of unique VcnUnderlyingNetworkTemplates that are
* ordered from most to least preferred, or an empty list to use the default
* prioritization. The default network prioritization order is Opportunistic cellular,
* Carrier WiFi and then Macro cellular.
* @return this {@link Builder} instance, for chaining
*/ */
/** @hide */
@NonNull @NonNull
public Builder setVcnUnderlyingNetworkPriorities( public Builder setVcnUnderlyingNetworkPriorities(
@NonNull LinkedHashSet<VcnUnderlyingNetworkTemplate> underlyingNetworkPriorities) { @NonNull List<VcnUnderlyingNetworkTemplate> underlyingNetworkTemplates) {
Objects.requireNonNull( validateNetworkTemplateList(underlyingNetworkTemplates);
mUnderlyingNetworkPriorities, "underlyingNetworkPriorities is null");
mUnderlyingNetworkPriorities.clear(); mUnderlyingNetworkTemplates.clear();
if (underlyingNetworkPriorities.isEmpty()) { if (underlyingNetworkTemplates.isEmpty()) {
mUnderlyingNetworkPriorities.addAll(DEFAULT_UNDERLYING_NETWORK_PRIORITIES); mUnderlyingNetworkTemplates.addAll(DEFAULT_UNDERLYING_NETWORK_TEMPLATES);
} else { } else {
mUnderlyingNetworkPriorities.addAll(underlyingNetworkPriorities); mUnderlyingNetworkTemplates.addAll(underlyingNetworkTemplates);
} }
return this; return this;
@@ -629,7 +642,7 @@ public final class VcnGatewayConnectionConfig {
mGatewayConnectionName, mGatewayConnectionName,
mTunnelConnectionParams, mTunnelConnectionParams,
mExposedCapabilities, mExposedCapabilities,
mUnderlyingNetworkPriorities, mUnderlyingNetworkTemplates,
mRetryIntervalsMs, mRetryIntervalsMs,
mMaxMtu); mMaxMtu);
} }

View File

@@ -15,6 +15,8 @@
*/ */
package android.net.vcn; package android.net.vcn;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
import static com.android.internal.annotations.VisibleForTesting.Visibility; import static com.android.internal.annotations.VisibleForTesting.Visibility;
import android.annotation.IntDef; import android.annotation.IntDef;
@@ -31,17 +33,24 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.Objects; import java.util.Objects;
// TODO: Add documents /**
/** @hide */ * This class represents a template containing set of underlying network requirements for doing
* route selection.
*
* <p>Apps provisioning a VCN can configure the underlying network priority for each Gateway
* Connection by setting a list (in priority order, most to least preferred) of the appropriate
* subclasses in the VcnGatewayConnectionConfig. See {@link
* VcnGatewayConnectionConfig.Builder#setVcnUnderlyingNetworkPriorities}
*/
public abstract class VcnUnderlyingNetworkTemplate { public abstract class VcnUnderlyingNetworkTemplate {
/** @hide */ /** @hide */
protected static final int NETWORK_PRIORITY_TYPE_WIFI = 1; static final int NETWORK_PRIORITY_TYPE_WIFI = 1;
/** @hide */ /** @hide */
protected static final int NETWORK_PRIORITY_TYPE_CELL = 2; static final int NETWORK_PRIORITY_TYPE_CELL = 2;
/** Denotes that any network quality is acceptable */ /** Denotes that any network quality is acceptable. @hide */
public static final int NETWORK_QUALITY_ANY = 0; public static final int NETWORK_QUALITY_ANY = 0;
/** Denotes that network quality needs to be OK */ /** Denotes that network quality needs to be OK. @hide */
public static final int NETWORK_QUALITY_OK = 100000; public static final int NETWORK_QUALITY_OK = 100000;
private static final SparseArray<String> NETWORK_QUALITY_TO_STRING_MAP = new SparseArray<>(); private static final SparseArray<String> NETWORK_QUALITY_TO_STRING_MAP = new SparseArray<>();
@@ -56,34 +65,82 @@ public abstract class VcnUnderlyingNetworkTemplate {
@IntDef({NETWORK_QUALITY_OK, NETWORK_QUALITY_ANY}) @IntDef({NETWORK_QUALITY_OK, NETWORK_QUALITY_ANY})
public @interface NetworkQuality {} 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
* characteristic are both acceptable to match this template.
*/
public static final int MATCH_ANY = 0;
/**
* Used to configure the matching criteria of a network characteristic. This may include network
* capabilities, or cellular subscription information. Denotes that a network MUST have the
* capability in order to match this template.
*/
public static final int MATCH_REQUIRED = 1;
/**
* Used to configure the matching criteria of a network characteristic. This may include network
* capabilities, or cellular subscription information. Denotes that a network MUST NOT have the
* capability in order to match this template.
*/
public static final int MATCH_FORBIDDEN = 2;
/** @hide */
@Retention(RetentionPolicy.SOURCE)
@IntDef({MATCH_ANY, MATCH_REQUIRED, MATCH_FORBIDDEN})
public @interface MatchCriteria {}
private static final SparseArray<String> MATCH_CRITERIA_TO_STRING_MAP = new SparseArray<>();
static {
MATCH_CRITERIA_TO_STRING_MAP.put(MATCH_ANY, "MATCH_ANY");
MATCH_CRITERIA_TO_STRING_MAP.put(MATCH_REQUIRED, "MATCH_REQUIRED");
MATCH_CRITERIA_TO_STRING_MAP.put(MATCH_FORBIDDEN, "MATCH_FORBIDDEN");
}
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 */ /** @hide */
protected static final String NETWORK_QUALITY_KEY = "mNetworkQuality"; static final String NETWORK_QUALITY_KEY = "mNetworkQuality";
private final int mNetworkQuality; private final int mNetworkQuality;
/** @hide */ /** @hide */
protected static final String ALLOW_METERED_KEY = "mAllowMetered"; static final String METERED_MATCH_KEY = "mMeteredMatchCriteria";
private final boolean mAllowMetered;
private final int mMeteredMatchCriteria;
/** @hide */ /** @hide */
protected VcnUnderlyingNetworkTemplate( VcnUnderlyingNetworkTemplate(
int networkPriorityType, int networkQuality, boolean allowMetered) { int networkPriorityType, int networkQuality, int meteredMatchCriteria) {
mNetworkPriorityType = networkPriorityType; mNetworkPriorityType = networkPriorityType;
mNetworkQuality = networkQuality; mNetworkQuality = networkQuality;
mAllowMetered = allowMetered; mMeteredMatchCriteria = meteredMatchCriteria;
} }
private static void validateNetworkQuality(int networkQuality) { /** @hide */
static void validateNetworkQuality(int networkQuality) {
Preconditions.checkArgument( Preconditions.checkArgument(
networkQuality == NETWORK_QUALITY_ANY || networkQuality == NETWORK_QUALITY_OK, networkQuality == NETWORK_QUALITY_ANY || networkQuality == NETWORK_QUALITY_OK,
"Invalid networkQuality:" + networkQuality); "Invalid networkQuality:" + networkQuality);
} }
/** @hide */
static void validateMatchCriteria(int meteredMatchCriteria, String matchingCapability) {
Preconditions.checkArgument(
MATCH_CRITERIA_TO_STRING_MAP.contains(meteredMatchCriteria),
"Invalid matching criteria: "
+ meteredMatchCriteria
+ " for "
+ matchingCapability);
}
/** @hide */ /** @hide */
protected void validate() { protected void validate() {
validateNetworkQuality(mNetworkQuality); validateNetworkQuality(mNetworkQuality);
validateMatchCriteria(mMeteredMatchCriteria, "mMeteredMatchCriteria");
} }
/** @hide */ /** @hide */
@@ -112,14 +169,14 @@ public abstract class VcnUnderlyingNetworkTemplate {
result.putInt(NETWORK_PRIORITY_TYPE_KEY, mNetworkPriorityType); result.putInt(NETWORK_PRIORITY_TYPE_KEY, mNetworkPriorityType);
result.putInt(NETWORK_QUALITY_KEY, mNetworkQuality); result.putInt(NETWORK_QUALITY_KEY, mNetworkQuality);
result.putBoolean(ALLOW_METERED_KEY, mAllowMetered); result.putInt(METERED_MATCH_KEY, mMeteredMatchCriteria);
return result; return result;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(mNetworkPriorityType, mNetworkQuality, mAllowMetered); return Objects.hash(mNetworkPriorityType, mNetworkQuality, mMeteredMatchCriteria);
} }
@Override @Override
@@ -131,7 +188,17 @@ 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 && mNetworkQuality == rhs.mNetworkQuality
&& mAllowMetered == rhs.mAllowMetered; && mMeteredMatchCriteria == rhs.mMeteredMatchCriteria;
}
/** @hide */
static String getNameString(SparseArray<String> toStringMap, int key) {
return toStringMap.get(key, "Invalid value " + key);
}
/** @hide */
static String getMatchCriteriaString(int meteredMatchCriteria) {
return getNameString(MATCH_CRITERIA_TO_STRING_MAP, meteredMatchCriteria);
} }
/** @hide */ /** @hide */
@@ -148,65 +215,32 @@ public abstract class VcnUnderlyingNetworkTemplate {
pw.println( pw.println(
"mNetworkQuality: " "mNetworkQuality: "
+ NETWORK_QUALITY_TO_STRING_MAP.get( + getNameString(NETWORK_QUALITY_TO_STRING_MAP, mNetworkQuality));
mNetworkQuality, "Invalid value " + mNetworkQuality)); pw.println("mMeteredMatchCriteria: " + getMatchCriteriaString(mMeteredMatchCriteria));
pw.println("mAllowMetered: " + mAllowMetered);
dumpTransportSpecificFields(pw); dumpTransportSpecificFields(pw);
pw.decreaseIndent(); pw.decreaseIndent();
} }
/** Retrieve the required network quality. */ /**
* Retrieve the required network quality to match this template.
*
* @see Builder#setNetworkQuality(int)
* @hide
*/
@NetworkQuality @NetworkQuality
public int getNetworkQuality() { public int getNetworkQuality() {
return mNetworkQuality; return mNetworkQuality;
} }
/** Return if a metered network is allowed. */
public boolean allowMetered() {
return mAllowMetered;
}
/** /**
* This class is used to incrementally build VcnUnderlyingNetworkTemplate objects. * Return the matching criteria for metered networks.
* *
* @param <T> The subclass to be built. * @see VcnWifiUnderlyingNetworkTemplate.Builder#setMetered(int)
* @see VcnCellUnderlyingNetworkTemplate.Builder#setMetered(int)
*/ */
public abstract static class Builder<T extends Builder<T>> { @MatchCriteria
/** @hide */ public int getMetered() {
protected int mNetworkQuality = NETWORK_QUALITY_ANY; return mMeteredMatchCriteria;
/** @hide */
protected boolean mAllowMetered = false;
/** @hide */
protected Builder() {}
/**
* Set the required network quality.
*
* @param networkQuality the required network quality. Defaults to NETWORK_QUALITY_ANY
*/
@NonNull
public T setNetworkQuality(@NetworkQuality int networkQuality) {
validateNetworkQuality(networkQuality);
mNetworkQuality = networkQuality;
return self();
}
/**
* Set if a metered network is allowed.
*
* @param allowMetered the flag to indicate if a metered network is allowed, defaults to
* {@code false}
*/
@NonNull
public T setAllowMetered(boolean allowMetered) {
mAllowMetered = allowMetered;
return self();
}
/** @hide */
abstract T self();
} }
} }

View File

@@ -16,30 +16,58 @@
package android.net.vcn; package android.net.vcn;
import static com.android.internal.annotations.VisibleForTesting.Visibility; import static com.android.internal.annotations.VisibleForTesting.Visibility;
import static com.android.server.vcn.util.PersistableBundleUtils.STRING_DESERIALIZER;
import static com.android.server.vcn.util.PersistableBundleUtils.STRING_SERIALIZER;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.net.NetworkCapabilities;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.util.ArraySet;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IndentingPrintWriter; import com.android.internal.util.IndentingPrintWriter;
import com.android.server.vcn.util.PersistableBundleUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
// TODO: Add documents /**
/** @hide */ * This class represents a configuration for a network template class of underlying Carrier WiFi
* networks.
*
* <p>See {@link VcnUnderlyingNetworkTemplate}
*/
public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetworkTemplate { public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetworkTemplate {
private static final String SSID_KEY = "mSsid"; private static final String SSIDS_KEY = "mSsids";
@Nullable private final String mSsid; @Nullable private final Set<String> mSsids;
private VcnWifiUnderlyingNetworkTemplate( private VcnWifiUnderlyingNetworkTemplate(
int networkQuality, boolean allowMetered, String ssid) { int networkQuality, int meteredMatchCriteria, Set<String> ssids) {
super(NETWORK_PRIORITY_TYPE_WIFI, networkQuality, allowMetered); super(NETWORK_PRIORITY_TYPE_WIFI, networkQuality, meteredMatchCriteria);
mSsid = ssid; mSsids = new ArraySet<>(ssids);
validate(); validate();
} }
/** @hide */
@Override
protected void validate() {
super.validate();
validateSsids(mSsids);
}
private static void validateSsids(Set<String> ssids) {
Objects.requireNonNull(ssids, "ssids is null");
for (String ssid : ssids) {
Objects.requireNonNull(ssid, "found null value ssid");
}
}
/** @hide */ /** @hide */
@NonNull @NonNull
@VisibleForTesting(visibility = Visibility.PROTECTED) @VisibleForTesting(visibility = Visibility.PROTECTED)
@@ -48,9 +76,14 @@ public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
Objects.requireNonNull(in, "PersistableBundle is null"); Objects.requireNonNull(in, "PersistableBundle is null");
final int networkQuality = in.getInt(NETWORK_QUALITY_KEY); final int networkQuality = in.getInt(NETWORK_QUALITY_KEY);
final boolean allowMetered = in.getBoolean(ALLOW_METERED_KEY); final int meteredMatchCriteria = in.getInt(METERED_MATCH_KEY);
final String ssid = in.getString(SSID_KEY);
return new VcnWifiUnderlyingNetworkTemplate(networkQuality, allowMetered, ssid); final PersistableBundle ssidsBundle = in.getPersistableBundle(SSIDS_KEY);
Objects.requireNonNull(ssidsBundle, "ssidsBundle is null");
final Set<String> ssids =
new ArraySet<String>(
PersistableBundleUtils.toList(ssidsBundle, STRING_DESERIALIZER));
return new VcnWifiUnderlyingNetworkTemplate(networkQuality, meteredMatchCriteria, ssids);
} }
/** @hide */ /** @hide */
@@ -59,13 +92,17 @@ public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
@VisibleForTesting(visibility = Visibility.PROTECTED) @VisibleForTesting(visibility = Visibility.PROTECTED)
public PersistableBundle toPersistableBundle() { public PersistableBundle toPersistableBundle() {
final PersistableBundle result = super.toPersistableBundle(); final PersistableBundle result = super.toPersistableBundle();
result.putString(SSID_KEY, mSsid);
final PersistableBundle ssidsBundle =
PersistableBundleUtils.fromList(new ArrayList<>(mSsids), STRING_SERIALIZER);
result.putPersistableBundle(SSIDS_KEY, ssidsBundle);
return result; return result;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(super.hashCode(), mSsid); return Objects.hash(super.hashCode(), mSsids);
} }
@Override @Override
@@ -79,49 +116,95 @@ public final class VcnWifiUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
} }
final VcnWifiUnderlyingNetworkTemplate rhs = (VcnWifiUnderlyingNetworkTemplate) other; final VcnWifiUnderlyingNetworkTemplate rhs = (VcnWifiUnderlyingNetworkTemplate) other;
return mSsid.equals(rhs.mSsid); return mSsids.equals(rhs.mSsids);
} }
/** @hide */ /** @hide */
@Override @Override
void dumpTransportSpecificFields(IndentingPrintWriter pw) { void dumpTransportSpecificFields(IndentingPrintWriter pw) {
pw.println("mSsid: " + mSsid); pw.println("mSsids: " + mSsids);
} }
/** Retrieve the required SSID, or {@code null} if there is no requirement on SSID. */ /**
@Nullable * Retrieve the matching SSIDs, or an empty set if any SSID is acceptable.
public String getSsid() { *
return mSsid; * @see Builder#setSsids(Set)
*/
@NonNull
public Set<String> getSsids() {
return Collections.unmodifiableSet(mSsids);
} }
/** This class is used to incrementally build VcnWifiUnderlyingNetworkTemplate objects. */ /** This class is used to incrementally build VcnWifiUnderlyingNetworkTemplate objects. */
public static class Builder extends VcnUnderlyingNetworkTemplate.Builder<Builder> { public static final class Builder {
@Nullable private String mSsid; private int mNetworkQuality = NETWORK_QUALITY_ANY;
private int mMeteredMatchCriteria = MATCH_ANY;
@NonNull private final Set<String> mSsids = new ArraySet<>();
/** Construct a Builder object. */ /** Construct a Builder object. */
public Builder() {} public Builder() {}
/** /**
* Set the required SSID. * Set the required network quality to match this template.
* *
* @param ssid the required SSID, or {@code null} if any SSID is acceptable. * <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 @NonNull
public Builder setSsid(@Nullable String ssid) { public Builder setNetworkQuality(@NetworkQuality int networkQuality) {
mSsid = ssid; validateNetworkQuality(networkQuality);
mNetworkQuality = networkQuality;
return this;
}
/**
* Set the matching criteria for metered networks.
*
* <p>A template where setMetered(MATCH_REQUIRED) will only match metered networks (one
* without NET_CAPABILITY_NOT_METERED). A template where setMetered(MATCH_FORBIDDEN) will
* only match a network that is not metered (one with NET_CAPABILITY_NOT_METERED).
*
* @param matchCriteria the matching criteria for metered networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_NOT_METERED
*/
// The matching getter is defined in the super class. Please see {@link
// VcnUnderlyingNetworkTemplate#getMetered()}
@SuppressLint("MissingGetterMatchingBuilder")
@NonNull
public Builder setMetered(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setMetered");
mMeteredMatchCriteria = matchCriteria;
return this;
}
/**
* Set the SSIDs with which a network can match this priority rule.
*
* @param ssids the matching SSIDs. Network with one of the matching SSIDs can match this
* priority rule. If the set is empty, any SSID will match. The default is an empty set.
*/
@NonNull
public Builder setSsids(@NonNull Set<String> ssids) {
validateSsids(ssids);
mSsids.clear();
mSsids.addAll(ssids);
return this; return this;
} }
/** Build the VcnWifiUnderlyingNetworkTemplate. */ /** Build the VcnWifiUnderlyingNetworkTemplate. */
@NonNull @NonNull
public VcnWifiUnderlyingNetworkTemplate build() { public VcnWifiUnderlyingNetworkTemplate build() {
return new VcnWifiUnderlyingNetworkTemplate(mNetworkQuality, mAllowMetered, mSsid); return new VcnWifiUnderlyingNetworkTemplate(
} mNetworkQuality, mMeteredMatchCriteria, mSsids);
/** @hide */
@Override
Builder self() {
return this;
} }
} }
} }

View File

@@ -20,6 +20,8 @@ import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_ROAMING;
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
import static android.net.NetworkCapabilities.TRANSPORT_TEST; 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_REQUIRED;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_ANY; import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_ANY;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK; import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK;
@@ -44,7 +46,7 @@ import com.android.internal.annotations.VisibleForTesting.Visibility;
import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot; import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscriptionSnapshot;
import com.android.server.vcn.VcnContext; import com.android.server.vcn.VcnContext;
import java.util.LinkedHashSet; import java.util.List;
import java.util.Set; import java.util.Set;
/** @hide */ /** @hide */
@@ -76,7 +78,7 @@ class NetworkPriorityClassifier {
public static int calculatePriorityClass( public static int calculatePriorityClass(
VcnContext vcnContext, VcnContext vcnContext,
UnderlyingNetworkRecord networkRecord, UnderlyingNetworkRecord networkRecord,
LinkedHashSet<VcnUnderlyingNetworkTemplate> underlyingNetworkPriorities, List<VcnUnderlyingNetworkTemplate> underlyingNetworkTemplates,
ParcelUuid subscriptionGroup, ParcelUuid subscriptionGroup,
TelephonySubscriptionSnapshot snapshot, TelephonySubscriptionSnapshot snapshot,
UnderlyingNetworkRecord currentlySelected, UnderlyingNetworkRecord currentlySelected,
@@ -94,7 +96,7 @@ class NetworkPriorityClassifier {
} }
int priorityIndex = 0; int priorityIndex = 0;
for (VcnUnderlyingNetworkTemplate nwPriority : underlyingNetworkPriorities) { for (VcnUnderlyingNetworkTemplate nwPriority : underlyingNetworkTemplates) {
if (checkMatchesPriorityRule( if (checkMatchesPriorityRule(
vcnContext, vcnContext,
nwPriority, nwPriority,
@@ -122,7 +124,11 @@ class NetworkPriorityClassifier {
// TODO: Check Network Quality reported by metric monitors/probers. // TODO: Check Network Quality reported by metric monitors/probers.
final NetworkCapabilities caps = networkRecord.networkCapabilities; final NetworkCapabilities caps = networkRecord.networkCapabilities;
if (!networkPriority.allowMetered() && !caps.hasCapability(NET_CAPABILITY_NOT_METERED)) {
final int meteredMatch = networkPriority.getMetered();
final boolean isMetered = !caps.hasCapability(NET_CAPABILITY_NOT_METERED);
if (meteredMatch == MATCH_REQUIRED && !isMetered
|| meteredMatch == MATCH_FORBIDDEN && isMetered) {
return false; return false;
} }
@@ -171,7 +177,8 @@ class NetworkPriorityClassifier {
return false; return false;
} }
if (networkPriority.getSsid() != null && networkPriority.getSsid() != caps.getSsid()) { if (!networkPriority.getSsids().isEmpty()
&& !networkPriority.getSsids().contains(caps.getSsid())) {
return false; return false;
} }
@@ -226,26 +233,31 @@ class NetworkPriorityClassifier {
.getSystemService(TelephonyManager.class) .getSystemService(TelephonyManager.class)
.createForSubscriptionId(subId); .createForSubscriptionId(subId);
if (!networkPriority.getAllowedOperatorPlmnIds().isEmpty()) { if (!networkPriority.getOperatorPlmnIds().isEmpty()) {
final String plmnId = subIdSpecificTelephonyMgr.getNetworkOperator(); final String plmnId = subIdSpecificTelephonyMgr.getNetworkOperator();
if (!networkPriority.getAllowedOperatorPlmnIds().contains(plmnId)) { if (!networkPriority.getOperatorPlmnIds().contains(plmnId)) {
return false; return false;
} }
} }
if (!networkPriority.getAllowedSpecificCarrierIds().isEmpty()) { if (!networkPriority.getSimSpecificCarrierIds().isEmpty()) {
final int carrierId = subIdSpecificTelephonyMgr.getSimSpecificCarrierId(); final int carrierId = subIdSpecificTelephonyMgr.getSimSpecificCarrierId();
if (!networkPriority.getAllowedSpecificCarrierIds().contains(carrierId)) { if (!networkPriority.getSimSpecificCarrierIds().contains(carrierId)) {
return false; return false;
} }
} }
if (!networkPriority.allowRoaming() && !caps.hasCapability(NET_CAPABILITY_NOT_ROAMING)) { final int roamingMatch = networkPriority.getRoaming();
final boolean isRoaming = !caps.hasCapability(NET_CAPABILITY_NOT_ROAMING);
if (roamingMatch == MATCH_REQUIRED && !isRoaming
|| roamingMatch == MATCH_FORBIDDEN && isRoaming) {
return false; return false;
} }
if (networkPriority.requireOpportunistic()) { final int opportunisticMatch = networkPriority.getOpportunistic();
if (!isOpportunistic(snapshot, caps.getSubscriptionIds())) { final boolean isOpportunistic = isOpportunistic(snapshot, caps.getSubscriptionIds());
if (opportunisticMatch == MATCH_REQUIRED) {
if (!isOpportunistic) {
return false; return false;
} }
@@ -265,6 +277,8 @@ class NetworkPriorityClassifier {
.contains(SubscriptionManager.getActiveDataSubscriptionId())) { .contains(SubscriptionManager.getActiveDataSubscriptionId())) {
return false; return false;
} }
} else if (opportunisticMatch == MATCH_FORBIDDEN && !isOpportunistic) {
return false;
} }
return true; return true;

View File

@@ -32,7 +32,7 @@ import com.android.server.vcn.TelephonySubscriptionTracker.TelephonySubscription
import com.android.server.vcn.VcnContext; import com.android.server.vcn.VcnContext;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedHashSet; import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
@@ -77,7 +77,7 @@ public class UnderlyingNetworkRecord {
static Comparator<UnderlyingNetworkRecord> getComparator( static Comparator<UnderlyingNetworkRecord> getComparator(
VcnContext vcnContext, VcnContext vcnContext,
LinkedHashSet<VcnUnderlyingNetworkTemplate> underlyingNetworkPriorities, List<VcnUnderlyingNetworkTemplate> underlyingNetworkTemplates,
ParcelUuid subscriptionGroup, ParcelUuid subscriptionGroup,
TelephonySubscriptionSnapshot snapshot, TelephonySubscriptionSnapshot snapshot,
UnderlyingNetworkRecord currentlySelected, UnderlyingNetworkRecord currentlySelected,
@@ -87,7 +87,7 @@ public class UnderlyingNetworkRecord {
NetworkPriorityClassifier.calculatePriorityClass( NetworkPriorityClassifier.calculatePriorityClass(
vcnContext, vcnContext,
left, left,
underlyingNetworkPriorities, underlyingNetworkTemplates,
subscriptionGroup, subscriptionGroup,
snapshot, snapshot,
currentlySelected, currentlySelected,
@@ -96,7 +96,7 @@ public class UnderlyingNetworkRecord {
NetworkPriorityClassifier.calculatePriorityClass( NetworkPriorityClassifier.calculatePriorityClass(
vcnContext, vcnContext,
right, right,
underlyingNetworkPriorities, underlyingNetworkTemplates,
subscriptionGroup, subscriptionGroup,
snapshot, snapshot,
currentlySelected, currentlySelected,
@@ -133,7 +133,7 @@ public class UnderlyingNetworkRecord {
void dump( void dump(
VcnContext vcnContext, VcnContext vcnContext,
IndentingPrintWriter pw, IndentingPrintWriter pw,
LinkedHashSet<VcnUnderlyingNetworkTemplate> underlyingNetworkPriorities, List<VcnUnderlyingNetworkTemplate> underlyingNetworkTemplates,
ParcelUuid subscriptionGroup, ParcelUuid subscriptionGroup,
TelephonySubscriptionSnapshot snapshot, TelephonySubscriptionSnapshot snapshot,
UnderlyingNetworkRecord currentlySelected, UnderlyingNetworkRecord currentlySelected,
@@ -145,7 +145,7 @@ public class UnderlyingNetworkRecord {
NetworkPriorityClassifier.calculatePriorityClass( NetworkPriorityClassifier.calculatePriorityClass(
vcnContext, vcnContext,
this, this,
underlyingNetworkPriorities, underlyingNetworkTemplates,
subscriptionGroup, subscriptionGroup,
snapshot, snapshot,
currentlySelected, currentlySelected,

View File

@@ -15,12 +15,13 @@
*/ */
package android.net.vcn; package android.net.vcn;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
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_ANY;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK; 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.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Test; import org.junit.Test;
@@ -32,26 +33,26 @@ public class VcnCellUnderlyingNetworkTemplateTest {
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 getTestNetworkPriority() { static VcnCellUnderlyingNetworkTemplate getTestNetworkTemplate() {
return new VcnCellUnderlyingNetworkTemplate.Builder() return new VcnCellUnderlyingNetworkTemplate.Builder()
.setNetworkQuality(NETWORK_QUALITY_OK) .setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(true /* allowMetered */) .setMetered(MATCH_FORBIDDEN)
.setAllowedOperatorPlmnIds(ALLOWED_PLMN_IDS) .setOperatorPlmnIds(ALLOWED_PLMN_IDS)
.setAllowedSpecificCarrierIds(ALLOWED_CARRIER_IDS) .setSimSpecificCarrierIds(ALLOWED_CARRIER_IDS)
.setAllowRoaming(true /* allowRoaming */) .setRoaming(MATCH_FORBIDDEN)
.setRequireOpportunistic(true /* requireOpportunistic */) .setOpportunistic(MATCH_REQUIRED)
.build(); .build();
} }
@Test @Test
public void testBuilderAndGetters() { public void testBuilderAndGetters() {
final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkPriority(); final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
assertEquals(NETWORK_QUALITY_OK, networkPriority.getNetworkQuality()); assertEquals(NETWORK_QUALITY_OK, networkPriority.getNetworkQuality());
assertTrue(networkPriority.allowMetered()); assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered());
assertEquals(ALLOWED_PLMN_IDS, networkPriority.getAllowedOperatorPlmnIds()); assertEquals(ALLOWED_PLMN_IDS, networkPriority.getOperatorPlmnIds());
assertEquals(ALLOWED_CARRIER_IDS, networkPriority.getAllowedSpecificCarrierIds()); assertEquals(ALLOWED_CARRIER_IDS, networkPriority.getSimSpecificCarrierIds());
assertTrue(networkPriority.allowRoaming()); assertEquals(MATCH_FORBIDDEN, networkPriority.getRoaming());
assertTrue(networkPriority.requireOpportunistic()); assertEquals(MATCH_REQUIRED, networkPriority.getOpportunistic());
} }
@Test @Test
@@ -59,16 +60,16 @@ public class VcnCellUnderlyingNetworkTemplateTest {
final VcnCellUnderlyingNetworkTemplate networkPriority = final VcnCellUnderlyingNetworkTemplate networkPriority =
new VcnCellUnderlyingNetworkTemplate.Builder().build(); new VcnCellUnderlyingNetworkTemplate.Builder().build();
assertEquals(NETWORK_QUALITY_ANY, networkPriority.getNetworkQuality()); assertEquals(NETWORK_QUALITY_ANY, networkPriority.getNetworkQuality());
assertFalse(networkPriority.allowMetered()); assertEquals(MATCH_ANY, networkPriority.getMetered());
assertEquals(new HashSet<String>(), networkPriority.getAllowedOperatorPlmnIds()); assertEquals(new HashSet<String>(), networkPriority.getOperatorPlmnIds());
assertEquals(new HashSet<Integer>(), networkPriority.getAllowedSpecificCarrierIds()); assertEquals(new HashSet<Integer>(), networkPriority.getSimSpecificCarrierIds());
assertFalse(networkPriority.allowRoaming()); assertEquals(MATCH_ANY, networkPriority.getRoaming());
assertFalse(networkPriority.requireOpportunistic()); assertEquals(MATCH_ANY, networkPriority.getOpportunistic());
} }
@Test @Test
public void testPersistableBundle() { public void testPersistableBundle() {
final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkPriority(); final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
assertEquals( assertEquals(
networkPriority, networkPriority,
VcnUnderlyingNetworkTemplate.fromPersistableBundle( VcnUnderlyingNetworkTemplate.fromPersistableBundle(

View File

@@ -17,8 +17,8 @@
package android.net.vcn; 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.VcnGatewayConnectionConfig.DEFAULT_UNDERLYING_NETWORK_PRIORITIES; import static android.net.vcn.VcnGatewayConnectionConfig.DEFAULT_UNDERLYING_NETWORK_TEMPLATES;
import static android.net.vcn.VcnGatewayConnectionConfig.UNDERLYING_NETWORK_PRIORITIES_KEY; import static android.net.vcn.VcnGatewayConnectionConfig.UNDERLYING_NETWORK_TEMPLATES_KEY;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@@ -40,8 +40,9 @@ import androidx.test.runner.AndroidJUnit4;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashSet; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@RunWith(AndroidJUnit4.class) @RunWith(AndroidJUnit4.class)
@@ -54,17 +55,17 @@ public class VcnGatewayConnectionConfigTest {
}; };
public static final int[] UNDERLYING_CAPS = new int[] {NetworkCapabilities.NET_CAPABILITY_DUN}; public static final int[] UNDERLYING_CAPS = new int[] {NetworkCapabilities.NET_CAPABILITY_DUN};
private static final LinkedHashSet<VcnUnderlyingNetworkTemplate> UNDERLYING_NETWORK_PRIORITIES = private static final List<VcnUnderlyingNetworkTemplate> UNDERLYING_NETWORK_TEMPLATES =
new LinkedHashSet(); new ArrayList();
static { static {
Arrays.sort(EXPOSED_CAPS); Arrays.sort(EXPOSED_CAPS);
Arrays.sort(UNDERLYING_CAPS); Arrays.sort(UNDERLYING_CAPS);
UNDERLYING_NETWORK_PRIORITIES.add( UNDERLYING_NETWORK_TEMPLATES.add(
VcnCellUnderlyingNetworkTemplateTest.getTestNetworkPriority()); VcnCellUnderlyingNetworkTemplateTest.getTestNetworkTemplate());
UNDERLYING_NETWORK_PRIORITIES.add( UNDERLYING_NETWORK_TEMPLATES.add(
VcnWifiUnderlyingNetworkTemplateTest.getTestNetworkPriority()); VcnWifiUnderlyingNetworkTemplateTest.getTestNetworkTemplate());
} }
public static final long[] RETRY_INTERVALS_MS = public static final long[] RETRY_INTERVALS_MS =
@@ -95,7 +96,7 @@ public class VcnGatewayConnectionConfigTest {
// Public for use in VcnGatewayConnectionTest // Public for use in VcnGatewayConnectionTest
public static VcnGatewayConnectionConfig buildTestConfig() { public static VcnGatewayConnectionConfig buildTestConfig() {
final VcnGatewayConnectionConfig.Builder builder = final VcnGatewayConnectionConfig.Builder builder =
newBuilder().setVcnUnderlyingNetworkPriorities(UNDERLYING_NETWORK_PRIORITIES); newBuilder().setVcnUnderlyingNetworkPriorities(UNDERLYING_NETWORK_TEMPLATES);
return buildTestConfigWithExposedCaps(builder, EXPOSED_CAPS); return buildTestConfigWithExposedCaps(builder, EXPOSED_CAPS);
} }
@@ -174,10 +175,10 @@ public class VcnGatewayConnectionConfigTest {
} }
@Test @Test
public void testBuilderRequiresNonNullNetworkPriorities() { public void testBuilderRequiresNonNullNetworkTemplates() {
try { try {
newBuilder().setVcnUnderlyingNetworkPriorities(null); newBuilder().setVcnUnderlyingNetworkPriorities(null);
fail("Expected exception due to invalid underlyingNetworkPriorities"); fail("Expected exception due to invalid underlyingNetworkTemplates");
} catch (NullPointerException e) { } catch (NullPointerException e) {
} }
} }
@@ -219,7 +220,7 @@ public class VcnGatewayConnectionConfigTest {
Arrays.sort(exposedCaps); Arrays.sort(exposedCaps);
assertArrayEquals(EXPOSED_CAPS, exposedCaps); assertArrayEquals(EXPOSED_CAPS, exposedCaps);
assertEquals(UNDERLYING_NETWORK_PRIORITIES, config.getVcnUnderlyingNetworkPriorities()); assertEquals(UNDERLYING_NETWORK_TEMPLATES, config.getVcnUnderlyingNetworkPriorities());
assertEquals(TUNNEL_CONNECTION_PARAMS, config.getTunnelConnectionParams()); assertEquals(TUNNEL_CONNECTION_PARAMS, config.getTunnelConnectionParams());
assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMillis()); assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMillis());
@@ -234,13 +235,13 @@ public class VcnGatewayConnectionConfigTest {
} }
@Test @Test
public void testParsePersistableBundleWithoutVcnUnderlyingNetworkPriorities() { public void testParsePersistableBundleWithoutVcnUnderlyingNetworkTemplates() {
PersistableBundle configBundle = buildTestConfig().toPersistableBundle(); PersistableBundle configBundle = buildTestConfig().toPersistableBundle();
configBundle.putPersistableBundle(UNDERLYING_NETWORK_PRIORITIES_KEY, null); configBundle.putPersistableBundle(UNDERLYING_NETWORK_TEMPLATES_KEY, null);
final VcnGatewayConnectionConfig config = new VcnGatewayConnectionConfig(configBundle); final VcnGatewayConnectionConfig config = new VcnGatewayConnectionConfig(configBundle);
assertEquals( assertEquals(
DEFAULT_UNDERLYING_NETWORK_PRIORITIES, config.getVcnUnderlyingNetworkPriorities()); DEFAULT_UNDERLYING_NETWORK_TEMPLATES, config.getVcnUnderlyingNetworkPriorities());
} }
private static IkeTunnelConnectionParams buildTunnelConnectionParams(String ikePsk) { private static IkeTunnelConnectionParams buildTunnelConnectionParams(String ikePsk) {
@@ -285,39 +286,36 @@ public class VcnGatewayConnectionConfigTest {
assertNotEquals(config, anotherConfig); assertNotEquals(config, anotherConfig);
} }
private static VcnGatewayConnectionConfig buildTestConfigWithVcnUnderlyingNetworkPriorities( private static VcnGatewayConnectionConfig buildTestConfigWithVcnUnderlyingNetworkTemplates(
LinkedHashSet<VcnUnderlyingNetworkTemplate> networkPriorities) { List<VcnUnderlyingNetworkTemplate> networkTemplates) {
return buildTestConfigWithExposedCaps( return buildTestConfigWithExposedCaps(
new VcnGatewayConnectionConfig.Builder( new VcnGatewayConnectionConfig.Builder(
"buildTestConfigWithVcnUnderlyingNetworkPriorities", "buildTestConfigWithVcnUnderlyingNetworkTemplates",
TUNNEL_CONNECTION_PARAMS) TUNNEL_CONNECTION_PARAMS)
.setVcnUnderlyingNetworkPriorities(networkPriorities), .setVcnUnderlyingNetworkPriorities(networkTemplates),
EXPOSED_CAPS); EXPOSED_CAPS);
} }
@Test @Test
public void testVcnUnderlyingNetworkPrioritiesEquality() throws Exception { public void testVcnUnderlyingNetworkTemplatesEquality() throws Exception {
final VcnGatewayConnectionConfig config = final VcnGatewayConnectionConfig config =
buildTestConfigWithVcnUnderlyingNetworkPriorities(UNDERLYING_NETWORK_PRIORITIES); buildTestConfigWithVcnUnderlyingNetworkTemplates(UNDERLYING_NETWORK_TEMPLATES);
final LinkedHashSet<VcnUnderlyingNetworkTemplate> networkPrioritiesEqual = final List<VcnUnderlyingNetworkTemplate> networkTemplatesEqual = new ArrayList();
new LinkedHashSet(); networkTemplatesEqual.add(VcnCellUnderlyingNetworkTemplateTest.getTestNetworkTemplate());
networkPrioritiesEqual.add(VcnCellUnderlyingNetworkTemplateTest.getTestNetworkPriority()); networkTemplatesEqual.add(VcnWifiUnderlyingNetworkTemplateTest.getTestNetworkTemplate());
networkPrioritiesEqual.add(VcnWifiUnderlyingNetworkTemplateTest.getTestNetworkPriority());
final VcnGatewayConnectionConfig configEqual = final VcnGatewayConnectionConfig configEqual =
buildTestConfigWithVcnUnderlyingNetworkPriorities(networkPrioritiesEqual); buildTestConfigWithVcnUnderlyingNetworkTemplates(networkTemplatesEqual);
final LinkedHashSet<VcnUnderlyingNetworkTemplate> networkPrioritiesNotEqual = final List<VcnUnderlyingNetworkTemplate> networkTemplatesNotEqual = new ArrayList();
new LinkedHashSet(); networkTemplatesNotEqual.add(VcnWifiUnderlyingNetworkTemplateTest.getTestNetworkTemplate());
networkPrioritiesNotEqual.add(
VcnWifiUnderlyingNetworkTemplateTest.getTestNetworkPriority());
final VcnGatewayConnectionConfig configNotEqual = final VcnGatewayConnectionConfig configNotEqual =
buildTestConfigWithVcnUnderlyingNetworkPriorities(networkPrioritiesNotEqual); buildTestConfigWithVcnUnderlyingNetworkTemplates(networkTemplatesNotEqual);
assertEquals(UNDERLYING_NETWORK_PRIORITIES, networkPrioritiesEqual); assertEquals(UNDERLYING_NETWORK_TEMPLATES, networkTemplatesEqual);
assertEquals(config, configEqual); assertEquals(config, configEqual);
assertNotEquals(UNDERLYING_NETWORK_PRIORITIES, networkPrioritiesNotEqual); assertNotEquals(UNDERLYING_NETWORK_TEMPLATES, networkTemplatesNotEqual);
assertNotEquals(config, configNotEqual); assertNotEquals(config, configNotEqual);
} }
} }

View File

@@ -15,36 +15,38 @@
*/ */
package android.net.vcn; package android.net.vcn;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
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_ANY;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK; 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.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.junit.Test; import org.junit.Test;
import java.util.Set;
public class VcnWifiUnderlyingNetworkTemplateTest { public class VcnWifiUnderlyingNetworkTemplateTest {
private static final String SSID = "TestWifi"; private static final String SSID = "TestWifi";
private static final int INVALID_NETWORK_QUALITY = -1; private static final int INVALID_NETWORK_QUALITY = -1;
// Package private for use in VcnGatewayConnectionConfigTest // Package private for use in VcnGatewayConnectionConfigTest
static VcnWifiUnderlyingNetworkTemplate getTestNetworkPriority() { static VcnWifiUnderlyingNetworkTemplate getTestNetworkTemplate() {
return new VcnWifiUnderlyingNetworkTemplate.Builder() return new VcnWifiUnderlyingNetworkTemplate.Builder()
.setNetworkQuality(NETWORK_QUALITY_OK) .setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(true /* allowMetered */) .setMetered(MATCH_FORBIDDEN)
.setSsid(SSID) .setSsids(Set.of(SSID))
.build(); .build();
} }
@Test @Test
public void testBuilderAndGetters() { public void testBuilderAndGetters() {
final VcnWifiUnderlyingNetworkTemplate networkPriority = getTestNetworkPriority(); final VcnWifiUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
assertEquals(NETWORK_QUALITY_OK, networkPriority.getNetworkQuality()); assertEquals(NETWORK_QUALITY_OK, networkPriority.getNetworkQuality());
assertTrue(networkPriority.allowMetered()); assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered());
assertEquals(SSID, networkPriority.getSsid()); assertEquals(Set.of(SSID), networkPriority.getSsids());
} }
@Test @Test
@@ -52,8 +54,8 @@ public class VcnWifiUnderlyingNetworkTemplateTest {
final VcnWifiUnderlyingNetworkTemplate networkPriority = final VcnWifiUnderlyingNetworkTemplate networkPriority =
new VcnWifiUnderlyingNetworkTemplate.Builder().build(); new VcnWifiUnderlyingNetworkTemplate.Builder().build();
assertEquals(NETWORK_QUALITY_ANY, networkPriority.getNetworkQuality()); assertEquals(NETWORK_QUALITY_ANY, networkPriority.getNetworkQuality());
assertFalse(networkPriority.allowMetered()); assertEquals(MATCH_ANY, networkPriority.getMetered());
assertNull(SSID, networkPriority.getSsid()); assertTrue(networkPriority.getSsids().isEmpty());
} }
@Test @Test
@@ -68,7 +70,7 @@ public class VcnWifiUnderlyingNetworkTemplateTest {
@Test @Test
public void testPersistableBundle() { public void testPersistableBundle() {
final VcnWifiUnderlyingNetworkTemplate networkPriority = getTestNetworkPriority(); final VcnWifiUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
assertEquals( assertEquals(
networkPriority, networkPriority,
VcnUnderlyingNetworkTemplate.fromPersistableBundle( VcnUnderlyingNetworkTemplate.fromPersistableBundle(

View File

@@ -16,6 +16,8 @@
package com.android.server.vcn.routeselection; package com.android.server.vcn.routeselection;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_FORBIDDEN;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK; import static android.net.vcn.VcnUnderlyingNetworkTemplate.NETWORK_QUALITY_OK;
import static com.android.server.vcn.VcnTestUtils.setupSystemService; import static com.android.server.vcn.VcnTestUtils.setupSystemService;
@@ -145,7 +147,7 @@ public class NetworkPriorityClassifierTest {
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority = final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
new VcnWifiUnderlyingNetworkTemplate.Builder() new VcnWifiUnderlyingNetworkTemplate.Builder()
.setNetworkQuality(NETWORK_QUALITY_OK) .setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(false /* allowMetered */) .setMetered(MATCH_FORBIDDEN)
.build(); .build();
assertFalse( assertFalse(
@@ -164,7 +166,6 @@ public class NetworkPriorityClassifierTest {
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority = final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
new VcnWifiUnderlyingNetworkTemplate.Builder() new VcnWifiUnderlyingNetworkTemplate.Builder()
.setNetworkQuality(NETWORK_QUALITY_OK) .setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(true /* allowMetered */)
.build(); .build();
final UnderlyingNetworkRecord selectedNetworkRecord = final UnderlyingNetworkRecord selectedNetworkRecord =
isSelectedNetwork ? mWifiNetworkRecord : null; isSelectedNetwork ? mWifiNetworkRecord : null;
@@ -214,8 +215,7 @@ public class NetworkPriorityClassifierTest {
final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority = final VcnWifiUnderlyingNetworkTemplate wifiNetworkPriority =
new VcnWifiUnderlyingNetworkTemplate.Builder() new VcnWifiUnderlyingNetworkTemplate.Builder()
.setNetworkQuality(NETWORK_QUALITY_OK) .setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(true /* allowMetered */) .setSsids(Set.of(nwPrioritySsid))
.setSsid(nwPrioritySsid)
.build(); .build();
assertEquals( assertEquals(
@@ -238,10 +238,7 @@ public class NetworkPriorityClassifierTest {
} }
private static VcnCellUnderlyingNetworkTemplate.Builder getCellNetworkPriorityBuilder() { private static VcnCellUnderlyingNetworkTemplate.Builder getCellNetworkPriorityBuilder() {
return new VcnCellUnderlyingNetworkTemplate.Builder() return new VcnCellUnderlyingNetworkTemplate.Builder().setNetworkQuality(NETWORK_QUALITY_OK);
.setNetworkQuality(NETWORK_QUALITY_OK)
.setAllowMetered(true /* allowMetered */)
.setAllowRoaming(true /* allowRoaming */);
} }
@Test @Test
@@ -258,9 +255,7 @@ public class NetworkPriorityClassifierTest {
@Test @Test
public void testMatchOpportunisticCell() { public void testMatchOpportunisticCell() {
final VcnCellUnderlyingNetworkTemplate opportunisticCellNetworkPriority = final VcnCellUnderlyingNetworkTemplate opportunisticCellNetworkPriority =
getCellNetworkPriorityBuilder() getCellNetworkPriorityBuilder().setOpportunistic(MATCH_REQUIRED).build();
.setRequireOpportunistic(true /* requireOpportunistic */)
.build();
when(mSubscriptionSnapshot.isOpportunistic(SUB_ID)).thenReturn(true); when(mSubscriptionSnapshot.isOpportunistic(SUB_ID)).thenReturn(true);
when(mSubscriptionSnapshot.getAllSubIdsInGroup(SUB_GROUP)).thenReturn(new ArraySet<>()); when(mSubscriptionSnapshot.getAllSubIdsInGroup(SUB_GROUP)).thenReturn(new ArraySet<>());
@@ -279,7 +274,7 @@ public class NetworkPriorityClassifierTest {
final String networkPriorityPlmnId = useMatchedPlmnId ? PLMN_ID : PLMN_ID_OTHER; final String networkPriorityPlmnId = useMatchedPlmnId ? PLMN_ID : PLMN_ID_OTHER;
final VcnCellUnderlyingNetworkTemplate networkPriority = final VcnCellUnderlyingNetworkTemplate networkPriority =
getCellNetworkPriorityBuilder() getCellNetworkPriorityBuilder()
.setAllowedOperatorPlmnIds(Set.of(networkPriorityPlmnId)) .setOperatorPlmnIds(Set.of(networkPriorityPlmnId))
.build(); .build();
assertEquals( assertEquals(
@@ -308,7 +303,7 @@ public class NetworkPriorityClassifierTest {
final int networkPriorityCarrierId = useMatchedCarrierId ? CARRIER_ID : CARRIER_ID_OTHER; final int networkPriorityCarrierId = useMatchedCarrierId ? CARRIER_ID : CARRIER_ID_OTHER;
final VcnCellUnderlyingNetworkTemplate networkPriority = final VcnCellUnderlyingNetworkTemplate networkPriority =
getCellNetworkPriorityBuilder() getCellNetworkPriorityBuilder()
.setAllowedSpecificCarrierIds(Set.of(networkPriorityCarrierId)) .setSimSpecificCarrierIds(Set.of(networkPriorityCarrierId))
.build(); .build();
assertEquals( assertEquals(
@@ -336,7 +331,7 @@ public class NetworkPriorityClassifierTest {
@Test @Test
public void testMatchWifiFailWithoutNotRoamingBit() { public void testMatchWifiFailWithoutNotRoamingBit() {
final VcnCellUnderlyingNetworkTemplate networkPriority = final VcnCellUnderlyingNetworkTemplate networkPriority =
getCellNetworkPriorityBuilder().setAllowRoaming(false /* allowRoaming */).build(); getCellNetworkPriorityBuilder().setRoaming(MATCH_FORBIDDEN).build();
assertFalse( assertFalse(
checkMatchesCellPriorityRule( checkMatchesCellPriorityRule(
@@ -353,7 +348,7 @@ public class NetworkPriorityClassifierTest {
calculatePriorityClass( calculatePriorityClass(
mVcnContext, mVcnContext,
networkRecord, networkRecord,
VcnGatewayConnectionConfig.DEFAULT_UNDERLYING_NETWORK_PRIORITIES, VcnGatewayConnectionConfig.DEFAULT_UNDERLYING_NETWORK_TEMPLATES,
SUB_GROUP, SUB_GROUP,
mSubscriptionSnapshot, mSubscriptionSnapshot,
null /* currentlySelected */, null /* currentlySelected */,