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

This commit is contained in:
Hyunyoung Song
2020-03-10 19:15:37 +00:00
committed by Android (Google) Code Review
2 changed files with 24 additions and 4 deletions
@@ -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);
r.run();
for (Runnable r: mListeners) {
r.run();
}
});
}
@@ -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,