diff options
author | Xiao Ma <xiaom@google.com> | 2023-08-28 17:37:30 +0900 |
---|---|---|
committer | Xiao Ma <xiaom@google.com> | 2023-08-28 17:52:04 +0900 |
commit | f4726de160529eb97dd8dafe187a3979024e949b (patch) | |
tree | 2a3b5ad37eb8955762bdf742466f02f84b36fc11 | |
parent | 027be158fc418d7838d47ff4f8541918822da6f6 (diff) | |
download | net-f4726de160529eb97dd8dafe187a3979024e949b.tar.gz |
Add isNetworkStackFeatureNotChickenedOut API for NetworkStack module.
Bug: 279108992
Test: atest NetworkStaticLibsTests
Change-Id: If42eb401b812017bd4d724b4323a8d51f7430606
-rw-r--r-- | common/device/com/android/net/module/util/DeviceConfigUtils.java | 39 | ||||
-rw-r--r-- | common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java | 15 |
2 files changed, 45 insertions, 9 deletions
diff --git a/common/device/com/android/net/module/util/DeviceConfigUtils.java b/common/device/com/android/net/module/util/DeviceConfigUtils.java index caa2b055..fb130f67 100644 --- a/common/device/com/android/net/module/util/DeviceConfigUtils.java +++ b/common/device/com/android/net/module/util/DeviceConfigUtils.java @@ -17,6 +17,7 @@ package com.android.net.module.util; import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY; +import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY; import static android.provider.DeviceConfig.NAMESPACE_TETHERING; import static com.android.net.module.util.FeatureVersions.CONNECTIVITY_MODULE_ID; @@ -335,23 +336,45 @@ public final class DeviceConfigUtils { } /** - * Check whether one specific experimental feature in tethering module from {@link DeviceConfig} - * is not disabled. Feature can be disabled by setting a non-zero value in the property. - * 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 #isTetheringFeatureEnabled} should be used. + * Check whether one specific experimental feature in specific namespace from + * {@link DeviceConfig} is not disabled. Feature can be disabled by setting a non-zero + * value in the property. 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 #isFeatureEnabled} should be used. * + * @param namespace The namespace containing the property to look up. * @param name The name of the property to look up. * @return true if this feature is enabled, or false if disabled. */ - public static boolean isTetheringFeatureNotChickenedOut(String name) { - final int propertyVersion = getDeviceConfigPropertyInt(NAMESPACE_TETHERING, name, + private static boolean isFeatureNotChickenedOut(String namespace, String name) { + final int propertyVersion = getDeviceConfigPropertyInt(namespace, name, 0 /* default value */); return propertyVersion == 0; } /** + * Check whether one specific experimental feature in Tethering module from {@link DeviceConfig} + * is not disabled. + * + * @param name The name of the property in tethering module to look up. + * @return true if this feature is enabled, or false if disabled. + */ + public static boolean isTetheringFeatureNotChickenedOut(String name) { + return isFeatureNotChickenedOut(NAMESPACE_TETHERING, name); + } + + /** + * Check whether one specific experimental feature in NetworkStack module from + * {@link DeviceConfig} is not disabled. + * + * @param name The name of the property in NetworkStack module to look up. + * @return true if this feature is enabled, or false if disabled. + */ + public static boolean isNetworkStackFeatureNotChickenedOut(String name) { + return isFeatureNotChickenedOut(NAMESPACE_CONNECTIVITY, name); + } + + /** * Gets boolean config from resources. */ public static boolean getResBooleanConfig(@NonNull final Context context, diff --git a/common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java b/common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java index e80fa80a..f259e687 100644 --- a/common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java +++ b/common/tests/unit/src/com/android/net/module/util/DeviceConfigUtilsTest.java @@ -17,6 +17,7 @@ package com.android.net.module.util; import static android.content.pm.PackageManager.MATCH_SYSTEM_ONLY; +import static android.provider.DeviceConfig.NAMESPACE_CONNECTIVITY; import static android.provider.DeviceConfig.NAMESPACE_TETHERING; import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn; @@ -421,7 +422,7 @@ public class DeviceConfigUtilsTest { } @Test - public void testIsTetheringFeatureForceDisabled() throws Exception { + public void testIsTetheringFeatureNotChickenedOut() throws Exception { doReturn("0").when(() -> DeviceConfig.getProperty( eq(NAMESPACE_TETHERING), eq(TEST_EXPERIMENT_FLAG))); assertTrue(DeviceConfigUtils.isTetheringFeatureNotChickenedOut(TEST_EXPERIMENT_FLAG)); @@ -430,4 +431,16 @@ public class DeviceConfigUtilsTest { () -> DeviceConfig.getProperty(eq(NAMESPACE_TETHERING), eq(TEST_EXPERIMENT_FLAG))); assertFalse(DeviceConfigUtils.isTetheringFeatureNotChickenedOut(TEST_EXPERIMENT_FLAG)); } + + @Test + public void testIsNetworkStackFeatureNotChickenedOut() throws Exception { + doReturn("0").when(() -> DeviceConfig.getProperty( + eq(NAMESPACE_CONNECTIVITY), eq(TEST_EXPERIMENT_FLAG))); + assertTrue(DeviceConfigUtils.isNetworkStackFeatureNotChickenedOut(TEST_EXPERIMENT_FLAG)); + + doReturn(TEST_FLAG_VALUE_STRING).when( + () -> DeviceConfig.getProperty(eq(NAMESPACE_CONNECTIVITY), + eq(TEST_EXPERIMENT_FLAG))); + assertFalse(DeviceConfigUtils.isNetworkStackFeatureNotChickenedOut(TEST_EXPERIMENT_FLAG)); + } } |