Merge "VCN: Allow restricting TRANSPORT_TEST for CTS"
This commit is contained in:
commit
dee01562d0
@ -16,6 +16,7 @@
|
||||
package android.net.vcn;
|
||||
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_TEST;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
|
||||
import static com.android.internal.annotations.VisibleForTesting.Visibility;
|
||||
@ -75,6 +76,7 @@ public final class VcnConfig implements Parcelable {
|
||||
static {
|
||||
ALLOWED_TRANSPORTS.add(TRANSPORT_WIFI);
|
||||
ALLOWED_TRANSPORTS.add(TRANSPORT_CELLULAR);
|
||||
ALLOWED_TRANSPORTS.add(TRANSPORT_TEST);
|
||||
}
|
||||
|
||||
private static final String PACKAGE_NAME_KEY = "mPackageName";
|
||||
@ -155,6 +157,11 @@ public final class VcnConfig implements Parcelable {
|
||||
+ transport
|
||||
+ " which might be from a new version of VcnConfig");
|
||||
}
|
||||
|
||||
if (transport == TRANSPORT_TEST && !mIsTestModeProfile) {
|
||||
throw new IllegalArgumentException(
|
||||
"Found TRANSPORT_TEST in a non-test-mode profile");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1074,9 +1074,10 @@ public class VcnManagementService extends IVcnManagementService.Stub {
|
||||
subGrp, mLastSnapshot, mConfigs.get(subGrp));
|
||||
for (int restrictedTransport : restrictedTransports) {
|
||||
if (ncCopy.hasTransport(restrictedTransport)) {
|
||||
if (restrictedTransport == TRANSPORT_CELLULAR) {
|
||||
// Only make a cell network as restricted when the VCN is in
|
||||
// active mode.
|
||||
if (restrictedTransport == TRANSPORT_CELLULAR
|
||||
|| restrictedTransport == TRANSPORT_TEST) {
|
||||
// For cell or test network, only mark it as restricted when
|
||||
// the VCN is in active mode.
|
||||
isRestricted |= (vcn.getStatus() == VCN_STATUS_CODE_ACTIVE);
|
||||
} else {
|
||||
isRestricted = true;
|
||||
|
@ -17,6 +17,7 @@
|
||||
package android.net.vcn;
|
||||
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_TEST;
|
||||
import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -160,6 +161,37 @@ public class VcnConfigTest {
|
||||
assertNotEquals(config, configNotEqual);
|
||||
}
|
||||
|
||||
private VcnConfig buildConfigRestrictTransportTest(boolean isTestMode) throws Exception {
|
||||
VcnConfig.Builder builder =
|
||||
new VcnConfig.Builder(mContext)
|
||||
.setRestrictedUnderlyingNetworkTransports(Set.of(TRANSPORT_TEST));
|
||||
if (isTestMode) {
|
||||
builder.setIsTestModeProfile();
|
||||
}
|
||||
|
||||
for (VcnGatewayConnectionConfig gatewayConnectionConfig : GATEWAY_CONNECTION_CONFIGS) {
|
||||
builder.addGatewayConnectionConfig(gatewayConnectionConfig);
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestrictTransportTestInTestModeProfile() throws Exception {
|
||||
final VcnConfig config = buildConfigRestrictTransportTest(true /* isTestMode */);
|
||||
assertEquals(Set.of(TRANSPORT_TEST), config.getRestrictedUnderlyingNetworkTransports());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestrictTransportTestInNonTestModeProfile() throws Exception {
|
||||
try {
|
||||
buildConfigRestrictTransportTest(false /* isTestMode */);
|
||||
fail("Expected exception because the config is not a test mode profile");
|
||||
} catch (Exception expected) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParceling() {
|
||||
final VcnConfig config = buildTestConfig(mContext);
|
||||
|
Loading…
x
Reference in New Issue
Block a user