Loading core/java/android/net/vcn/VcnGatewayConnectionConfig.java +46 −0 Original line number Diff line number Diff line Loading @@ -16,10 +16,12 @@ package android.net.vcn; 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 com.android.internal.annotations.VisibleForTesting.Visibility; import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; Loading Loading @@ -235,6 +237,9 @@ public final class VcnGatewayConnectionConfig { "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"; @NonNull private final Set<Integer> mGatewayOptions; Loading @@ -247,6 +252,7 @@ public final class VcnGatewayConnectionConfig { @NonNull long[] retryIntervalsMs, @IntRange(from = MIN_MTU_V6) int maxMtu, @NonNull int minUdpPort4500NatTimeoutSeconds, boolean isSafeModeDisabled, @NonNull Set<Integer> gatewayOptions) { mGatewayConnectionName = gatewayConnectionName; mTunnelConnectionParams = tunnelConnectionParams; Loading @@ -255,6 +261,7 @@ public final class VcnGatewayConnectionConfig { mMaxMtu = maxMtu; mMinUdpPort4500NatTimeoutSeconds = minUdpPort4500NatTimeoutSeconds; mGatewayOptions = Collections.unmodifiableSet(new ArraySet(gatewayOptions)); mIsSafeModeDisabled = isSafeModeDisabled; mUnderlyingNetworkTemplates = new ArrayList<>(underlyingNetworkTemplates); if (mUnderlyingNetworkTemplates.isEmpty()) { Loading Loading @@ -317,6 +324,7 @@ public final class VcnGatewayConnectionConfig { in.getInt( MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS_KEY, MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET); mIsSafeModeDisabled = in.getBoolean(IS_SAFE_MODE_DISABLED_KEY); validate(); } Loading Loading @@ -482,6 +490,17 @@ public final class VcnGatewayConnectionConfig { 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. * Loading Loading @@ -528,6 +547,7 @@ public final class VcnGatewayConnectionConfig { result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs); result.putInt(MAX_MTU_KEY, mMaxMtu); result.putInt(MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS_KEY, mMinUdpPort4500NatTimeoutSeconds); result.putBoolean(IS_SAFE_MODE_DISABLED_KEY, mIsSafeModeDisabled); return result; } Loading @@ -542,6 +562,7 @@ public final class VcnGatewayConnectionConfig { Arrays.hashCode(mRetryIntervalsMs), mMaxMtu, mMinUdpPort4500NatTimeoutSeconds, mIsSafeModeDisabled, mGatewayOptions); } Loading @@ -559,6 +580,7 @@ public final class VcnGatewayConnectionConfig { && Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs) && mMaxMtu == rhs.mMaxMtu && mMinUdpPort4500NatTimeoutSeconds == rhs.mMinUdpPort4500NatTimeoutSeconds && mIsSafeModeDisabled == rhs.mIsSafeModeDisabled && mGatewayOptions.equals(rhs.mGatewayOptions); } Loading @@ -577,6 +599,7 @@ public final class VcnGatewayConnectionConfig { @NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS; private int mMaxMtu = DEFAULT_MAX_MTU; private int mMinUdpPort4500NatTimeoutSeconds = MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET; private boolean mIsSafeModeDisabled = false; @NonNull private final Set<Integer> mGatewayOptions = new ArraySet<>(); Loading Loading @@ -788,6 +811,28 @@ public final class VcnGatewayConnectionConfig { 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. * Loading @@ -803,6 +848,7 @@ public final class VcnGatewayConnectionConfig { mRetryIntervalsMs, mMaxMtu, mMinUdpPort4500NatTimeoutSeconds, mIsSafeModeDisabled, mGatewayOptions); } } Loading tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java +40 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,17 @@ public class VcnGatewayConnectionConfigTest { 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( VcnGatewayConnectionConfig.Builder builder, Set<Integer> gatewayOptions, Loading Loading @@ -273,6 +284,7 @@ public class VcnGatewayConnectionConfigTest { assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMillis()); assertEquals(MAX_MTU, config.getMaxMtu()); assertTrue(config.isSafeModeEnabled()); assertFalse( config.hasGatewayOption( Loading @@ -289,6 +301,13 @@ public class VcnGatewayConnectionConfigTest { } } @Test public void testBuilderAndGettersSafeModeDisabled() { final VcnGatewayConnectionConfig config = newBuilderMinimal().enableSafeMode(false).build(); assertFalse(config.isSafeModeEnabled()); } @Test public void testPersistableBundle() { final VcnGatewayConnectionConfig config = buildTestConfig(); Loading @@ -304,6 +323,13 @@ public class VcnGatewayConnectionConfigTest { assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle())); } @Test public void testPersistableBundleSafeModeDisabled() { final VcnGatewayConnectionConfig config = newBuilderMinimal().enableSafeMode(false).build(); assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle())); } @Test public void testParsePersistableBundleWithoutVcnUnderlyingNetworkTemplates() { PersistableBundle configBundle = buildTestConfig().toPersistableBundle(); Loading Loading @@ -411,4 +437,18 @@ public class VcnGatewayConnectionConfigTest { assertEquals(config, configEqual); 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); } } Loading
core/java/android/net/vcn/VcnGatewayConnectionConfig.java +46 −0 Original line number Diff line number Diff line Loading @@ -16,10 +16,12 @@ package android.net.vcn; 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 com.android.internal.annotations.VisibleForTesting.Visibility; import android.annotation.FlaggedApi; import android.annotation.IntDef; import android.annotation.IntRange; import android.annotation.NonNull; Loading Loading @@ -235,6 +237,9 @@ public final class VcnGatewayConnectionConfig { "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"; @NonNull private final Set<Integer> mGatewayOptions; Loading @@ -247,6 +252,7 @@ public final class VcnGatewayConnectionConfig { @NonNull long[] retryIntervalsMs, @IntRange(from = MIN_MTU_V6) int maxMtu, @NonNull int minUdpPort4500NatTimeoutSeconds, boolean isSafeModeDisabled, @NonNull Set<Integer> gatewayOptions) { mGatewayConnectionName = gatewayConnectionName; mTunnelConnectionParams = tunnelConnectionParams; Loading @@ -255,6 +261,7 @@ public final class VcnGatewayConnectionConfig { mMaxMtu = maxMtu; mMinUdpPort4500NatTimeoutSeconds = minUdpPort4500NatTimeoutSeconds; mGatewayOptions = Collections.unmodifiableSet(new ArraySet(gatewayOptions)); mIsSafeModeDisabled = isSafeModeDisabled; mUnderlyingNetworkTemplates = new ArrayList<>(underlyingNetworkTemplates); if (mUnderlyingNetworkTemplates.isEmpty()) { Loading Loading @@ -317,6 +324,7 @@ public final class VcnGatewayConnectionConfig { in.getInt( MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS_KEY, MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET); mIsSafeModeDisabled = in.getBoolean(IS_SAFE_MODE_DISABLED_KEY); validate(); } Loading Loading @@ -482,6 +490,17 @@ public final class VcnGatewayConnectionConfig { 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. * Loading Loading @@ -528,6 +547,7 @@ public final class VcnGatewayConnectionConfig { result.putLongArray(RETRY_INTERVAL_MS_KEY, mRetryIntervalsMs); result.putInt(MAX_MTU_KEY, mMaxMtu); result.putInt(MIN_UDP_PORT_4500_NAT_TIMEOUT_SECONDS_KEY, mMinUdpPort4500NatTimeoutSeconds); result.putBoolean(IS_SAFE_MODE_DISABLED_KEY, mIsSafeModeDisabled); return result; } Loading @@ -542,6 +562,7 @@ public final class VcnGatewayConnectionConfig { Arrays.hashCode(mRetryIntervalsMs), mMaxMtu, mMinUdpPort4500NatTimeoutSeconds, mIsSafeModeDisabled, mGatewayOptions); } Loading @@ -559,6 +580,7 @@ public final class VcnGatewayConnectionConfig { && Arrays.equals(mRetryIntervalsMs, rhs.mRetryIntervalsMs) && mMaxMtu == rhs.mMaxMtu && mMinUdpPort4500NatTimeoutSeconds == rhs.mMinUdpPort4500NatTimeoutSeconds && mIsSafeModeDisabled == rhs.mIsSafeModeDisabled && mGatewayOptions.equals(rhs.mGatewayOptions); } Loading @@ -577,6 +599,7 @@ public final class VcnGatewayConnectionConfig { @NonNull private long[] mRetryIntervalsMs = DEFAULT_RETRY_INTERVALS_MS; private int mMaxMtu = DEFAULT_MAX_MTU; private int mMinUdpPort4500NatTimeoutSeconds = MIN_UDP_PORT_4500_NAT_TIMEOUT_UNSET; private boolean mIsSafeModeDisabled = false; @NonNull private final Set<Integer> mGatewayOptions = new ArraySet<>(); Loading Loading @@ -788,6 +811,28 @@ public final class VcnGatewayConnectionConfig { 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. * Loading @@ -803,6 +848,7 @@ public final class VcnGatewayConnectionConfig { mRetryIntervalsMs, mMaxMtu, mMinUdpPort4500NatTimeoutSeconds, mIsSafeModeDisabled, mGatewayOptions); } } Loading
tests/vcn/java/android/net/vcn/VcnGatewayConnectionConfigTest.java +40 −0 Original line number Diff line number Diff line Loading @@ -125,6 +125,17 @@ public class VcnGatewayConnectionConfigTest { 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( VcnGatewayConnectionConfig.Builder builder, Set<Integer> gatewayOptions, Loading Loading @@ -273,6 +284,7 @@ public class VcnGatewayConnectionConfigTest { assertArrayEquals(RETRY_INTERVALS_MS, config.getRetryIntervalsMillis()); assertEquals(MAX_MTU, config.getMaxMtu()); assertTrue(config.isSafeModeEnabled()); assertFalse( config.hasGatewayOption( Loading @@ -289,6 +301,13 @@ public class VcnGatewayConnectionConfigTest { } } @Test public void testBuilderAndGettersSafeModeDisabled() { final VcnGatewayConnectionConfig config = newBuilderMinimal().enableSafeMode(false).build(); assertFalse(config.isSafeModeEnabled()); } @Test public void testPersistableBundle() { final VcnGatewayConnectionConfig config = buildTestConfig(); Loading @@ -304,6 +323,13 @@ public class VcnGatewayConnectionConfigTest { assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle())); } @Test public void testPersistableBundleSafeModeDisabled() { final VcnGatewayConnectionConfig config = newBuilderMinimal().enableSafeMode(false).build(); assertEquals(config, new VcnGatewayConnectionConfig(config.toPersistableBundle())); } @Test public void testParsePersistableBundleWithoutVcnUnderlyingNetworkTemplates() { PersistableBundle configBundle = buildTestConfig().toPersistableBundle(); Loading Loading @@ -411,4 +437,18 @@ public class VcnGatewayConnectionConfigTest { assertEquals(config, configEqual); 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); } }