Merge "Removing support for change listeners from feature flags" into sc-v2-dev

This commit is contained in:
TreeHugger Robot 2021-07-16 01:20:32 +00:00 committed by Android (Google) Code Review
commit 4aac62110e
2 changed files with 2 additions and 52 deletions

View File

@ -17,21 +17,17 @@
package com.android.launcher3.uioverrides;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
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);
@ -43,54 +39,12 @@ 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) {
if (mListeners == null) {
initialize(context);
}
mListeners.add(r);
}
@Override
public void removeChangeListener(Runnable r) {
if (mListeners == null) {
return;
}
mListeners.remove(r);
}
@Override
public boolean get() {
// Override this method in order to let Robolectric ShadowDeviceFlag to stub it.
return super.get();
}
private void registerDeviceConfigChangedListener(Context context) {
DeviceConfig.addOnPropertiesChangedListener(
NAMESPACE_LAUNCHER,
context.getMainExecutor(),
properties -> {
if (!NAMESPACE_LAUNCHER.equals(properties.getNamespace())
|| !properties.getKeyset().contains(key)) {
return;
}
defaultValue = getDeviceValue(key, mDefaultValueInCode);
initialize(context);
for (Runnable r: mListeners) {
r.run();
}
});
}
protected static boolean getDeviceValue(String key, boolean defaultValue) {
return DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, key, defaultValue);
}

View File

@ -295,7 +295,7 @@ public final class FeatureFlags {
public static class BooleanFlag {
public final String key;
public boolean defaultValue;
public final boolean defaultValue;
public BooleanFlag(String key, boolean defaultValue) {
this.key = key;
@ -314,16 +314,12 @@ public final class FeatureFlags {
protected StringBuilder appendProps(StringBuilder src) {
return src.append(key).append(", defaultValue=").append(defaultValue);
}
public void addChangeListener(Context context, Runnable r) { }
public void removeChangeListener(Runnable r) {}
}
public static class DebugFlag extends BooleanFlag {
public final String description;
private boolean mCurrentValue;
protected boolean mCurrentValue;
public DebugFlag(String key, boolean defaultValue, String description) {
super(key, defaultValue);