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

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

Merge "Add setter/getter to disable VCN safe mode" into main am: 9df48db6 am: 2f9a235b

parents 39fdcb1d 2f9a235b
Loading
Loading
Loading
Loading
+46 −0
Original line number Original line Diff line number Diff line
@@ -16,10 +16,12 @@
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.Flags.FLAG_SAFE_MODE_CONFIG;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;
import static android.net.vcn.VcnUnderlyingNetworkTemplate.MATCH_REQUIRED;


import static com.android.internal.annotations.VisibleForTesting.Visibility;
import static com.android.internal.annotations.VisibleForTesting.Visibility;


import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.NonNull;
@@ -235,6 +237,9 @@ public final class VcnGatewayConnectionConfig {
            "mMinUdpPort4500NatTimeoutSeconds";
            "mMinUdpPort4500NatTimeoutSeconds";
    private final int mMinUdpPort4500NatTimeoutSeconds;
    private final int mMinUdpPort4500NatTimeoutSeconds;


    private static final String IS_SAFE_MODE_DISABLED_KEY = "mIsSafeModeDisabled";
    private final boolean mIsSafeModeDisabled;

    private static final String GATEWAY_OPTIONS_KEY = "mGatewayOptions";
    private static final String GATEWAY_OPTIONS_KEY = "mGatewayOptions";
    @NonNull private final Set<Integer> mGatewayOptions;
    @NonNull private final Set<Integer> mGatewayOptions;


@@ -247,6 +252,7 @@ public final class VcnGatewayConnectionConfig {
            @NonNull long[] retryIntervalsMs,
            @NonNull long[] retryIntervalsMs,
            @IntRange(from = MIN_MTU_V6) int maxMtu,
            @IntRange(from = MIN_MTU_V6) int maxMtu,
            @NonNull int minUdpPort4500NatTimeoutSeconds,
            @NonNull int minUdpPort4500NatTimeoutSeconds,
            boolean isSafeModeDisabled,
            @NonNull Set<Integer> gatewayOptions) {
            @NonNull Set<Integer> gatewayOptions) {
        mGatewayConnectionName = gatewayConnectionName;
        mGatewayConnectionName = gatewayConnectionName;
        mTunnelConnectionParams = tunnelConnectionParams;
        mTunnelConnectionParams = tunnelConnectionParams;
@@ -255,6 +261,7 @@ public final class VcnGatewayConnectionConfig {
        mMaxMtu = maxMtu;
        mMaxMtu = maxMtu;
        mMinUdpPort4500NatTimeoutSeconds = minUdpPort4500NatTimeoutSeconds;
        mMinUdpPort4500NatTimeoutSeconds = minUdpPort4500NatTimeoutSeconds;
        mGatewayOptions = Collections.unmodifiableSet(new ArraySet(gatewayOptions));
        mGatewayOptions = Collections.unmodifiableSet(new ArraySet(gatewayOptions));
        mIsSafeModeDisabled = isSafeModeDisabled;


        mUnderlyingNetworkTemplates = new ArrayList<>(underlyingNetworkTemplates);
        mUnderlyingNetworkTemplates = new ArrayList<>(underlyingNetworkTemplates);
        if (mUnderlyingNetworkTemplates.isEmpty()) {
        if (mUnderlyingNetworkTemplates.isEmpty()) {
@@ -317,6 +324,7 @@ public final class VcnGatewayConnectionConfig {
                in.getInt(
                in.getInt(
                        MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS_KEY,
                        MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS_KEY,
                        MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET);
                        MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET);
        mIsSafeModeDisabled = in.getBoolean(IS_SAFE_MODE_DISABLED_KEY);


        validate();
        validate();
    }
    }
@@ -482,6 +490,17 @@ public final class VcnGatewayConnectionConfig {
        return mMinUdpPort4500NatTimeoutSeconds;
        return mMinUdpPort4500NatTimeoutSeconds;
    }
    }


    /**
     * Check whether safe mode is enabled
     *
     * @see Builder#enableSafeMode(boolean)
     * @hide
     */
    @FlaggedApi(FLAG_SAFE_MODE_CONFIG)
    public boolean isSafeModeEnabled() {
        return !mIsSafeModeDisabled;
    }

    /**
    /**
     * Checks if the given VCN gateway option is enabled.
     * Checks if the given VCN gateway option is enabled.
     *
     *
@@ -528,6 +547,7 @@ public final class VcnGatewayConnectionConfig {
        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);
        result.putInt(MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS_KEY, mMinUdpPort4500NatTimeoutSeconds);
        result.putInt(MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS_KEY, mMinUdpPort4500NatTimeoutSeconds);
        result.putBoolean(IS_SAFE_MODE_DISABLED_KEY, mIsSafeModeDisabled);


        return result;
        return result;
    }
    }
@@ -542,6 +562,7 @@ public final class VcnGatewayConnectionConfig {
                Arrays.hashCode(mRetryIntervalsMs),
                Arrays.hashCode(mRetryIntervalsMs),
                mMaxMtu,
                mMaxMtu,
                mMinUdpPort4500NatTimeoutSeconds,
                mMinUdpPort4500NatTimeoutSeconds,
                mIsSafeModeDisabled,
                mGatewayOptions);
                mGatewayOptions);
    }
    }


@@ -559,6 +580,7 @@ public final class VcnGatewayConnectionConfig {
                && Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs)
                && Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs)
                && mMaxMtu == rhs.mMaxMtu
                && mMaxMtu == rhs.mMaxMtu
                && mMinUdpPort4500NatTimeoutSeconds == rhs.mMinUdpPort4500NatTimeoutSeconds
                && mMinUdpPort4500NatTimeoutSeconds == rhs.mMinUdpPort4500NatTimeoutSeconds
                && mIsSafeModeDisabled == rhs.mIsSafeModeDisabled
                && mGatewayOptions.equals(rhs.mGatewayOptions);
                && mGatewayOptions.equals(rhs.mGatewayOptions);
    }
    }


@@ -577,6 +599,7 @@ public final class VcnGatewayConnectionConfig {
        @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;
        private int mMinUdpPort4500NatTimeoutSeconds = MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET;
        private int mMinUdpPort4500NatTimeoutSeconds = MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET;
        private boolean mIsSafeModeDisabled = false;


        @NonNull private final Set<Integer> mGatewayOptions = new ArraySet<>();
        @NonNull private final Set<Integer> mGatewayOptions = new ArraySet<>();


@@ -788,6 +811,28 @@ public final class VcnGatewayConnectionConfig {
            return this;
            return this;
        }
        }


        /**
         * Enable/disable safe mode
         *
         * <p>If a VCN fails to provide connectivity within a system-provided timeout, it will enter
         * safe mode. In safe mode, the VCN Network will be torn down and the system will restore
         * connectivity by allowing underlying cellular networks to be used as default. At the same
         * time, VCN will continue to retry until it succeeds.
         *
         * <p>When safe mode is disabled and VCN connection fails to provide connectivity, end users
         * might not have connectivity, and may not have access to carrier-owned underlying
         * networks.
         *
         * @param enabled whether safe mode should be enabled. Defaults to {@code true}
         * @hide
         */
        @FlaggedApi(FLAG_SAFE_MODE_CONFIG)
        @NonNull
        public Builder enableSafeMode(boolean enabled) {
            mIsSafeModeDisabled = !enabled;
            return this;
        }

        /**
        /**
         * Builds and validates the VcnGatewayConnectionConfig.
         * Builds and validates the VcnGatewayConnectionConfig.
         *
         *
@@ -803,6 +848,7 @@ public final class VcnGatewayConnectionConfig {
                    mRetryIntervalsMs,
                    mRetryIntervalsMs,
                    mMaxMtu,
                    mMaxMtu,
                    mMinUdpPort4500NatTimeoutSeconds,
                    mMinUdpPort4500NatTimeoutSeconds,
                    mIsSafeModeDisabled,
                    mGatewayOptions);
                    mGatewayOptions);
        }
        }
    }
    }
+40 −0
Original line number Original line Diff line number Diff line
@@ -125,6 +125,17 @@ public class VcnGatewayConnectionConfigTest {
                TUNNEL_CONNECTION_PARAMS);
                TUNNEL_CONNECTION_PARAMS);
    }
    }


    private static VcnGatewayConnectionConfig.Builder newBuilderMinimal() {
        final VcnGatewayConnectionConfig.Builder builder =
                new VcnGatewayConnectionConfig.Builder(
                        "newBuilderMinimal", TUNNEL_CONNECTION_PARAMS);
        for (int caps : EXPOSED_CAPS) {
            builder.addExposedCapability(caps);
        }

        return builder;
    }

    private static VcnGatewayConnectionConfig buildTestConfigWithExposedCapsAndOptions(
    private static VcnGatewayConnectionConfig buildTestConfigWithExposedCapsAndOptions(
            VcnGatewayConnectionConfig.Builder builder,
            VcnGatewayConnectionConfig.Builder builder,
            Set<Integer> gatewayOptions,
            Set<Integer> gatewayOptions,
@@ -273,6 +284,7 @@ public class VcnGatewayConnectionConfigTest {


        assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMillis());
        assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMillis());
        assertEquals(MAX_MTU, config.getMaxMtu());
        assertEquals(MAX_MTU, config.getMaxMtu());
        assertTrue(config.isSafeModeEnabled());


        assertFalse(
        assertFalse(
                config.hasGatewayOption(
                config.hasGatewayOption(
@@ -289,6 +301,13 @@ public class VcnGatewayConnectionConfigTest {
        }
        }
    }
    }


    @Test
    public void testBuilderAndGettersSafeModeDisabled() {
        final VcnGatewayConnectionConfig config = newBuilderMinimal().enableSafeMode(false).build();

        assertFalse(config.isSafeModeEnabled());
    }

    @Test
    @Test
    public void testPersistableBundle() {
    public void testPersistableBundle() {
        final VcnGatewayConnectionConfig config = buildTestConfig();
        final VcnGatewayConnectionConfig config = buildTestConfig();
@@ -304,6 +323,13 @@ public class VcnGatewayConnectionConfigTest {
        assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle()));
        assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle()));
    }
    }


    @Test
    public void testPersistableBundleSafeModeDisabled() {
        final VcnGatewayConnectionConfig config = newBuilderMinimal().enableSafeMode(false).build();

        assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle()));
    }

    @Test
    @Test
    public void testParsePersistableBundleWithoutVcnUnderlyingNetworkTemplates() {
    public void testParsePersistableBundleWithoutVcnUnderlyingNetworkTemplates() {
        PersistableBundle configBundle = buildTestConfig().toPersistableBundle();
        PersistableBundle configBundle = buildTestConfig().toPersistableBundle();
@@ -411,4 +437,18 @@ public class VcnGatewayConnectionConfigTest {
        assertEquals(config, configEqual);
        assertEquals(config, configEqual);
        assertNotEquals(config, configNotEqual);
        assertNotEquals(config, configNotEqual);
    }
    }

    @Test
    public void testSafeModeEnableDisableEquality() throws Exception {
        final VcnGatewayConnectionConfig config = newBuilderMinimal().build();
        final VcnGatewayConnectionConfig configEqual = newBuilderMinimal().build();

        assertEquals(config.isSafeModeEnabled(), configEqual.isSafeModeEnabled());

        final VcnGatewayConnectionConfig configNotEqual =
                newBuilderMinimal().enableSafeMode(false).build();

        assertEquals(config, configEqual);
        assertNotEquals(config, configNotEqual);
    }
}
}