Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5741a448 authored by Yan Yan's avatar Yan Yan Committed by Automerger Merge Worker
Browse files

Merge "VCN: Allow restricting TRANSPORT_TEST for CTS" am: dee01562 am:...

Merge "VCN: Allow restricting TRANSPORT_TEST for CTS" am: dee01562 am: 80e6084a am: 4dd2cc29 am: fd6a8541

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2496395



Change-Id: I901721e25d50e50e54d21e34ceb21b430c694e80
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 130cc520 fd6a8541
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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");
            }
        }
    }

+4 −3
Original line number Diff line number Diff line
@@ -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;
+32 −0
Original line number Diff line number Diff line
@@ -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);