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

Commit d7c84416 authored by Hyunyoung Song's avatar Hyunyoung Song Committed by Android (Google) Code Review
Browse files

Merge "DeviceFlag change is not detected when phenotype updates." into ub-launcher3-master

parents 0a947154 3c1db273
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -23,12 +23,15 @@ import android.provider.DeviceConfig;

import com.android.launcher3.config.FeatureFlags.DebugFlag;

import java.util.ArrayList;

@TargetApi(Build.VERSION_CODES.P)
public class DeviceFlag extends DebugFlag {

    public static final String NAMESPACE_LAUNCHER = "launcher";

    private final boolean mDefaultValueInCode;
    ArrayList<Runnable> mListeners;

    public DeviceFlag(String key, boolean defaultValue, String description) {
        super(key, getDeviceValue(key, defaultValue), description);
@@ -40,18 +43,34 @@ public class DeviceFlag extends DebugFlag {
        return super.appendProps(src).append(", mDefaultValueInCode=").append(mDefaultValueInCode);
    }

    @Override
    public void initialize(Context context) {
        super.initialize(context);
        if (mListeners == null) {
            mListeners = new ArrayList<>();
            registerDeviceConfigChangedListener(context);
        }
    }

    @Override
    public void addChangeListener(Context context, Runnable r) {
        mListeners.add(r);
    }

    private void registerDeviceConfigChangedListener(Context context) {
        DeviceConfig.addOnPropertiesChangedListener(
                NAMESPACE_LAUNCHER,
                context.getMainExecutor(),
                properties -> {
                    if (!NAMESPACE_LAUNCHER.equals(properties.getNamespace())) {
                    if (!NAMESPACE_LAUNCHER.equals(properties.getNamespace())
                            || !properties.getKeyset().contains(key)) {
                        return;
                    }
                    defaultValue = getDeviceValue(key, mDefaultValueInCode);
                    initialize(context);
                    for (Runnable r: mListeners) {
                        r.run();
                    }
                });
    }

+3 −2
Original line number Diff line number Diff line
@@ -93,8 +93,9 @@ public final class FeatureFlags {
    public static final BooleanFlag FAKE_LANDSCAPE_UI = getDebugFlag(
            "FAKE_LANDSCAPE_UI", false, "Rotate launcher UI instead of using transposed layout");

    public static final BooleanFlag FOLDER_NAME_SUGGEST = getDebugFlag(
            "FOLDER_NAME_SUGGEST", true, "Suggests folder names instead of blank text.");
    public static final BooleanFlag FOLDER_NAME_SUGGEST = new DeviceFlag(
            "FOLDER_NAME_SUGGEST", true,
            "Suggests folder names instead of blank text.");

    public static final BooleanFlag APP_SEARCH_IMPROVEMENTS = new DeviceFlag(
            "APP_SEARCH_IMPROVEMENTS", false,