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
diff --git a/quickstep/src/com/android/launcher3/uioverrides/TogglableFlag.java b/quickstep/src/com/android/launcher3/uioverrides/TogglableFlag.java
index e425088..853a1c6 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/TogglableFlag.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/TogglableFlag.java
@@ -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();
+ });
}
}
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 2a801d6..b4a2216 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -94,6 +94,7 @@
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();
diff --git a/src/com/android/launcher3/config/BaseFlags.java b/src/com/android/launcher3/config/BaseFlags.java
index ea6261a..025087b 100644
--- a/src/com/android/launcher3/config/BaseFlags.java
+++ b/src/com/android/launcher3/config/BaseFlags.java
@@ -143,6 +143,8 @@
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 @@
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 @@
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 @@
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 @@
return "TogglableFlag{"
+ "key=" + key + ", "
+ "defaultValue=" + defaultValue + ", "
+ + "overriddenDefaultValue=" + getOverridenDefaultValue(defaultValue) + ", "
+ + "currentValue=" + currentValue + ", "
+ "description=" + description
+ "}";
}
@@ -220,7 +227,7 @@
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 @@
h$ *= 1000003;
h$ ^= key.hashCode();
h$ *= 1000003;
- h$ ^= defaultValue ? 1231 : 1237;
+ h$ ^= getDefaultValue() ? 1231 : 1237;
h$ *= 1000003;
h$ ^= description.hashCode();
return h$;
diff --git a/src/com/android/launcher3/icons/IconCache.java b/src/com/android/launcher3/icons/IconCache.java
index 55d58b9..abff237 100644
--- a/src/com/android/launcher3/icons/IconCache.java
+++ b/src/com/android/launcher3/icons/IconCache.java
@@ -42,6 +42,7 @@
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 @@
@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 {
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/TogglableFlag.java b/src_ui_overrides/com/android/launcher3/uioverrides/TogglableFlag.java
index e875a3c..60f12d8 100644
--- a/src_ui_overrides/com/android/launcher3/uioverrides/TogglableFlag.java
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/TogglableFlag.java
@@ -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 @@
}
@Override
- public boolean getInitialValue(boolean value) {
+ public boolean getOverridenDefaultValue(boolean value) {
return value;
}
+
+ @Override
+ public void addChangeListener(Context context, Runnable r) { }
}