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

Commit ac23dfc9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Extend FeatureFlagUtils to take a context object."

parents 1d5d3df3 93d87e69
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.util;

import android.content.Context;
import android.os.SystemProperties;
import android.text.TextUtils;

@@ -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);
+9 −4
Original line number Diff line number Diff line
@@ -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;

@@ -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();
    }

@@ -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
@@ -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);

@@ -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));
    }

}