VCN: Allow restricting TRANSPORT_TEST for CTS
This commit updates VCN to be able to mark a test network as restricted. Additionally, when VCN is in safe mode, VCN will delegate to the Android system to decide the restriction policy of the test network. This commit allows CTS to verify VCN's ability of restricting networks based on the transport type. Bug: 263415068 Test: atest VcnManagerTest (new tests) Change-Id: I5fe0be4ce445a4d9c20cbef5ee4a2eb55403b3c8
This commit is contained in:
parent
47300d9e09
commit
653a8e6abe
@ -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