Loading core/java/android/util/FeatureFlagUtils.java +2 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.util; import android.content.Context; import android.os.SystemProperties; import android.text.TextUtils; Loading @@ -37,7 +38,7 @@ public class FeatureFlagUtils { * @param feature the flag name * @return true if the flag is enabled (either by default in system, or override by user) */ public static boolean isEnabled(String feature) { public static boolean isEnabled(Context context, String feature) { // Tries to get feature flag from system property. // Step 1: check if feature flag has any override. Flag name: sys.fflag.override.<feature> String value = SystemProperties.get(FFLAG_OVERRIDE_PREFIX + feature); Loading core/tests/featureflagtests/src/android/util/FeatureFlagUtilsTest.java +9 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import android.content.Context; import android.os.SystemProperties; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; Loading @@ -35,8 +37,11 @@ public class FeatureFlagUtilsTest { private static final String TEST_FEATURE_NAME = "feature_foobar"; private Context mContext; @Before public void setUp() { mContext = InstrumentationRegistry.getTargetContext(); cleanup(); } Loading @@ -54,7 +59,7 @@ public class FeatureFlagUtilsTest { public void testGetFlag_enabled_shouldReturnTrue() { SystemProperties.set(FeatureFlagUtils.FFLAG_PREFIX + TEST_FEATURE_NAME, "true"); assertTrue(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME)); assertTrue(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME)); } @Test Loading @@ -62,12 +67,12 @@ public class FeatureFlagUtilsTest { SystemProperties.set(FeatureFlagUtils.FFLAG_PREFIX + TEST_FEATURE_NAME, "false"); SystemProperties.set(FeatureFlagUtils.FFLAG_OVERRIDE_PREFIX + TEST_FEATURE_NAME, "true"); assertTrue(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME)); assertTrue(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME)); } @Test public void testSetEnabled_shouldSetOverrideFlag() { assertFalse(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME)); assertFalse(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME)); FeatureFlagUtils.setEnabled(TEST_FEATURE_NAME, true); Loading @@ -79,7 +84,7 @@ public class FeatureFlagUtilsTest { @Test public void testGetFlag_notSet_shouldReturnFalse() { assertFalse(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME)); assertFalse(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME)); } } Loading
core/java/android/util/FeatureFlagUtils.java +2 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.util; import android.content.Context; import android.os.SystemProperties; import android.text.TextUtils; Loading @@ -37,7 +38,7 @@ public class FeatureFlagUtils { * @param feature the flag name * @return true if the flag is enabled (either by default in system, or override by user) */ public static boolean isEnabled(String feature) { public static boolean isEnabled(Context context, String feature) { // Tries to get feature flag from system property. // Step 1: check if feature flag has any override. Flag name: sys.fflag.override.<feature> String value = SystemProperties.get(FFLAG_OVERRIDE_PREFIX + feature); Loading
core/tests/featureflagtests/src/android/util/FeatureFlagUtilsTest.java +9 −4 Original line number Diff line number Diff line Loading @@ -20,7 +20,9 @@ import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import android.content.Context; import android.os.SystemProperties; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; Loading @@ -35,8 +37,11 @@ public class FeatureFlagUtilsTest { private static final String TEST_FEATURE_NAME = "feature_foobar"; private Context mContext; @Before public void setUp() { mContext = InstrumentationRegistry.getTargetContext(); cleanup(); } Loading @@ -54,7 +59,7 @@ public class FeatureFlagUtilsTest { public void testGetFlag_enabled_shouldReturnTrue() { SystemProperties.set(FeatureFlagUtils.FFLAG_PREFIX + TEST_FEATURE_NAME, "true"); assertTrue(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME)); assertTrue(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME)); } @Test Loading @@ -62,12 +67,12 @@ public class FeatureFlagUtilsTest { SystemProperties.set(FeatureFlagUtils.FFLAG_PREFIX + TEST_FEATURE_NAME, "false"); SystemProperties.set(FeatureFlagUtils.FFLAG_OVERRIDE_PREFIX + TEST_FEATURE_NAME, "true"); assertTrue(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME)); assertTrue(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME)); } @Test public void testSetEnabled_shouldSetOverrideFlag() { assertFalse(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME)); assertFalse(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME)); FeatureFlagUtils.setEnabled(TEST_FEATURE_NAME, true); Loading @@ -79,7 +84,7 @@ public class FeatureFlagUtilsTest { @Test public void testGetFlag_notSet_shouldReturnFalse() { assertFalse(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME)); assertFalse(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME)); } }