Loading quickstep/src/com/android/launcher3/uioverrides/flags/FlagTogglerPrefUi.java +6 −12 Original line number Diff line number Diff line Loading @@ -16,12 +16,10 @@ package com.android.launcher3.uioverrides.flags; import static com.android.launcher3.config.FeatureFlags.FLAGS_PREF_NAME; import static com.android.launcher3.config.FeatureFlags.FlagState.TEAMFOOD; import static com.android.launcher3.uioverrides.flags.FlagsFactory.TEAMFOOD_FLAG; import android.content.Context; import android.content.SharedPreferences; import android.os.Handler; import android.os.Process; import android.text.Html; Loading Loading @@ -52,31 +50,27 @@ public final class FlagTogglerPrefUi { private final PreferenceFragmentCompat mFragment; private final Context mContext; private final SharedPreferences mSharedPreferences; private final PreferenceDataStore mDataStore = new PreferenceDataStore() { @Override public void putBoolean(String key, boolean value) { mSharedPreferences.edit().putBoolean(key, value).apply(); FlagsFactory.getSharedPreferences().edit().putBoolean(key, value).apply(); updateMenu(); } @Override public boolean getBoolean(String key, boolean defaultValue) { return mSharedPreferences.getBoolean(key, defaultValue); return FlagsFactory.getSharedPreferences().getBoolean(key, defaultValue); } }; public FlagTogglerPrefUi(PreferenceFragmentCompat fragment) { mFragment = fragment; mContext = fragment.getActivity(); mSharedPreferences = mContext.getSharedPreferences( FLAGS_PREF_NAME, Context.MODE_PRIVATE); } public void applyTo(PreferenceGroup parent) { Set<String> modifiedPrefs = mSharedPreferences.getAll().keySet(); Set<String> modifiedPrefs = FlagsFactory.getSharedPreferences().getAll().keySet(); List<DebugFlag> flags = FlagsFactory.getDebugFlags(); flags.sort((f1, f2) -> { // Sort first by any prefs that the user has changed, then alphabetically. Loading @@ -102,7 +96,7 @@ public final class FlagTogglerPrefUi { public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); holder.itemView.setOnLongClickListener(v -> { mSharedPreferences.edit().remove(flag.key).apply(); FlagsFactory.getSharedPreferences().edit().remove(flag.key).apply(); setChecked(getFlagStateFromSharedPrefs(flag)); updateSummary(this, flag); updateMenu(); Loading Loading @@ -133,7 +127,7 @@ public final class FlagTogglerPrefUi { private void updateSummary(SwitchPreference switchPreference, DebugFlag flag) { String summary = flag.defaultValue == TEAMFOOD ? "<font color='blue'><b>[TEAMFOOD]</b> </font>" : ""; if (mSharedPreferences.contains(flag.key)) { if (FlagsFactory.getSharedPreferences().contains(flag.key)) { summary += "<font color='red'><b>[OVERRIDDEN]</b> </font>"; } if (!TextUtils.isEmpty(summary)) { Loading @@ -156,7 +150,7 @@ public final class FlagTogglerPrefUi { public void onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menu_apply_flags) { mSharedPreferences.edit().commit(); FlagsFactory.getSharedPreferences().edit().commit(); Log.e(TAG, "Killing launcher process " + Process.myPid() + " to apply new flag values"); System.exit(0); Loading quickstep/src/com/android/launcher3/uioverrides/flags/FlagsFactory.java +17 −8 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import static android.app.ActivityThread.currentApplication; import static com.android.launcher3.BuildConfig.IS_DEBUG_DEVICE; import static com.android.launcher3.config.FeatureFlags.FlagState.DISABLED; import static com.android.launcher3.config.FeatureFlags.FlagState.ENABLED; import static com.android.launcher3.config.FeatureFlags.FlagState.TEAMFOOD; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import android.content.Context; Loading @@ -30,6 +29,8 @@ import android.provider.DeviceConfig; import android.provider.DeviceConfig.Properties; import android.util.Log; import androidx.annotation.NonNull; import com.android.launcher3.config.FeatureFlags.BooleanFlag; import com.android.launcher3.config.FeatureFlags.FlagState; import com.android.launcher3.config.FeatureFlags.IntFlag; Loading @@ -52,10 +53,11 @@ public class FlagsFactory { private static final FlagsFactory INSTANCE = new FlagsFactory(); private static final boolean FLAG_AUTO_APPLY_ENABLED = true; public static final String FLAGS_PREF_NAME = "featureFlags"; private static final String FLAGS_PREF_NAME = "featureFlags"; public static final String NAMESPACE_LAUNCHER = "launcher"; private static final List<DebugFlag> sDebugFlags = new ArrayList<>(); private static SharedPreferences sSharedPreferences; static final BooleanFlag TEAMFOOD_FLAG = getReleaseFlag( 0, "LAUNCHER_TEAMFOOD", DISABLED, "Enable this flag to opt-in all team food flags"); Loading Loading @@ -93,10 +95,8 @@ public class FlagsFactory { public static BooleanFlag getDebugFlag( int bugId, String key, FlagState flagState, String description) { if (IS_DEBUG_DEVICE) { SharedPreferences prefs = currentApplication() .getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); boolean defaultValue = getEnabledValue(flagState); boolean currentValue = prefs.getBoolean(key, defaultValue); boolean currentValue = getSharedPreferences().getBoolean(key, defaultValue); DebugFlag flag = new DebugFlag(key, description, flagState, currentValue); sDebugFlags.add(flag); return flag; Loading @@ -115,9 +115,7 @@ public class FlagsFactory { boolean defaultValueInCode = getEnabledValue(flagState); boolean defaultValue = DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, key, defaultValueInCode); if (IS_DEBUG_DEVICE) { SharedPreferences prefs = currentApplication() .getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); boolean currentValue = prefs.getBoolean(key, defaultValue); boolean currentValue = getSharedPreferences().getBoolean(key, defaultValue); DebugFlag flag = new DeviceFlag(key, description, flagState, currentValue, defaultValueInCode); sDebugFlags.add(flag); Loading Loading @@ -145,6 +143,17 @@ public class FlagsFactory { } } /** Returns the SharedPreferences instance backing Debug FeatureFlags. */ @NonNull static SharedPreferences getSharedPreferences() { if (sSharedPreferences == null) { sSharedPreferences = currentApplication() .createDeviceProtectedStorageContext() .getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); } return sSharedPreferences; } /** * Dumps the current flags state to the print writer */ Loading src/com/android/launcher3/config/FeatureFlags.java +0 −2 Original line number Diff line number Diff line Loading @@ -39,8 +39,6 @@ import java.util.function.ToIntFunction; */ public final class FeatureFlags { public static final String FLAGS_PREF_NAME = "featureFlags"; @VisibleForTesting public static Predicate<BooleanFlag> sBooleanReader = f -> f.mCurrentValue; @VisibleForTesting Loading Loading
quickstep/src/com/android/launcher3/uioverrides/flags/FlagTogglerPrefUi.java +6 −12 Original line number Diff line number Diff line Loading @@ -16,12 +16,10 @@ package com.android.launcher3.uioverrides.flags; import static com.android.launcher3.config.FeatureFlags.FLAGS_PREF_NAME; import static com.android.launcher3.config.FeatureFlags.FlagState.TEAMFOOD; import static com.android.launcher3.uioverrides.flags.FlagsFactory.TEAMFOOD_FLAG; import android.content.Context; import android.content.SharedPreferences; import android.os.Handler; import android.os.Process; import android.text.Html; Loading Loading @@ -52,31 +50,27 @@ public final class FlagTogglerPrefUi { private final PreferenceFragmentCompat mFragment; private final Context mContext; private final SharedPreferences mSharedPreferences; private final PreferenceDataStore mDataStore = new PreferenceDataStore() { @Override public void putBoolean(String key, boolean value) { mSharedPreferences.edit().putBoolean(key, value).apply(); FlagsFactory.getSharedPreferences().edit().putBoolean(key, value).apply(); updateMenu(); } @Override public boolean getBoolean(String key, boolean defaultValue) { return mSharedPreferences.getBoolean(key, defaultValue); return FlagsFactory.getSharedPreferences().getBoolean(key, defaultValue); } }; public FlagTogglerPrefUi(PreferenceFragmentCompat fragment) { mFragment = fragment; mContext = fragment.getActivity(); mSharedPreferences = mContext.getSharedPreferences( FLAGS_PREF_NAME, Context.MODE_PRIVATE); } public void applyTo(PreferenceGroup parent) { Set<String> modifiedPrefs = mSharedPreferences.getAll().keySet(); Set<String> modifiedPrefs = FlagsFactory.getSharedPreferences().getAll().keySet(); List<DebugFlag> flags = FlagsFactory.getDebugFlags(); flags.sort((f1, f2) -> { // Sort first by any prefs that the user has changed, then alphabetically. Loading @@ -102,7 +96,7 @@ public final class FlagTogglerPrefUi { public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); holder.itemView.setOnLongClickListener(v -> { mSharedPreferences.edit().remove(flag.key).apply(); FlagsFactory.getSharedPreferences().edit().remove(flag.key).apply(); setChecked(getFlagStateFromSharedPrefs(flag)); updateSummary(this, flag); updateMenu(); Loading Loading @@ -133,7 +127,7 @@ public final class FlagTogglerPrefUi { private void updateSummary(SwitchPreference switchPreference, DebugFlag flag) { String summary = flag.defaultValue == TEAMFOOD ? "<font color='blue'><b>[TEAMFOOD]</b> </font>" : ""; if (mSharedPreferences.contains(flag.key)) { if (FlagsFactory.getSharedPreferences().contains(flag.key)) { summary += "<font color='red'><b>[OVERRIDDEN]</b> </font>"; } if (!TextUtils.isEmpty(summary)) { Loading @@ -156,7 +150,7 @@ public final class FlagTogglerPrefUi { public void onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.menu_apply_flags) { mSharedPreferences.edit().commit(); FlagsFactory.getSharedPreferences().edit().commit(); Log.e(TAG, "Killing launcher process " + Process.myPid() + " to apply new flag values"); System.exit(0); Loading
quickstep/src/com/android/launcher3/uioverrides/flags/FlagsFactory.java +17 −8 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import static android.app.ActivityThread.currentApplication; import static com.android.launcher3.BuildConfig.IS_DEBUG_DEVICE; import static com.android.launcher3.config.FeatureFlags.FlagState.DISABLED; import static com.android.launcher3.config.FeatureFlags.FlagState.ENABLED; import static com.android.launcher3.config.FeatureFlags.FlagState.TEAMFOOD; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; import android.content.Context; Loading @@ -30,6 +29,8 @@ import android.provider.DeviceConfig; import android.provider.DeviceConfig.Properties; import android.util.Log; import androidx.annotation.NonNull; import com.android.launcher3.config.FeatureFlags.BooleanFlag; import com.android.launcher3.config.FeatureFlags.FlagState; import com.android.launcher3.config.FeatureFlags.IntFlag; Loading @@ -52,10 +53,11 @@ public class FlagsFactory { private static final FlagsFactory INSTANCE = new FlagsFactory(); private static final boolean FLAG_AUTO_APPLY_ENABLED = true; public static final String FLAGS_PREF_NAME = "featureFlags"; private static final String FLAGS_PREF_NAME = "featureFlags"; public static final String NAMESPACE_LAUNCHER = "launcher"; private static final List<DebugFlag> sDebugFlags = new ArrayList<>(); private static SharedPreferences sSharedPreferences; static final BooleanFlag TEAMFOOD_FLAG = getReleaseFlag( 0, "LAUNCHER_TEAMFOOD", DISABLED, "Enable this flag to opt-in all team food flags"); Loading Loading @@ -93,10 +95,8 @@ public class FlagsFactory { public static BooleanFlag getDebugFlag( int bugId, String key, FlagState flagState, String description) { if (IS_DEBUG_DEVICE) { SharedPreferences prefs = currentApplication() .getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); boolean defaultValue = getEnabledValue(flagState); boolean currentValue = prefs.getBoolean(key, defaultValue); boolean currentValue = getSharedPreferences().getBoolean(key, defaultValue); DebugFlag flag = new DebugFlag(key, description, flagState, currentValue); sDebugFlags.add(flag); return flag; Loading @@ -115,9 +115,7 @@ public class FlagsFactory { boolean defaultValueInCode = getEnabledValue(flagState); boolean defaultValue = DeviceConfig.getBoolean(NAMESPACE_LAUNCHER, key, defaultValueInCode); if (IS_DEBUG_DEVICE) { SharedPreferences prefs = currentApplication() .getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); boolean currentValue = prefs.getBoolean(key, defaultValue); boolean currentValue = getSharedPreferences().getBoolean(key, defaultValue); DebugFlag flag = new DeviceFlag(key, description, flagState, currentValue, defaultValueInCode); sDebugFlags.add(flag); Loading Loading @@ -145,6 +143,17 @@ public class FlagsFactory { } } /** Returns the SharedPreferences instance backing Debug FeatureFlags. */ @NonNull static SharedPreferences getSharedPreferences() { if (sSharedPreferences == null) { sSharedPreferences = currentApplication() .createDeviceProtectedStorageContext() .getSharedPreferences(FLAGS_PREF_NAME, Context.MODE_PRIVATE); } return sSharedPreferences; } /** * Dumps the current flags state to the print writer */ Loading
src/com/android/launcher3/config/FeatureFlags.java +0 −2 Original line number Diff line number Diff line Loading @@ -39,8 +39,6 @@ import java.util.function.ToIntFunction; */ public final class FeatureFlags { public static final String FLAGS_PREF_NAME = "featureFlags"; @VisibleForTesting public static Predicate<BooleanFlag> sBooleanReader = f -> f.mCurrentValue; @VisibleForTesting Loading