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

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

Merge "Make a static list of flags."

parents 20782fac 3080636f
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.SystemProperties;
import android.provider.Settings;
import android.text.TextUtils;

import java.util.HashMap;
import java.util.Map;

/**
@@ -33,6 +34,17 @@ public class FeatureFlagUtils {
    public static final String FFLAG_PREFIX = "sys.fflag.";
    public static final String FFLAG_OVERRIDE_PREFIX = FFLAG_PREFIX + "override.";

    private static final Map<String, String> DEFAULT_FLAGS;
    static {
        DEFAULT_FLAGS = new HashMap<>();
        DEFAULT_FLAGS.put("device_info_v2", "true");
        DEFAULT_FLAGS.put("new_settings_suggestion", "true");
        DEFAULT_FLAGS.put("settings_search_v2", "false");
        DEFAULT_FLAGS.put("settings_app_info_v2", "false");
        DEFAULT_FLAGS.put("settings_connected_device_v2", "false");
        DEFAULT_FLAGS.put("settings_battery_v2", "false");
    }

    /**
     * Whether or not a flag is enabled.
     *
@@ -41,7 +53,7 @@ public class FeatureFlagUtils {
     */
    public static boolean isEnabled(Context context, String feature) {
        // Override precedence:
        // Settings.Global -> sys.fflag.override.* -> sys.fflag.*
        // Settings.Global -> sys.fflag.override.* -> static list

        // Step 1: check if feature flag is set in Settings.Global.
        String value;
@@ -57,8 +69,8 @@ public class FeatureFlagUtils {
        if (!TextUtils.isEmpty(value)) {
            return Boolean.parseBoolean(value);
        }
        // Step 3: check if feature flag has any default value. Flag name: sys.fflag.<feature>
        value = SystemProperties.get(FFLAG_PREFIX + feature);
        // Step 3: check if feature flag has any default value.
        value = getAllFeatureFlags().get(feature);
        return Boolean.parseBoolean(value);
    }

@@ -73,6 +85,6 @@ public class FeatureFlagUtils {
     * Returns all feature flags in their raw form.
     */
    public static Map<String, String> getAllFeatureFlags() {
        return null;
        return DEFAULT_FLAGS;
    }
}
+7 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.util;

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

import android.content.Context;
@@ -59,7 +60,7 @@ public class FeatureFlagUtilsTest {

    @Test
    public void testGetFlag_enabled_shouldReturnTrue() {
        SystemProperties.set(FeatureFlagUtils.FFLAG_PREFIX + TEST_FEATURE_NAME, "true");
        FeatureFlagUtils.getAllFeatureFlags().put(TEST_FEATURE_NAME, "true");

        assertTrue(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME));
    }
@@ -96,7 +97,11 @@ public class FeatureFlagUtilsTest {

    @Test
    public void testGetFlag_notSet_shouldReturnFalse() {
        assertFalse(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME));
        assertFalse(FeatureFlagUtils.isEnabled(mContext, TEST_FEATURE_NAME + "does_not_exist"));
    }

    @Test
    public void getAllFeatureFlags_shouldNotBeNull() {
        assertNotNull(FeatureFlagUtils.getAllFeatureFlags());
    }
}