Merge changes I3da7afab,I3ed65ae8

* changes:
  APIs to configure capabilities in VCN cell network template
  Support configuring capabilities in VCN cell network template
This commit is contained in:
Yan Yan
2022-12-15 18:26:41 +00:00
committed by Gerrit Code Review
3 changed files with 342 additions and 9 deletions

View File

@@ -27265,8 +27265,14 @@ package android.net.sip {
package android.net.vcn { package android.net.vcn {
public final class VcnCellUnderlyingNetworkTemplate extends android.net.vcn.VcnUnderlyingNetworkTemplate { public final class VcnCellUnderlyingNetworkTemplate extends android.net.vcn.VcnUnderlyingNetworkTemplate {
method public int getCbs();
method public int getDun();
method public int getIms();
method public int getInternet();
method public int getMms();
method @NonNull public java.util.Set<java.lang.String> getOperatorPlmnIds(); method @NonNull public java.util.Set<java.lang.String> getOperatorPlmnIds();
method public int getOpportunistic(); method public int getOpportunistic();
method public int getRcs();
method public int getRoaming(); method public int getRoaming();
method @NonNull public java.util.Set<java.lang.Integer> getSimSpecificCarrierIds(); method @NonNull public java.util.Set<java.lang.Integer> getSimSpecificCarrierIds();
} }
@@ -27274,11 +27280,17 @@ package android.net.vcn {
public static final class VcnCellUnderlyingNetworkTemplate.Builder { public static final class VcnCellUnderlyingNetworkTemplate.Builder {
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 setCbs(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setDun(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setIms(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setInternet(int);
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 setMinDownstreamBandwidthKbps(int, int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMinUpstreamBandwidthKbps(int, int); method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMinUpstreamBandwidthKbps(int, int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setMms(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 setRcs(int);
method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setRoaming(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>); method @NonNull public android.net.vcn.VcnCellUnderlyingNetworkTemplate.Builder setSimSpecificCarrierIds(@NonNull java.util.Set<java.lang.Integer>);
} }

View File

@@ -15,6 +15,12 @@
*/ */
package android.net.vcn; package android.net.vcn;
import static android.net.NetworkCapabilities.NET_CAPABILITY_CBS;
import static android.net.NetworkCapabilities.NET_CAPABILITY_DUN;
import static android.net.NetworkCapabilities.NET_CAPABILITY_IMS;
import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET;
import static android.net.NetworkCapabilities.NET_CAPABILITY_MMS;
import static android.net.NetworkCapabilities.NET_CAPABILITY_RCS;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY; import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_ANY;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.getMatchCriteriaString; import static android.net.vcn.VcnUnderlyingNetworkTemplate.getMatchCriteriaString;
@@ -37,10 +43,13 @@ 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.internal.util.Preconditions;
import com.android.server.vcn.util.PersistableBundleUtils; import com.android.server.vcn.util.PersistableBundleUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@@ -64,6 +73,23 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
private static final int DEFAULT_OPPORTUNISTIC_MATCH_CRITERIA = MATCH_ANY; private static final int DEFAULT_OPPORTUNISTIC_MATCH_CRITERIA = MATCH_ANY;
private final int mOpportunisticMatchCriteria; private final int mOpportunisticMatchCriteria;
private static final String CAPABILITIES_MATCH_CRITERIA_KEY = "mCapabilitiesMatchCriteria";
@NonNull private final Map<Integer, Integer> mCapabilitiesMatchCriteria;
private static final Map<Integer, Integer> CAPABILITIES_MATCH_CRITERIA_DEFAULT;
static {
Map<Integer, Integer> capsMatchCriteria = new HashMap<>();
capsMatchCriteria.put(NET_CAPABILITY_CBS, MATCH_ANY);
capsMatchCriteria.put(NET_CAPABILITY_DUN, MATCH_ANY);
capsMatchCriteria.put(NET_CAPABILITY_IMS, MATCH_ANY);
capsMatchCriteria.put(NET_CAPABILITY_INTERNET, MATCH_REQUIRED);
capsMatchCriteria.put(NET_CAPABILITY_MMS, MATCH_ANY);
capsMatchCriteria.put(NET_CAPABILITY_RCS, MATCH_ANY);
CAPABILITIES_MATCH_CRITERIA_DEFAULT = Collections.unmodifiableMap(capsMatchCriteria);
}
private VcnCellUnderlyingNetworkTemplate( private VcnCellUnderlyingNetworkTemplate(
int meteredMatchCriteria, int meteredMatchCriteria,
int minEntryUpstreamBandwidthKbps, int minEntryUpstreamBandwidthKbps,
@@ -73,7 +99,8 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
Set<String> allowedNetworkPlmnIds, Set<String> allowedNetworkPlmnIds,
Set<Integer> allowedSpecificCarrierIds, Set<Integer> allowedSpecificCarrierIds,
int roamingMatchCriteria, int roamingMatchCriteria,
int opportunisticMatchCriteria) { int opportunisticMatchCriteria,
Map<Integer, Integer> capabilitiesMatchCriteria) {
super( super(
NETWORK_PRIORITY_TYPE_CELL, NETWORK_PRIORITY_TYPE_CELL,
meteredMatchCriteria, meteredMatchCriteria,
@@ -85,6 +112,7 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
mAllowedSpecificCarrierIds = new ArraySet<>(allowedSpecificCarrierIds); mAllowedSpecificCarrierIds = new ArraySet<>(allowedSpecificCarrierIds);
mRoamingMatchCriteria = roamingMatchCriteria; mRoamingMatchCriteria = roamingMatchCriteria;
mOpportunisticMatchCriteria = opportunisticMatchCriteria; mOpportunisticMatchCriteria = opportunisticMatchCriteria;
mCapabilitiesMatchCriteria = new HashMap<>(capabilitiesMatchCriteria);
validate(); validate();
} }
@@ -94,6 +122,7 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
protected void validate() { protected void validate() {
super.validate(); super.validate();
validatePlmnIds(mAllowedNetworkPlmnIds); validatePlmnIds(mAllowedNetworkPlmnIds);
validateCapabilitiesMatchCriteria(mCapabilitiesMatchCriteria);
Objects.requireNonNull(mAllowedSpecificCarrierIds, "matchingCarrierIds is null"); Objects.requireNonNull(mAllowedSpecificCarrierIds, "matchingCarrierIds is null");
validateMatchCriteria(mRoamingMatchCriteria, "mRoamingMatchCriteria"); validateMatchCriteria(mRoamingMatchCriteria, "mRoamingMatchCriteria");
validateMatchCriteria(mOpportunisticMatchCriteria, "mOpportunisticMatchCriteria"); validateMatchCriteria(mOpportunisticMatchCriteria, "mOpportunisticMatchCriteria");
@@ -113,6 +142,28 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
} }
} }
private static void validateCapabilitiesMatchCriteria(
Map<Integer, Integer> capabilitiesMatchCriteria) {
Objects.requireNonNull(capabilitiesMatchCriteria, "capabilitiesMatchCriteria is null");
boolean requiredCapabilityFound = false;
for (Map.Entry<Integer, Integer> entry : capabilitiesMatchCriteria.entrySet()) {
final int capability = entry.getKey();
final int matchCriteria = entry.getValue();
Preconditions.checkArgument(
CAPABILITIES_MATCH_CRITERIA_DEFAULT.containsKey(capability),
"NetworkCapability " + capability + "out of range");
validateMatchCriteria(matchCriteria, "capability " + capability);
requiredCapabilityFound |= (matchCriteria == MATCH_REQUIRED);
}
if (!requiredCapabilityFound) {
throw new IllegalArgumentException("No required capabilities found");
}
}
/** @hide */ /** @hide */
@NonNull @NonNull
@VisibleForTesting(visibility = Visibility.PROTECTED) @VisibleForTesting(visibility = Visibility.PROTECTED)
@@ -146,6 +197,19 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
PersistableBundleUtils.toList( PersistableBundleUtils.toList(
specificCarrierIdsBundle, INTEGER_DESERIALIZER)); specificCarrierIdsBundle, INTEGER_DESERIALIZER));
final PersistableBundle capabilitiesMatchCriteriaBundle =
in.getPersistableBundle(CAPABILITIES_MATCH_CRITERIA_KEY);
final Map<Integer, Integer> capabilitiesMatchCriteria;
if (capabilitiesMatchCriteriaBundle == null) {
capabilitiesMatchCriteria = CAPABILITIES_MATCH_CRITERIA_DEFAULT;
} else {
capabilitiesMatchCriteria =
PersistableBundleUtils.toMap(
capabilitiesMatchCriteriaBundle,
INTEGER_DESERIALIZER,
INTEGER_DESERIALIZER);
}
final int roamingMatchCriteria = in.getInt(ROAMING_MATCH_KEY); final int roamingMatchCriteria = in.getInt(ROAMING_MATCH_KEY);
final int opportunisticMatchCriteria = in.getInt(OPPORTUNISTIC_MATCH_KEY); final int opportunisticMatchCriteria = in.getInt(OPPORTUNISTIC_MATCH_KEY);
@@ -158,7 +222,8 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
allowedNetworkPlmnIds, allowedNetworkPlmnIds,
allowedSpecificCarrierIds, allowedSpecificCarrierIds,
roamingMatchCriteria, roamingMatchCriteria,
opportunisticMatchCriteria); opportunisticMatchCriteria,
capabilitiesMatchCriteria);
} }
/** @hide */ /** @hide */
@@ -178,6 +243,12 @@ 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);
final PersistableBundle capabilitiesMatchCriteriaBundle =
PersistableBundleUtils.fromMap(
mCapabilitiesMatchCriteria, INTEGER_SERIALIZER, INTEGER_SERIALIZER);
result.putPersistableBundle(
CAPABILITIES_MATCH_CRITERIA_KEY, capabilitiesMatchCriteriaBundle);
result.putInt(ROAMING_MATCH_KEY, mRoamingMatchCriteria); result.putInt(ROAMING_MATCH_KEY, mRoamingMatchCriteria);
result.putInt(OPPORTUNISTIC_MATCH_KEY, mOpportunisticMatchCriteria); result.putInt(OPPORTUNISTIC_MATCH_KEY, mOpportunisticMatchCriteria);
@@ -225,12 +296,70 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
return mOpportunisticMatchCriteria; return mOpportunisticMatchCriteria;
} }
/**
* Returns the matching criteria for CBS networks.
*
* @see Builder#setCbs(int)
*/
@MatchCriteria
public int getCbs() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_CBS);
}
/**
* Returns the matching criteria for DUN networks.
*
* @see Builder#setDun(int)
*/
@MatchCriteria
public int getDun() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_DUN);
}
/**
* Returns the matching criteria for IMS networks.
*
* @see Builder#setIms(int)
*/
@MatchCriteria
public int getIms() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_IMS);
}
/**
* Returns the matching criteria for INTERNET networks.
*
* @see Builder#setInternet(int)
*/
@MatchCriteria
public int getInternet() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_INTERNET);
}
/**
* Returns the matching criteria for MMS networks.
*
* @see Builder#setMms(int)
*/
@MatchCriteria
public int getMms() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_MMS);
}
/**
* Returns the matching criteria for RCS networks.
*
* @see Builder#setRcs(int)
*/
@MatchCriteria
public int getRcs() {
return mCapabilitiesMatchCriteria.get(NET_CAPABILITY_RCS);
}
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash( return Objects.hash(
super.hashCode(), super.hashCode(),
mAllowedNetworkPlmnIds, mAllowedNetworkPlmnIds,
mAllowedSpecificCarrierIds, mAllowedSpecificCarrierIds,
mCapabilitiesMatchCriteria,
mRoamingMatchCriteria, mRoamingMatchCriteria,
mOpportunisticMatchCriteria); mOpportunisticMatchCriteria);
} }
@@ -248,6 +377,7 @@ 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)
&& Objects.equals(mCapabilitiesMatchCriteria, rhs.mCapabilitiesMatchCriteria)
&& mRoamingMatchCriteria == rhs.mRoamingMatchCriteria && mRoamingMatchCriteria == rhs.mRoamingMatchCriteria
&& mOpportunisticMatchCriteria == rhs.mOpportunisticMatchCriteria; && mOpportunisticMatchCriteria == rhs.mOpportunisticMatchCriteria;
} }
@@ -261,6 +391,7 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
if (!mAllowedNetworkPlmnIds.isEmpty()) { if (!mAllowedNetworkPlmnIds.isEmpty()) {
pw.println("mAllowedSpecificCarrierIds: " + mAllowedSpecificCarrierIds); pw.println("mAllowedSpecificCarrierIds: " + mAllowedSpecificCarrierIds);
} }
pw.println("mCapabilitiesMatchCriteria: " + mCapabilitiesMatchCriteria);
if (mRoamingMatchCriteria != DEFAULT_ROAMING_MATCH_CRITERIA) { if (mRoamingMatchCriteria != DEFAULT_ROAMING_MATCH_CRITERIA) {
pw.println("mRoamingMatchCriteria: " + getMatchCriteriaString(mRoamingMatchCriteria)); pw.println("mRoamingMatchCriteria: " + getMatchCriteriaString(mRoamingMatchCriteria));
} }
@@ -277,6 +408,7 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
@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<>();
@NonNull private final Map<Integer, Integer> mCapabilitiesMatchCriteria = new HashMap<>();
private int mRoamingMatchCriteria = DEFAULT_ROAMING_MATCH_CRITERIA; private int mRoamingMatchCriteria = DEFAULT_ROAMING_MATCH_CRITERIA;
private int mOpportunisticMatchCriteria = DEFAULT_OPPORTUNISTIC_MATCH_CRITERIA; private int mOpportunisticMatchCriteria = DEFAULT_OPPORTUNISTIC_MATCH_CRITERIA;
@@ -287,7 +419,9 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
private int mMinExitDownstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS; private int mMinExitDownstreamBandwidthKbps = DEFAULT_MIN_BANDWIDTH_KBPS;
/** Construct a Builder object. */ /** Construct a Builder object. */
public Builder() {} public Builder() {
mCapabilitiesMatchCriteria.putAll(CAPABILITIES_MATCH_CRITERIA_DEFAULT);
}
/** /**
* Set the matching criteria for metered networks. * Set the matching criteria for metered networks.
@@ -461,6 +595,126 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
return this; return this;
} }
/**
* Sets the matching criteria for CBS networks.
*
* <p>A template where {@code setCbs(MATCH_REQUIRED)} is called will only match CBS networks
* (ones with NET_CAPABILITY_CBS). A template where {@code setCbs(MATCH_FORBIDDEN)} is
* called will only match networks that do not support CBS (ones without
* NET_CAPABILITY_CBS).
*
* @param matchCriteria the matching criteria for CBS networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_CBS
*/
@NonNull
public Builder setCbs(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setCbs");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_CBS, matchCriteria);
return this;
}
/**
* Sets the matching criteria for DUN networks.
*
* <p>A template where {@code setDun(MATCH_REQUIRED)} is called will only match DUN networks
* (ones with NET_CAPABILITY_DUN). A template where {@code setDun(MATCH_FORBIDDEN)} is
* called will only match networks that do not support DUN (ones without
* NET_CAPABILITY_DUN).
*
* @param matchCriteria the matching criteria for DUN networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_DUN
*/
@NonNull
public Builder setDun(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setDun");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_DUN, matchCriteria);
return this;
}
/**
* Sets the matching criteria for IMS networks.
*
* <p>A template where {@code setIms(MATCH_REQUIRED)} is called will only match IMS networks
* (ones with NET_CAPABILITY_IMS). A template where {@code setIms(MATCH_FORBIDDEN)} is
* called will only match networks that do not support IMS (ones without
* NET_CAPABILITY_IMS).
*
* @param matchCriteria the matching criteria for IMS networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_IMS
*/
@NonNull
public Builder setIms(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setIms");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_IMS, matchCriteria);
return this;
}
/**
* Sets the matching criteria for INTERNET networks.
*
* <p>A template where {@code setInternet(MATCH_REQUIRED)} is called will only match
* INTERNET networks (ones with NET_CAPABILITY_INTERNET). A template where {@code
* setInternet(MATCH_FORBIDDEN)} is called will only match networks that do not support
* INTERNET (ones without NET_CAPABILITY_INTERNET).
*
* @param matchCriteria the matching criteria for INTERNET networks. Defaults to {@link
* #MATCH_REQUIRED}.
* @see NetworkCapabilities#NET_CAPABILITY_INTERNET
*/
@NonNull
public Builder setInternet(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setInternet");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_INTERNET, matchCriteria);
return this;
}
/**
* Sets the matching criteria for MMS networks.
*
* <p>A template where {@code setMms(MATCH_REQUIRED)} is called will only match MMS networks
* (ones with NET_CAPABILITY_MMS). A template where {@code setMms(MATCH_FORBIDDEN)} is
* called will only match networks that do not support MMS (ones without
* NET_CAPABILITY_MMS).
*
* @param matchCriteria the matching criteria for MMS networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_MMS
*/
@NonNull
public Builder setMms(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setMms");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_MMS, matchCriteria);
return this;
}
/**
* Sets the matching criteria for RCS networks.
*
* <p>A template where {@code setRcs(MATCH_REQUIRED)} is called will only match RCS networks
* (ones with NET_CAPABILITY_RCS). A template where {@code setRcs(MATCH_FORBIDDEN)} is
* called will only match networks that do not support RCS (ones without
* NET_CAPABILITY_RCS).
*
* @param matchCriteria the matching criteria for RCS networks. Defaults to {@link
* #MATCH_ANY}.
* @see NetworkCapabilities#NET_CAPABILITY_RCS
*/
@NonNull
public Builder setRcs(@MatchCriteria int matchCriteria) {
validateMatchCriteria(matchCriteria, "setRcs");
mCapabilitiesMatchCriteria.put(NET_CAPABILITY_RCS, matchCriteria);
return this;
}
/** Build the VcnCellUnderlyingNetworkTemplate. */ /** Build the VcnCellUnderlyingNetworkTemplate. */
@NonNull @NonNull
public VcnCellUnderlyingNetworkTemplate build() { public VcnCellUnderlyingNetworkTemplate build() {
@@ -473,7 +727,8 @@ public final class VcnCellUnderlyingNetworkTemplate extends VcnUnderlyingNetwork
mAllowedNetworkPlmnIds, mAllowedNetworkPlmnIds,
mAllowedSpecificCarrierIds, mAllowedSpecificCarrierIds,
mRoamingMatchCriteria, mRoamingMatchCriteria,
mOpportunisticMatchCriteria); mOpportunisticMatchCriteria,
mCapabilitiesMatchCriteria);
} }
} }
} }

