Merge "Removing support for change listeners from feature flags" into sc-v2-dev
This commit is contained in:
commit
4aac62110e
|
@ -17,21 +17,17 @@
|
||||||
package com.android.launcher3.uioverrides;
|
package com.android.launcher3.uioverrides;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.provider.DeviceConfig;
|
import android.provider.DeviceConfig;
|
||||||
|
|
||||||
import com.android.launcher3.config.FeatureFlags.DebugFlag;
|
import com.android.launcher3.config.FeatureFlags.DebugFlag;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.P)
|
@TargetApi(Build.VERSION_CODES.P)
|
||||||
public class DeviceFlag extends DebugFlag {
|
public class DeviceFlag extends DebugFlag {
|
||||||
|
|
||||||
public static final String NAMESPACE_LAUNCHER = "launcher";
|
public static final String NAMESPACE_LAUNCHER = "launcher";
|
||||||
|
|
||||||
private final boolean mDefaultValueInCode;
|
private final boolean mDefaultValueInCode;
|
||||||
ArrayList<Runnable> mListeners;
|
|
||||||
|
|
||||||
public DeviceFlag(String key, boolean defaultValue, String description) {
|
public DeviceFlag(String key, boolean defaultValue, String description) {
|
||||||
super(key, getDeviceValue(key, defaultValue), description);
|
super(key, getDeviceValue(key, defaultValue), description);
|
||||||
|
@ -43,54 +39,12 @@ public class DeviceFlag extends DebugFlag {
|
||||||
return super.appendProps(src).append(", mDefaultValueInCode=").append(mDefaultValueInCode);
|
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
|
@Override
|
||||||
public boolean get() {
|
public boolean get() {
|
||||||
// Override this method in order to let Robolectric ShadowDeviceFlag to stub it.
|
// Override this method in order to let Robolectric ShadowDeviceFlag to stub it.
|
||||||
return super.get();
|
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) {
|
protected static boolean getDeviceValue(String key, boolean defaultValue) {
|
||||||
return DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, key, defaultValue);
|
return DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -295,7 +295,7 @@ public final class FeatureFlags {
|
||||||
public static class BooleanFlag {
|
public static class BooleanFlag {
|
||||||
|
|
||||||
public final String key;
|
public final String key;
|
||||||
public boolean defaultValue;
|
public final boolean defaultValue;
|
||||||
|
|
||||||
public BooleanFlag(String key, boolean defaultValue) {
|
public BooleanFlag(String key, boolean defaultValue) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
|
@ -314,16 +314,12 @@ public final class FeatureFlags {
|
||||||
protected StringBuilder appendProps(StringBuilder src) {
|
protected StringBuilder appendProps(StringBuilder src) {
|
||||||
return src.append(key).append(", defaultValue=").append(defaultValue);
|
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 static class DebugFlag extends BooleanFlag {
|
||||||
|
|
||||||
public final String description;
|
public final String description;
|
||||||
private boolean mCurrentValue;
|
protected boolean mCurrentValue;
|
||||||
|
|
||||||
public DebugFlag(String key, boolean defaultValue, String description) {
|
public DebugFlag(String key, boolean defaultValue, String description) {
|
||||||
super(key, defaultValue);
|
super(key, defaultValue);
|
||||||
|
|
Loading…
Reference in New Issue