mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-01 00:06:47 +00:00
When DeviceConfig/FeatureFlag value is different than the previous
value, refresh icon cache Bug: 135638690 Bug: 138964490 Test: manually toggled feature flag UI on/off $ adb shell device_config put launcher APP_SEARCH_IMPROVEMENTS [true|false] when launcher is in foreground and also when it is in the background Afterwards, saw if "bank" would show BofA app or not Change-Id: I98b62bd07b14a225168217d7eb9bfdfc7f74435d
This commit is contained in:
@@ -16,17 +16,34 @@
|
||||
|
||||
package com.android.launcher3.uioverrides;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.DeviceConfig;
|
||||
import com.android.launcher3.config.BaseFlags.BaseTogglableFlag;
|
||||
|
||||
public class TogglableFlag extends BaseTogglableFlag {
|
||||
public static final String NAMESPACE_LAUNCHER = "launcher";
|
||||
public static final String TAG = "TogglableFlag";
|
||||
|
||||
public TogglableFlag(String key, boolean defaultValue, String description) {
|
||||
super(key, defaultValue, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInitialValue(boolean value) {
|
||||
return DeviceConfig.getBoolean("launcher", getKey(), value);
|
||||
public boolean getOverridenDefaultValue(boolean value) {
|
||||
return DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, getKey(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChangeListener(Context context, Runnable r) {
|
||||
DeviceConfig.addOnPropertiesChangedListener(
|
||||
NAMESPACE_LAUNCHER,
|
||||
context.getMainExecutor(),
|
||||
(properties) -> {
|
||||
if (!NAMESPACE_LAUNCHER.equals(properties.getNamespace())) {
|
||||
return;
|
||||
}
|
||||
initialize(context);
|
||||
r.run();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ public class LauncherAppState {
|
||||
if (FeatureFlags.IS_DOGFOOD_BUILD) {
|
||||
filter.addAction(ACTION_FORCE_ROLOAD);
|
||||
}
|
||||
FeatureFlags.APP_SEARCH_IMPROVEMENTS.addChangeListener(context, mModel::forceReload);
|
||||
|
||||
mContext.registerReceiver(mModel, filter);
|
||||
UserManagerCompat.getInstance(mContext).enableAndResetCache();
|
||||
|
||||
@@ -143,6 +143,8 @@ public abstract class BaseFlags {
|
||||
|
||||
public static abstract class BaseTogglableFlag {
|
||||
private final String key;
|
||||
// should be value that is hardcoded in client side.
|
||||
// Comparatively, getDefaultValue() can be overridden.
|
||||
private final boolean defaultValue;
|
||||
private final String description;
|
||||
private boolean currentValue;
|
||||
@@ -152,8 +154,9 @@ public abstract class BaseFlags {
|
||||
boolean defaultValue,
|
||||
String description) {
|
||||
this.key = checkNotNull(key);
|
||||
this.currentValue = this.defaultValue = getInitialValue(defaultValue);
|
||||
this.currentValue = this.defaultValue = defaultValue;
|
||||
this.description = checkNotNull(description);
|
||||
|
||||
synchronized (sLock) {
|
||||
sFlags.add((TogglableFlag)this);
|
||||
}
|
||||
@@ -169,16 +172,18 @@ public abstract class BaseFlags {
|
||||
return key;
|
||||
}
|
||||
|
||||
void initialize(Context context) {
|
||||
currentValue = getFromStorage(context, defaultValue);
|
||||
protected void initialize(Context context) {
|
||||
currentValue = getFromStorage(context, getDefaultValue());
|
||||
}
|
||||
|
||||
protected abstract boolean getInitialValue(boolean value);
|
||||
protected abstract boolean getOverridenDefaultValue(boolean value);
|
||||
|
||||
protected abstract void addChangeListener(Context context, Runnable r);
|
||||
|
||||
public void updateStorage(Context context, boolean value) {
|
||||
SharedPreferences.Editor editor = context.getSharedPreferences(FLAGS_PREF_NAME,
|
||||
Context.MODE_PRIVATE).edit();
|
||||
if (value == defaultValue) {
|
||||
if (value == getDefaultValue()) {
|
||||
editor.remove(key).apply();
|
||||
} else {
|
||||
editor.putBoolean(key, value).apply();
|
||||
@@ -187,11 +192,11 @@ public abstract class BaseFlags {
|
||||
|
||||
boolean getFromStorage(Context context, boolean defaultValue) {
|
||||
return context.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE)
|
||||
.getBoolean(key, defaultValue);
|
||||
.getBoolean(key, getDefaultValue());
|
||||
}
|
||||
|
||||
boolean getDefaultValue() {
|
||||
return defaultValue;
|
||||
return getOverridenDefaultValue(defaultValue);
|
||||
}
|
||||
|
||||
/** Returns the value of the flag at process start, including any overrides present. */
|
||||
@@ -208,6 +213,8 @@ public abstract class BaseFlags {
|
||||
return "TogglableFlag{"
|
||||
+ "key=" + key + ", "
|
||||
+ "defaultValue=" + defaultValue + ", "
|
||||
+ "overriddenDefaultValue=" + getOverridenDefaultValue(defaultValue) + ", "
|
||||
+ "currentValue=" + currentValue + ", "
|
||||
+ "description=" + description
|
||||
+ "}";
|
||||
}
|
||||
@@ -220,7 +227,7 @@ public abstract class BaseFlags {
|
||||
if (o instanceof TogglableFlag) {
|
||||
BaseTogglableFlag that = (BaseTogglableFlag) o;
|
||||
return (this.key.equals(that.getKey()))
|
||||
&& (this.defaultValue == that.getDefaultValue())
|
||||
&& (this.getDefaultValue() == that.getDefaultValue())
|
||||
&& (this.description.equals(that.getDescription()));
|
||||
}
|
||||
return false;
|
||||
@@ -232,7 +239,7 @@ public abstract class BaseFlags {
|
||||
h$ *= 1000003;
|
||||
h$ ^= key.hashCode();
|
||||
h$ *= 1000003;
|
||||
h$ ^= defaultValue ? 1231 : 1237;
|
||||
h$ ^= getDefaultValue() ? 1231 : 1237;
|
||||
h$ *= 1000003;
|
||||
h$ ^= description.hashCode();
|
||||
return h$;
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.android.launcher3.Utilities;
|
||||
import com.android.launcher3.WorkspaceItemInfo;
|
||||
import com.android.launcher3.compat.LauncherAppsCompat;
|
||||
import com.android.launcher3.compat.UserManagerCompat;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.icons.ComponentWithLabel.ComponentCachingLogic;
|
||||
import com.android.launcher3.icons.cache.BaseIconCache;
|
||||
import com.android.launcher3.icons.cache.CachingLogic;
|
||||
@@ -237,7 +238,8 @@ public class IconCache extends BaseIconCache {
|
||||
|
||||
@Override
|
||||
protected String getIconSystemState(String packageName) {
|
||||
return mIconProvider.getSystemStateForPackage(mSystemState, packageName);
|
||||
return mIconProvider.getSystemStateForPackage(mSystemState, packageName)
|
||||
+ ",flags_asi:" + FeatureFlags.APP_SEARCH_IMPROVEMENTS.get();
|
||||
}
|
||||
|
||||
public static abstract class IconLoadRequest extends HandlerRunnable {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.launcher3.uioverrides;
|
||||
|
||||
import android.content.Context;
|
||||
import com.android.launcher3.config.BaseFlags.BaseTogglableFlag;
|
||||
|
||||
public class TogglableFlag extends BaseTogglableFlag {
|
||||
@@ -25,7 +26,10 @@ public class TogglableFlag extends BaseTogglableFlag {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getInitialValue(boolean value) {
|
||||
public boolean getOverridenDefaultValue(boolean value) {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChangeListener(Context context, Runnable r) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user