Merge "Removing flag management UI states from flag definition" into tm-qpr-dev am: 839fc20feb

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/21725630

Change-Id: I64613adac5217b6a2abd734e80af21f9ba2962d4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Sunny Goyal
2023-03-08 20:18:37 +00:00
committed by Automerger Merge Worker
3 changed files with 19 additions and 36 deletions

View File

@@ -24,8 +24,6 @@ class DebugFlag extends BooleanFlag {
public final boolean defaultValue;
boolean mHasBeenChangedAtLeastOnce;
public DebugFlag(String key, String description, boolean defaultValue, boolean currentValue) {
super(currentValue);
this.key = key;

View File

@@ -35,6 +35,9 @@ import androidx.preference.SwitchPreference;
import com.android.launcher3.R;
import com.android.launcher3.config.FeatureFlags;
import java.util.List;
import java.util.Set;
/**
* Dev-build only UI allowing developers to toggle flag settings. See {@link FeatureFlags}.
*/
@@ -50,31 +53,15 @@ public final class FlagTogglerPrefUi {
@Override
public void putBoolean(String key, boolean value) {
for (DebugFlag flag : FlagsFactory.getDebugFlags()) {
if (flag.key.equals(key)) {
SharedPreferences prefs = mContext.getSharedPreferences(
FLAGS_PREF_NAME, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
// We keep the key in the prefs even if it has the default value, because it's a
// signal that it has been changed at one point.
if (!prefs.contains(key) && value == flag.defaultValue) {
editor.remove(key).apply();
flag.mHasBeenChangedAtLeastOnce = false;
} else {
editor.putBoolean(key, value).apply();
flag.mHasBeenChangedAtLeastOnce = true;
}
updateMenu();
}
}
mSharedPreferences.edit().putBoolean(key, value).apply();
updateMenu();
}
@Override
public boolean getBoolean(String key, boolean defaultValue) {
for (DebugFlag flag : FlagsFactory.getDebugFlags()) {
if (flag.key.equals(key)) {
return mContext.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE)
.getBoolean(key, flag.defaultValue);
return mSharedPreferences.getBoolean(key, flag.defaultValue);
}
}
return defaultValue;
@@ -89,11 +76,22 @@ public final class FlagTogglerPrefUi {
}
public void applyTo(PreferenceGroup parent) {
Set<String> modifiedPrefs = mSharedPreferences.getAll().keySet();
List<DebugFlag> flags = FlagsFactory.getDebugFlags();
flags.sort((f1, f2) -> {
// Sort first by any prefs that the user has changed, then alphabetically.
int changeComparison = Boolean.compare(
modifiedPrefs.contains(f2.key), modifiedPrefs.contains(f1.key));
return changeComparison != 0
? changeComparison
: f1.key.compareToIgnoreCase(f2.key);
});
// For flag overrides we only want to store when the engineer chose to override the
// flag with a different value than the default. That way, when we flip flags in
// future, engineers will pick up the new value immediately. To accomplish this, we use a
// custom preference data store.
for (DebugFlag flag : FlagsFactory.getDebugFlags()) {
for (DebugFlag flag : flags) {
SwitchPreference switchPreference = new SwitchPreference(mContext);
switchPreference.setKey(flag.key);
switchPreference.setDefaultValue(flag.defaultValue);

View File

@@ -53,7 +53,6 @@ public class FlagsFactory {
private static final List<DebugFlag> sDebugFlags = new ArrayList<>();
private final Set<String> mKeySet = new HashSet<>();
private boolean mRestartRequested = false;
@@ -75,7 +74,6 @@ public class FlagsFactory {
.getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE);
boolean currentValue = prefs.getBoolean(key, defaultValue);
DebugFlag flag = new DebugFlag(key, description, defaultValue, currentValue);
flag.mHasBeenChangedAtLeastOnce = prefs.contains(key);
sDebugFlags.add(flag);
return flag;
} else {
@@ -96,7 +94,6 @@ public class FlagsFactory {
boolean currentValue = prefs.getBoolean(key, defaultValue);
DebugFlag flag = new DeviceFlag(key, description, defaultValue, currentValue,
defaultValueInCode);
flag.mHasBeenChangedAtLeastOnce = prefs.contains(key);
sDebugFlags.add(flag);
return flag;
} else {
@@ -117,19 +114,9 @@ public class FlagsFactory {
if (!Utilities.IS_DEBUG_DEVICE) {
return Collections.emptyList();
}
List<DebugFlag> flags;
synchronized (sDebugFlags) {
flags = new ArrayList<>(sDebugFlags);
return new ArrayList<>(sDebugFlags);
}
flags.sort((f1, f2) -> {
// Sort first by any prefs that the user has changed, then alphabetically.
int changeComparison = Boolean.compare(
f2.mHasBeenChangedAtLeastOnce, f1.mHasBeenChangedAtLeastOnce);
return changeComparison != 0
? changeComparison
: f1.key.compareToIgnoreCase(f2.key);
});
return flags;
}
/**