View File

@@ -20,6 +20,7 @@ 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 org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.junit.Test; import org.junit.Test;
@@ -31,8 +32,7 @@ public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTe
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 private static VcnCellUnderlyingNetworkTemplate.Builder getTestNetworkTemplateBuilder() {
static VcnCellUnderlyingNetworkTemplate getTestNetworkTemplate() {
return new VcnCellUnderlyingNetworkTemplate.Builder() return new VcnCellUnderlyingNetworkTemplate.Builder()
.setMetered(MATCH_FORBIDDEN) .setMetered(MATCH_FORBIDDEN)
.setMinUpstreamBandwidthKbps( .setMinUpstreamBandwidthKbps(
@@ -44,13 +44,44 @@ public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTe
.setOperatorPlmnIds(ALLOWED_PLMN_IDS) .setOperatorPlmnIds(ALLOWED_PLMN_IDS)
.setSimSpecificCarrierIds(ALLOWED_CARRIER_IDS) .setSimSpecificCarrierIds(ALLOWED_CARRIER_IDS)
.setRoaming(MATCH_FORBIDDEN) .setRoaming(MATCH_FORBIDDEN)
.setOpportunistic(MATCH_REQUIRED) .setOpportunistic(MATCH_REQUIRED);
.build(); }
// Package private for use in VcnGatewayConnectionConfigTest
static VcnCellUnderlyingNetworkTemplate getTestNetworkTemplate() {
return getTestNetworkTemplateBuilder().build();
}
private void setAllCapabilities(
VcnCellUnderlyingNetworkTemplate.Builder builder, int matchCriteria) {
builder.setCbs(matchCriteria);
builder.setDun(matchCriteria);
builder.setIms(matchCriteria);
builder.setInternet(matchCriteria);
builder.setMms(matchCriteria);
builder.setRcs(matchCriteria);
}
private void verifyAllCapabilities(
VcnCellUnderlyingNetworkTemplate template,
int expectMatchCriteriaforNonInternet,
int expectMatchCriteriaforInternet) {
assertEquals(expectMatchCriteriaforNonInternet, template.getCbs());
assertEquals(expectMatchCriteriaforNonInternet, template.getDun());
assertEquals(expectMatchCriteriaforNonInternet, template.getIms());
assertEquals(expectMatchCriteriaforNonInternet, template.getMms());
assertEquals(expectMatchCriteriaforNonInternet, template.getRcs());
assertEquals(expectMatchCriteriaforInternet, template.getInternet());
} }
@Test @Test
public void testBuilderAndGetters() { public void testBuilderAndGetters() {
final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate(); final VcnCellUnderlyingNetworkTemplate.Builder builder = getTestNetworkTemplateBuilder();
setAllCapabilities(builder, MATCH_REQUIRED);
final VcnCellUnderlyingNetworkTemplate networkPriority = builder.build();
assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered()); assertEquals(MATCH_FORBIDDEN, networkPriority.getMetered());
assertEquals( assertEquals(
TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS, TEST_MIN_ENTRY_UPSTREAM_BANDWIDTH_KBPS,
@@ -68,6 +99,8 @@ public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTe
assertEquals(ALLOWED_CARRIER_IDS, networkPriority.getSimSpecificCarrierIds()); assertEquals(ALLOWED_CARRIER_IDS, networkPriority.getSimSpecificCarrierIds());
assertEquals(MATCH_FORBIDDEN, networkPriority.getRoaming()); assertEquals(MATCH_FORBIDDEN, networkPriority.getRoaming());
assertEquals(MATCH_REQUIRED, networkPriority.getOpportunistic()); assertEquals(MATCH_REQUIRED, networkPriority.getOpportunistic());
verifyAllCapabilities(networkPriority, MATCH_REQUIRED, MATCH_REQUIRED);
} }
@Test @Test
@@ -86,6 +119,8 @@ public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTe
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());
verifyAllCapabilities(networkPriority, MATCH_ANY, MATCH_REQUIRED);
} }
@Test @Test
@@ -111,6 +146,25 @@ public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTe
} }
} }
@Test
public void testBuildFailWithoutRequiredCapabilities() {
try {
new VcnCellUnderlyingNetworkTemplate.Builder().setInternet(MATCH_ANY).build();
fail("Expected IAE for missing required capabilities");
} catch (IllegalArgumentException expected) {
}
}
@Test
public void testEqualsWithDifferentCapabilities() {
final VcnCellUnderlyingNetworkTemplate left =
new VcnCellUnderlyingNetworkTemplate.Builder().setDun(MATCH_REQUIRED).build();
final VcnCellUnderlyingNetworkTemplate right =
new VcnCellUnderlyingNetworkTemplate.Builder().setMms(MATCH_REQUIRED).build();
assertNotEquals(left, right);
}
@Test @Test
public void testPersistableBundle() { public void testPersistableBundle() {
final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate(); final VcnCellUnderlyingNetworkTemplate networkPriority = getTestNetworkTemplate();
@@ -119,4 +173,16 @@ public class VcnCellUnderlyingNetworkTemplateTest extends VcnUnderlyingNetworkTe
VcnUnderlyingNetworkTemplate.fromPersistableBundle( VcnUnderlyingNetworkTemplate.fromPersistableBundle(
networkPriority.toPersistableBundle())); networkPriority.toPersistableBundle()));
} }
@Test
public void testPersistableBundleWithCapabilities() {
final VcnCellUnderlyingNetworkTemplate.Builder builder = getTestNetworkTemplateBuilder();
setAllCapabilities(builder, MATCH_REQUIRED);
final VcnCellUnderlyingNetworkTemplate networkPriority = builder.build();
assertEquals(
networkPriority,
VcnUnderlyingNetworkTemplate.fromPersistableBundle(
networkPriority.toPersistableBundle()));
}
} }