diff --git a/staticlibs/device/com/android/net/module/util/DeviceConfigUtils.java b/staticlibs/device/com/android/net/module/util/DeviceConfigUtils.java index 04ce2fab50..d9528b94b2 100644 --- a/staticlibs/device/com/android/net/module/util/DeviceConfigUtils.java +++ b/staticlibs/device/com/android/net/module/util/DeviceConfigUtils.java @@ -229,6 +229,24 @@ public final class DeviceConfigUtils { () -> getPackageVersion(context)); } + /** + * Check whether one specific experimental feature in CaptivePortalLogin module from + * {@link DeviceConfig} is not disabled. + * If the feature is enabled by default and disabled by flag push (kill switch), this method + * should be used. + * If the feature is disabled by default and enabled by flag push, + * {@link #isCaptivePortalLoginFeatureEnabled(Context, String)} should be used. + * + * @param context The global context information about an app environment. + * @param name The name of the property in CaptivePortalLogin module to look up. + * @return true if this feature is enabled, or false if disabled. + */ + public static boolean isCaptivePortalLoginFeatureNotChickenedOut(@NonNull Context context, + @NonNull String name) { + return isFeatureEnabled(NAMESPACE_CAPTIVEPORTALLOGIN, name, true /* defaultEnabled */, + () -> getPackageVersion(context)); + } + private static boolean isFeatureEnabled(@NonNull String namespace, String name, boolean defaultEnabled, Supplier packageVersionSupplier) { final int flagValue = getDeviceConfigPropertyInt(namespace, name, 0 /* default value */); diff --git a/staticlibs/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java b/staticlibs/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java index a5af09b3d7..d5bc582abc 100644 --- a/staticlibs/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java +++ b/staticlibs/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java @@ -536,10 +536,14 @@ public class DeviceConfigUtilsTest { TEST_EXPERIMENT_FLAG)); doReturn(TEST_FLAG_VALUE_STRING).when(() -> DeviceConfig.getProperty(NAMESPACE_TETHERING, TEST_EXPERIMENT_FLAG)); + doReturn(TEST_FLAG_VALUE_STRING).when(() -> DeviceConfig.getProperty( + NAMESPACE_CAPTIVEPORTALLOGIN, TEST_EXPERIMENT_FLAG)); assertTrue(DeviceConfigUtils.isTetheringFeatureNotChickenedOut( mContext, TEST_EXPERIMENT_FLAG)); assertTrue(DeviceConfigUtils.isNetworkStackFeatureNotChickenedOut( mContext, TEST_EXPERIMENT_FLAG)); + assertTrue(DeviceConfigUtils.isCaptivePortalLoginFeatureNotChickenedOut( + mContext, TEST_EXPERIMENT_FLAG)); } @Test @@ -548,10 +552,14 @@ public class DeviceConfigUtilsTest { TEST_EXPERIMENT_FLAG)); doReturn(null).when(() -> DeviceConfig.getProperty(NAMESPACE_TETHERING, TEST_EXPERIMENT_FLAG)); + doReturn(null).when(() -> DeviceConfig.getProperty(NAMESPACE_CAPTIVEPORTALLOGIN, + TEST_EXPERIMENT_FLAG)); assertTrue(DeviceConfigUtils.isTetheringFeatureNotChickenedOut( mContext, TEST_EXPERIMENT_FLAG)); assertTrue(DeviceConfigUtils.isNetworkStackFeatureNotChickenedOut( mContext, TEST_EXPERIMENT_FLAG)); + assertTrue(DeviceConfigUtils.isCaptivePortalLoginFeatureNotChickenedOut( + mContext, TEST_EXPERIMENT_FLAG)); // If the flag is unset, package info is not queried verify(mContext, never()).getPackageManager(); @@ -565,10 +573,14 @@ public class DeviceConfigUtilsTest { TEST_EXPERIMENT_FLAG)); doReturn("1").when(() -> DeviceConfig.getProperty(NAMESPACE_TETHERING, TEST_EXPERIMENT_FLAG)); + doReturn("1").when(() -> DeviceConfig.getProperty(NAMESPACE_CAPTIVEPORTALLOGIN, + TEST_EXPERIMENT_FLAG)); assertTrue(DeviceConfigUtils.isNetworkStackFeatureNotChickenedOut( mContext, TEST_EXPERIMENT_FLAG)); assertTrue(DeviceConfigUtils.isTetheringFeatureNotChickenedOut( mContext, TEST_EXPERIMENT_FLAG)); + assertTrue(DeviceConfigUtils.isCaptivePortalLoginFeatureNotChickenedOut( + mContext, TEST_EXPERIMENT_FLAG)); // If the feature is force enabled, package info is not queried verify(mContext, never()).getPackageManager(); @@ -582,10 +594,14 @@ public class DeviceConfigUtilsTest { TEST_EXPERIMENT_FLAG)); doReturn("-1").when(() -> DeviceConfig.getProperty(NAMESPACE_TETHERING, TEST_EXPERIMENT_FLAG)); + doReturn("-1").when(() -> DeviceConfig.getProperty(NAMESPACE_CAPTIVEPORTALLOGIN, + TEST_EXPERIMENT_FLAG)); assertFalse(DeviceConfigUtils.isNetworkStackFeatureNotChickenedOut( mContext, TEST_EXPERIMENT_FLAG)); assertFalse(DeviceConfigUtils.isTetheringFeatureNotChickenedOut( mContext, TEST_EXPERIMENT_FLAG)); + assertFalse(DeviceConfigUtils.isCaptivePortalLoginFeatureNotChickenedOut( + mContext, TEST_EXPERIMENT_FLAG)); // If the feature is force disabled, package info is not queried verify(mContext, never()).getPackageManager();