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

Commit cfd02742 authored by Fan Zhang's avatar Fan Zhang
Browse files

Add helper method to override flag

Bug: 36222960
Test: atest FrameworksCoreFeatureFlagTests
Change-Id: I45edc5171e66e4ac8e84cfc58a9fdf9bae2b136a
parent d96b97b8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -49,6 +49,13 @@ public class FeatureFlagUtils {
        return Boolean.parseBoolean(value);
    }

    /**
     * Override feature flag to new state.
     */
    public static void setEnabled(String feature, boolean enabled) {
        SystemProperties.set(FFLAG_OVERRIDE_PREFIX + feature, enabled ? "true" : "false");
    }

    /**
     * Returns all feature flags in their raw form.
     */
+13 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.util;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;

@@ -64,6 +65,18 @@ public class FeatureFlagUtilsTest {
        assertTrue(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME));
    }

    @Test
    public void testSetEnabled_shouldSetOverrideFlag() {
        assertFalse(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME));

        FeatureFlagUtils.setEnabled(TEST_FEATURE_NAME, true);

        assertEquals(SystemProperties.get(FeatureFlagUtils.FFLAG_PREFIX + TEST_FEATURE_NAME, null),
                "");
        assertTrue(Boolean.parseBoolean(SystemProperties.get(
                FeatureFlagUtils.FFLAG_OVERRIDE_PREFIX + TEST_FEATURE_NAME, "")));
    }

    @Test
    public void testGetFlag_notSet_shouldReturnFalse() {
        assertFalse(FeatureFlagUtils.isEnabled(TEST_FEATURE_NAME));