Fix the Int value to reflect shared preferences value in TouchInteractionService.

This cl fixes following things

- When featureFlag is present, always read the value from FeatureFlag.get() instead of preferences.

- Add new function getIntFlagBackedUpByLauncherPrefs to read from sharedPreferences

- Make FlagTogglerPrefUi.java updateMenu() public

- When intFlag is modified in Developer Options, Apply button will show up. So launcher can restart and values get applied.

- Omnient Int flags will read from Featureflag.get() instead of shared preferences directly.

Bug: 320696242
Test: Manual
Flag: NA. Developer Options related

Change-Id: Id916b25d0397505d240ea8444d896c8ace826e57
diff --git a/quickstep/src/com/android/launcher3/uioverrides/flags/DeveloperOptionsUI.java b/quickstep/src/com/android/launcher3/uioverrides/flags/DeveloperOptionsUI.java
index c1a85fa..369ff14 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/flags/DeveloperOptionsUI.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/flags/DeveloperOptionsUI.java
@@ -21,14 +21,14 @@
 import static android.view.View.VISIBLE;
 
 import static com.android.launcher3.LauncherPrefs.ALL_APPS_OVERVIEW_THRESHOLD;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_DELAY;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_TIMEOUT_MS;
 import static com.android.launcher3.LauncherPrefs.PRIVATE_SPACE_APPS;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_DELAY;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_END_SCALE_PERCENT;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_ITERATIONS;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_SCALE_EXPONENT;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_START_SCALE_PERCENT;
+import static com.android.launcher3.config.FeatureFlags.LPNH_SLOP_PERCENTAGE;
+import static com.android.launcher3.config.FeatureFlags.LPNH_TIMEOUT_MS;
 import static com.android.launcher3.settings.SettingsActivity.EXTRA_FRAGMENT_HIGHLIGHT_KEY;
 import static com.android.launcher3.uioverrides.plugins.PluginManagerWrapper.PLUGIN_CHANGED;
 import static com.android.launcher3.uioverrides.plugins.PluginManagerWrapper.pluginEnabledKey;
@@ -50,6 +50,7 @@
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.util.ArrayMap;
+import android.util.Log;
 import android.util.Pair;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -88,11 +89,14 @@
 
     private static final String ACTION_PLUGIN_SETTINGS =
             "com.android.systemui.action.PLUGIN_SETTINGS";
+    private static final String TAG = "DeveloperOptionsUI";
     private static final String PLUGIN_PERMISSION = "com.android.systemui.permission.PLUGIN";
 
     private final PreferenceFragmentCompat mFragment;
     private final PreferenceScreen mPreferenceScreen;
 
+    private final FlagTogglerPrefUi mFlagTogglerPrefUi;
+
     private PreferenceCategory mPluginsCategory;
 
     public DeveloperOptionsUI(PreferenceFragmentCompat fragment, PreferenceCategory flags) {
@@ -107,8 +111,9 @@
         parent.addView(topBar, parent.indexOfChild(listView));
         initSearch(topBar.findViewById(R.id.filter_box));
 
-        new FlagTogglerPrefUi(mFragment.requireActivity(), topBar.findViewById(R.id.flag_apply_btn))
-                .applyTo(flags);
+        mFlagTogglerPrefUi = new FlagTogglerPrefUi(mFragment.requireActivity(),
+                topBar.findViewById(R.id.flag_apply_btn));
+        mFlagTogglerPrefUi.applyTo(flags);
 
         loadPluginPrefs();
         maybeAddSandboxCategory();
@@ -350,23 +355,27 @@
     private void addCustomLpnhCategory() {
         PreferenceCategory category = newCategory("Long Press Nav Handle Config");
         if (FeatureFlags.CUSTOM_LPNH_THRESHOLDS.get()) {
-            category.addPreference(createSeekBarPreference("Slop multiplier (applied to edge slop, "
+            category.addPreference(createSeekBarPreference(
+                    "Slop multiplier (applied to edge slop, "
                             + "which is generally already 50% higher than touch slop)",
-                    25, 200, 100, LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE));
-            category.addPreference(createSeekBarPreference("Trigger milliseconds",
-                    100, 500, 1, LONG_PRESS_NAV_HANDLE_TIMEOUT_MS));
+                    25, 200, 100, LPNH_SLOP_PERCENTAGE));
+            category.addPreference(createSeekBarPreference("LPNH timeout",
+                    100, 500, 1, LPNH_TIMEOUT_MS));
         }
         if (FeatureFlags.ENABLE_SEARCH_HAPTIC_HINT.get()) {
-            category.addPreference(createSeekBarPreference("Haptic hint start scale",
-                    0, 100, 100, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT));
+            category.addPreference(
+                    createSeekBarPreference("Haptic hint start scale",
+                            0, 100, 100, LPNH_HAPTIC_HINT_START_SCALE_PERCENT));
             category.addPreference(createSeekBarPreference("Haptic hint end scale",
-                    0, 100, 100, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT));
-            category.addPreference(createSeekBarPreference("Haptic hint scale exponent",
-                    1, 5, 1, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT));
-            category.addPreference(createSeekBarPreference("Haptic hint iterations (12 ms each)",
-                    0, 200, 1, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS));
+                    0, 100, 100, LPNH_HAPTIC_HINT_END_SCALE_PERCENT));
+            category.addPreference(
+                    createSeekBarPreference("Haptic hint scale exponent",
+                            1, 5, 1, LPNH_HAPTIC_HINT_SCALE_EXPONENT));
+            category.addPreference(
+                    createSeekBarPreference("Haptic hint iterations (12 ms each)",
+                            0, 200, 1, LPNH_HAPTIC_HINT_ITERATIONS));
             category.addPreference(createSeekBarPreference("Haptic hint delay (ms)",
-                    0, 400, 1, LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_DELAY));
+                    0, 400, 1, LPNH_HAPTIC_HINT_DELAY));
         }
     }
 
@@ -376,6 +385,29 @@
                 "Number of Apps to put in private region", 0, 100, 1, PRIVATE_SPACE_APPS));
     }
 
+    private SeekBarPreference createSeekBarPreference(String title, int min,
+            int max, int scale, FeatureFlags.IntFlag flag) {
+        if (!(flag instanceof IntDebugFlag)) {
+            Log.e(TAG, "Cannot create seekbar preference with IntFlag. Use a launcher preference "
+                    + "flag or pref-backed IntDebugFlag instead");
+            return null;
+        }
+        IntDebugFlag debugflag = (IntDebugFlag) flag;
+        if (debugflag.launcherPrefFlag == null) {
+            Log.e(TAG, "Cannot create seekbar preference with IntDebugFlag. Use a launcher "
+                    + "preference flag or pref-backed IntDebugFlag instead");
+            return null;
+        }
+        SeekBarPreference seekBarPref = createSeekBarPreference(title, min, max, scale,
+                debugflag.launcherPrefFlag);
+        int value = flag.get();
+        seekBarPref.setValue(value);
+        // For some reason the initial value is not triggering the summary update, so call manually.
+        seekBarPref.setSummary(String.valueOf(scale == 1 ? value
+                : value / (float) scale));
+        return seekBarPref;
+    }
+
     /**
      * Create a preference with text and a seek bar. Should be added to a PreferenceCategory.
      *
@@ -401,6 +433,7 @@
             LauncherPrefs.get(getContext()).put(launcherPref, newValue);
             preference.setSummary(String.valueOf(scale == 1 ? newValue
                     : (int) newValue / (float) scale));
+            mFlagTogglerPrefUi.updateMenu();
             return true;
         });
         int value = LauncherPrefs.get(getContext()).get(launcherPref);
diff --git a/quickstep/src/com/android/launcher3/uioverrides/flags/FlagTogglerPrefUi.java b/quickstep/src/com/android/launcher3/uioverrides/flags/FlagTogglerPrefUi.java
index ec0566a..4326c67 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/flags/FlagTogglerPrefUi.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/flags/FlagTogglerPrefUi.java
@@ -34,6 +34,7 @@
 import androidx.preference.PreferenceViewHolder;
 import androidx.preference.SwitchPreference;
 
+import com.android.launcher3.LauncherPrefs;
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.util.ActivityLifecycleCallbacksAdapter;
 
@@ -144,7 +145,7 @@
         switchPreference.setSummary(Html.fromHtml(summary + flag.description));
     }
 
-    private void updateMenu() {
+    public void updateMenu() {
         mFlagsApplyButton.setVisibility(anyChanged() ? View.VISIBLE : View.INVISIBLE);
     }
 
@@ -161,12 +162,22 @@
         return mDataStore.getBoolean(flag.key, defaultValue);
     }
 
+    private int getIntFlagStateFromSharedPrefs(IntDebugFlag flag) {
+        LauncherPrefs prefs = LauncherPrefs.get(mContext);
+        return flag.launcherPrefFlag == null ? flag.get() : prefs.get(flag.launcherPrefFlag);
+    }
+
     private boolean anyChanged() {
         for (DebugFlag flag : FlagsFactory.getDebugFlags()) {
             if (getFlagStateFromSharedPrefs(flag) != flag.get()) {
                 return true;
             }
         }
+        for (IntDebugFlag flag : FlagsFactory.getIntDebugFlags()) {
+            if (getIntFlagStateFromSharedPrefs(flag) != flag.get()) {
+                return true;
+            }
+        }
         return false;
     }
 }
diff --git a/quickstep/src/com/android/launcher3/uioverrides/flags/FlagsFactory.java b/quickstep/src/com/android/launcher3/uioverrides/flags/FlagsFactory.java
index 48d313e..686ed64 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/flags/FlagsFactory.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/flags/FlagsFactory.java
@@ -23,6 +23,8 @@
 import static com.android.launcher3.config.FeatureFlags.FlagState.ENABLED;
 import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
 
+import static java.util.Collections.unmodifiableList;
+
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.provider.DeviceConfig;
@@ -30,7 +32,10 @@
 import android.util.Log;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 
+import com.android.launcher3.ConstantItem;
+import com.android.launcher3.LauncherPrefs;
 import com.android.launcher3.config.FeatureFlags.BooleanFlag;
 import com.android.launcher3.config.FeatureFlags.FlagState;
 import com.android.launcher3.config.FeatureFlags.IntFlag;
@@ -57,7 +62,7 @@
     public static final String NAMESPACE_LAUNCHER = "launcher";
 
     private static final List<DebugFlag> sDebugFlags = new ArrayList<>();
-    private static final List<IntFlag> sIntFlags = new ArrayList<>();
+    private static final List<IntDebugFlag> sIntDebugFlags = new ArrayList<>();
     private static SharedPreferences sSharedPreferences;
 
     static final BooleanFlag TEAMFOOD_FLAG = getReleaseFlag(
@@ -132,11 +137,32 @@
      */
     public static IntFlag getIntFlag(
             int bugId, String key, int defaultValueInCode, String description) {
+        return getIntFlag(bugId, key, defaultValueInCode, description, null);
+    }
+
+    /**
+     * Creates a new integer flag.
+     *
+     * @param launcherPrefFlag Set launcherPrefFlag to non-null if you want
+     * to modify the int flag in Launcher Developer Options and IntDebugFlag
+     * will be backed up by LauncherPrefs. Modified int value will be saved
+     * in LauncherPrefs.
+     */
+    public static IntFlag getIntFlag(
+            int bugId, String key, int defaultValueInCode, String description,
+            @Nullable ConstantItem<Integer> launcherPrefFlag) {
         INSTANCE.mKeySet.add(key);
         int defaultValue = DeviceConfig.getInt(NAMESPACE_LAUNCHER, key, defaultValueInCode);
         if (IS_DEBUG_DEVICE) {
-            IntDeviceFlag flag = new IntDeviceFlag(key, defaultValue, defaultValueInCode);
-            sIntFlags.add(flag);
+            int currentValue;
+            if (launcherPrefFlag == null) {
+                currentValue = defaultValue;
+            } else {
+                currentValue = LauncherPrefs.get(currentApplication()).get(launcherPrefFlag);
+            }
+            IntDebugFlag flag = new IntDebugFlag(key, currentValue, defaultValueInCode,
+                    launcherPrefFlag);
+            sIntDebugFlags.add(flag);
             return flag;
         } else {
             return new IntFlag(defaultValue);
@@ -152,6 +178,15 @@
         }
     }
 
+    static List<IntDebugFlag> getIntDebugFlags() {
+        if (!IS_DEBUG_DEVICE) {
+            return unmodifiableList(Collections.emptyList());
+        }
+        synchronized (sIntDebugFlags) {
+            return unmodifiableList(sIntDebugFlags);
+        }
+    }
+
     /** Returns the SharedPreferences instance backing Debug FeatureFlags. */
     @NonNull
     static SharedPreferences getSharedPreferences() {
@@ -180,8 +215,8 @@
             }
         }
         pw.println("  IntFlags:");
-        synchronized (sIntFlags) {
-            for (IntFlag flag : sIntFlags) {
+        synchronized (sIntDebugFlags) {
+            for (IntFlag flag : sIntDebugFlags) {
                 pw.println("    " + flag);
             }
         }
diff --git a/quickstep/src/com/android/launcher3/uioverrides/flags/IntDeviceFlag.java b/quickstep/src/com/android/launcher3/uioverrides/flags/IntDebugFlag.java
similarity index 73%
rename from quickstep/src/com/android/launcher3/uioverrides/flags/IntDeviceFlag.java
rename to quickstep/src/com/android/launcher3/uioverrides/flags/IntDebugFlag.java
index 4f3b0ae..1350aa8 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/flags/IntDeviceFlag.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/flags/IntDebugFlag.java
@@ -15,16 +15,23 @@
  */
 package com.android.launcher3.uioverrides.flags;
 
+import androidx.annotation.Nullable;
+
+import com.android.launcher3.ConstantItem;
 import com.android.launcher3.config.FeatureFlags.IntFlag;
 
-public class IntDeviceFlag extends IntFlag {
+public class IntDebugFlag extends IntFlag {
     public final String key;
     private final int mDefaultValueInCode;
+    @Nullable
+    public final ConstantItem<Integer> launcherPrefFlag;
 
-    public IntDeviceFlag(String key, int currentValue, int defaultValueInCode) {
+    public IntDebugFlag(String key, int currentValue, int defaultValueInCode,
+            @Nullable ConstantItem<Integer> launcherPrefFlag) {
         super(currentValue);
         this.key = key;
         mDefaultValueInCode = defaultValueInCode;
+        this.launcherPrefFlag = launcherPrefFlag;
     }
 
     @Override
diff --git a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java
index 179612b..d617828 100644
--- a/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java
+++ b/quickstep/src/com/android/quickstep/RecentsAnimationDeviceState.java
@@ -19,7 +19,6 @@
 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
 import static android.view.Display.DEFAULT_DISPLAY;
 
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE;
 import static com.android.launcher3.util.DisplayController.CHANGE_ALL;
 import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
 import static com.android.launcher3.util.DisplayController.CHANGE_ROTATION;
@@ -66,7 +65,6 @@
 import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 
-import com.android.launcher3.LauncherPrefs;
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.util.DisplayController;
 import com.android.launcher3.util.DisplayController.DisplayInfoChangeListener;
@@ -608,7 +606,7 @@
 
         if (FeatureFlags.CUSTOM_LPNH_THRESHOLDS.get()) {
             float customSlopMultiplier =
-                    LauncherPrefs.get(mContext).get(LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE) / 100f;
+                    FeatureFlags.LPNH_SLOP_PERCENTAGE.get() / 100f;
             return customSlopMultiplier * slopMultiplier * touchSlop;
         } else {
             return slopMultiplier * touchSlop;
diff --git a/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java
index 4c0b550..cf8750f 100644
--- a/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java
+++ b/quickstep/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumer.java
@@ -15,7 +15,6 @@
  */
 package com.android.quickstep.inputconsumers;
 
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_TIMEOUT_MS;
 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_DEEP_PRESS_NAVBAR;
 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_DEEP_PRESS_STASHED_TASKBAR;
 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_LONG_PRESS_NAVBAR;
@@ -26,7 +25,6 @@
 import android.view.MotionEvent;
 import android.view.ViewConfiguration;
 
-import com.android.launcher3.LauncherPrefs;
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.logging.StatsLogManager;
 import com.android.launcher3.util.DisplayController;
@@ -63,7 +61,7 @@
         mScreenWidth = DisplayController.INSTANCE.get(context).getInfo().currentSize.x;
         mDeepPressEnabled = FeatureFlags.ENABLE_LPNH_DEEP_PRESS.get();
         if (FeatureFlags.CUSTOM_LPNH_THRESHOLDS.get()) {
-            mLongPressTimeout = LauncherPrefs.get(context).get(LONG_PRESS_NAV_HANDLE_TIMEOUT_MS);
+            mLongPressTimeout = FeatureFlags.LPNH_TIMEOUT_MS.get();
         } else {
             mLongPressTimeout = ViewConfiguration.getLongPressTimeout();
         }
diff --git a/src/com/android/launcher3/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt
index 067d150..3b62ae1 100644
--- a/src/com/android/launcher3/LauncherPrefs.kt
+++ b/src/com/android/launcher3/LauncherPrefs.kt
@@ -20,17 +20,11 @@
 import android.content.SharedPreferences
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener
 import android.util.Log
+import android.view.ViewConfiguration
 import androidx.annotation.VisibleForTesting
 import com.android.launcher3.BuildConfig.WIDGET_ON_FIRST_SCREEN
 import com.android.launcher3.LauncherFiles.DEVICE_PREFERENCES_KEY
 import com.android.launcher3.LauncherFiles.SHARED_PREFERENCES_KEY
-import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_DELAY
-import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_END_SCALE_PERCENT
-import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_ITERATIONS
-import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_SCALE_EXPONENT
-import com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_START_SCALE_PERCENT
-import com.android.launcher3.config.FeatureFlags.LPNH_SLOP_PERCENTAGE
-import com.android.launcher3.config.FeatureFlags.LPNH_TIMEOUT_MS
 import com.android.launcher3.model.DeviceGridState
 import com.android.launcher3.pm.InstallSessionHelper
 import com.android.launcher3.provider.RestoreDbTask
@@ -313,53 +307,45 @@
             )
         @JvmField
         val LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE =
-            nonRestorableItem(
-                "pref_long_press_nav_handle_slop_percentage",
-                LPNH_SLOP_PERCENTAGE.get(),
-                EncryptionType.MOVE_TO_DEVICE_PROTECTED
-            )
+            nonRestorableItem("LPNH_SLOP_PERCENTAGE", 100, EncryptionType.MOVE_TO_DEVICE_PROTECTED)
         @JvmField
         val LONG_PRESS_NAV_HANDLE_TIMEOUT_MS =
             nonRestorableItem(
-                "pref_long_press_nav_handle_timeout_ms",
-                LPNH_TIMEOUT_MS.get(),
+                "LPNH_TIMEOUT_MS",
+                ViewConfiguration.getLongPressTimeout(),
                 EncryptionType.MOVE_TO_DEVICE_PROTECTED
             )
         @JvmField
         val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT =
             nonRestorableItem(
-                "pref_long_press_nav_handle_haptic_hint_start_scale_percent",
-                LPNH_HAPTIC_HINT_START_SCALE_PERCENT.get(),
+                "LPNH_HAPTIC_HINT_START_SCALE_PERCENT",
+                0,
                 EncryptionType.MOVE_TO_DEVICE_PROTECTED
             )
         @JvmField
         val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT =
             nonRestorableItem(
-                "pref_long_press_nav_handle_haptic_hint_end_scale_percent",
-                LPNH_HAPTIC_HINT_END_SCALE_PERCENT.get(),
+                "LPNH_HAPTIC_HINT_END_SCALE_PERCENT",
+                100,
                 EncryptionType.MOVE_TO_DEVICE_PROTECTED
             )
         @JvmField
         val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT =
             nonRestorableItem(
-                "pref_long_press_nav_handle_haptic_hint_scale_exponent",
-                LPNH_HAPTIC_HINT_SCALE_EXPONENT.get(),
+                "LPNH_HAPTIC_HINT_SCALE_EXPONENT",
+                1,
                 EncryptionType.MOVE_TO_DEVICE_PROTECTED
             )
         @JvmField
         val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS =
             nonRestorableItem(
-                "pref_long_press_nav_handle_haptic_hint_iterations",
-                LPNH_HAPTIC_HINT_ITERATIONS.get(),
+                "LPNH_HAPTIC_HINT_ITERATIONS",
+                50,
                 EncryptionType.MOVE_TO_DEVICE_PROTECTED
             )
         @JvmField
         val LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_DELAY =
-            nonRestorableItem(
-                "pref_long_press_nav_handle_haptic_hint_delay",
-                LPNH_HAPTIC_HINT_DELAY.get(),
-                EncryptionType.MOVE_TO_DEVICE_PROTECTED
-            )
+            nonRestorableItem("LPNH_HAPTIC_HINT_DELAY", 0, EncryptionType.MOVE_TO_DEVICE_PROTECTED)
         @JvmField
         val PRIVATE_SPACE_APPS =
             nonRestorableItem("pref_private_space_apps", 0, EncryptionType.MOVE_TO_DEVICE_PROTECTED)
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 1994bd1..6b675c4 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -17,11 +17,17 @@
 package com.android.launcher3.config;
 
 import static com.android.launcher3.BuildConfig.WIDGET_ON_FIRST_SCREEN;
+import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_DELAY;
+import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT;
+import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS;
+import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT;
+import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT;
+import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE;
+import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_TIMEOUT_MS;
 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.uioverrides.flags.FlagsFactory.getDebugFlag;
-import static com.android.launcher3.uioverrides.flags.FlagsFactory.getIntFlag;
 import static com.android.launcher3.uioverrides.flags.FlagsFactory.getReleaseFlag;
 import static com.android.wm.shell.Flags.enableTaskbarNavbarUnification;
 
@@ -31,6 +37,7 @@
 
 import com.android.launcher3.BuildConfig;
 import com.android.launcher3.Flags;
+import com.android.launcher3.uioverrides.flags.FlagsFactory;
 
 import java.util.function.Predicate;
 import java.util.function.ToIntFunction;
@@ -93,6 +100,12 @@
             "ENABLE_DISMISS_PREDICTION_UNDO", DISABLED,
             "Show an 'Undo' snackbar when users dismiss a predicted hotseat item");
 
+    public static final BooleanFlag MOVE_STARTUP_DATA_TO_DEVICE_PROTECTED_STORAGE = getDebugFlag(
+            251502424, "ENABLE_BOOT_AWARE_STARTUP_DATA", DISABLED,
+            "Marks LauncherPref data as (and allows it to) available while the device is"
+                    + " locked. Enabling this causes a 1-time movement of certain SharedPreferences"
+                    + " data. Improves startup latency.");
+
     public static final BooleanFlag CONTINUOUS_VIEW_TREE_CAPTURE = getDebugFlag(270395171,
             "CONTINUOUS_VIEW_TREE_CAPTURE", ENABLED, "Capture View tree every frame");
 
@@ -129,12 +142,14 @@
                     "Shrinks navbar when long pressing if ANIMATE_LPNH is enabled");
 
     public static final IntFlag LPNH_SLOP_PERCENTAGE =
-            getIntFlag(301680992, "LPNH_SLOP_PERCENTAGE", 100,
-                    "Controls touch slop percentage for lpnh");
+            FlagsFactory.getIntFlag(301680992, "LPNH_SLOP_PERCENTAGE", 100,
+                    "Controls touch slop percentage for lpnh",
+                    LONG_PRESS_NAV_HANDLE_SLOP_PERCENTAGE);
 
     public static final IntFlag LPNH_TIMEOUT_MS =
-            getIntFlag(301680992, "LPNH_TIMEOUT_MS", ViewConfiguration.getLongPressTimeout(),
-                    "Controls lpnh timeout in milliseconds");
+            FlagsFactory.getIntFlag(301680992, "LPNH_TIMEOUT_MS",
+                    ViewConfiguration.getLongPressTimeout(),
+                    "Controls lpnh timeout in milliseconds", LONG_PRESS_NAV_HANDLE_TIMEOUT_MS);
 
     public static final BooleanFlag ENABLE_SHOW_KEYBOARD_OPTION_IN_ALL_APPS = getReleaseFlag(
             270394468, "ENABLE_SHOW_KEYBOARD_OPTION_IN_ALL_APPS", ENABLED,
@@ -280,28 +295,35 @@
                     "Enables haptic hint at end of long pressing on the bottom bar nav handle.");
 
     public static final IntFlag LPNH_HAPTIC_HINT_START_SCALE_PERCENT =
-            getIntFlag(309972570, "LPNH_HAPTIC_HINT_START_SCALE_PERCENT", 0,
-            "Haptic hint start scale.");
+            FlagsFactory.getIntFlag(309972570,
+                    "LPNH_HAPTIC_HINT_START_SCALE_PERCENT", 0,
+                    "Haptic hint start scale.",
+                    LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT);
 
     public static final IntFlag LPNH_HAPTIC_HINT_END_SCALE_PERCENT =
-            getIntFlag(309972570, "LPNH_HAPTIC_HINT_END_SCALE_PERCENT", 100,
-            "Haptic hint end scale.");
+            FlagsFactory.getIntFlag(309972570,
+                    "LPNH_HAPTIC_HINT_END_SCALE_PERCENT", 100,
+                    "Haptic hint end scale.", LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT);
 
     public static final IntFlag LPNH_HAPTIC_HINT_SCALE_EXPONENT =
-            getIntFlag(309972570, "LPNH_HAPTIC_HINT_SCALE_EXPONENT", 1,
-            "Haptic hint scale exponent.");
+            FlagsFactory.getIntFlag(309972570,
+                    "LPNH_HAPTIC_HINT_SCALE_EXPONENT", 1,
+                    "Haptic hint scale exponent.",
+                    LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT);
 
     public static final IntFlag LPNH_HAPTIC_HINT_ITERATIONS =
-            getIntFlag(309972570, "LPNH_HAPTIC_HINT_ITERATIONS", 50,
-            "Haptic hint number of iterations.");
+            FlagsFactory.getIntFlag(309972570, "LPNH_HAPTIC_HINT_ITERATIONS",
+                    50,
+                    "Haptic hint number of iterations.",
+                    LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS);
 
     public static final BooleanFlag ENABLE_LPNH_DEEP_PRESS =
             getReleaseFlag(310952290, "ENABLE_LPNH_DEEP_PRESS", ENABLED,
                     "Long press of nav handle is instantly triggered if deep press is detected.");
 
     public static final IntFlag LPNH_HAPTIC_HINT_DELAY =
-            getIntFlag(309972570, "LPNH_HAPTIC_HINT_DELAY", 0,
-                    "Delay before haptic hint starts.");
+            FlagsFactory.getIntFlag(309972570, "LPNH_HAPTIC_HINT_DELAY", 0,
+                    "Delay before haptic hint starts.", LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_DELAY);
 
     // TODO(Block 17): Clean up flags
     // Aconfig migration complete for ENABLE_TASKBAR_PINNING.
@@ -314,12 +336,6 @@
         return ENABLE_TASKBAR_PINNING.get() || Flags.enableTaskbarPinning();
     }
 
-    public static final BooleanFlag MOVE_STARTUP_DATA_TO_DEVICE_PROTECTED_STORAGE = getDebugFlag(
-            251502424, "ENABLE_BOOT_AWARE_STARTUP_DATA", DISABLED,
-            "Marks LauncherPref data as (and allows it to) available while the device is"
-                    + " locked. Enabling this causes a 1-time movement of certain SharedPreferences"
-                    + " data. Improves startup latency.");
-
     // Aconfig migration complete for ENABLE_APP_PAIRS.
     public static final BooleanFlag ENABLE_APP_PAIRS = getDebugFlag(274189428,
             "ENABLE_APP_PAIRS", DISABLED,
diff --git a/src/com/android/launcher3/util/VibratorWrapper.java b/src/com/android/launcher3/util/VibratorWrapper.java
index 4f20bbc..931f036 100644
--- a/src/com/android/launcher3/util/VibratorWrapper.java
+++ b/src/com/android/launcher3/util/VibratorWrapper.java
@@ -19,11 +19,11 @@
 import static android.os.VibrationEffect.createPredefined;
 import static android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED;
 
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_DELAY;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT;
-import static com.android.launcher3.LauncherPrefs.LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_DELAY;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_END_SCALE_PERCENT;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_ITERATIONS;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_SCALE_EXPONENT;
+import static com.android.launcher3.config.FeatureFlags.LPNH_HAPTIC_HINT_START_SCALE_PERCENT;
 import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
 import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR;
 
@@ -41,7 +41,6 @@
 
 import androidx.annotation.Nullable;
 
-import com.android.launcher3.LauncherPrefs;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.config.FeatureFlags;
 
@@ -261,17 +260,11 @@
     public void vibrateForSearchHint() {
         if (FeatureFlags.ENABLE_SEARCH_HAPTIC_HINT.get() && Utilities.ATLEAST_S
                 && mVibrator.areAllPrimitivesSupported(PRIMITIVE_LOW_TICK)) {
-            LauncherPrefs launcherPrefs = LauncherPrefs.get(mContext);
-            float startScale = launcherPrefs.get(
-                    LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_START_SCALE_PERCENT) / 100f;
-            float endScale = launcherPrefs.get(
-                    LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_END_SCALE_PERCENT) / 100f;
-            int scaleExponent = launcherPrefs.get(
-                    LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_SCALE_EXPONENT);
-            int iterations = launcherPrefs.get(
-                    LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_ITERATIONS);
-            int delayMs = launcherPrefs.get(
-                    LONG_PRESS_NAV_HANDLE_HAPTIC_HINT_DELAY);
+            float startScale = LPNH_HAPTIC_HINT_START_SCALE_PERCENT.get() / 100f;
+            float endScale = LPNH_HAPTIC_HINT_END_SCALE_PERCENT.get() / 100f;
+            int scaleExponent = LPNH_HAPTIC_HINT_SCALE_EXPONENT.get();
+            int iterations = LPNH_HAPTIC_HINT_ITERATIONS.get();
+            int delayMs = LPNH_HAPTIC_HINT_DELAY.get();
 
             VibrationEffect.Composition composition = VibrationEffect.startComposition();
             for (int i = 0; i < iterations; i++) {
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/flags/FlagsFactory.java b/src_ui_overrides/com/android/launcher3/uioverrides/flags/FlagsFactory.java
index eb0494e..b193d37 100644
--- a/src_ui_overrides/com/android/launcher3/uioverrides/flags/FlagsFactory.java
+++ b/src_ui_overrides/com/android/launcher3/uioverrides/flags/FlagsFactory.java
@@ -18,6 +18,9 @@
 
 import static com.android.launcher3.config.FeatureFlags.FlagState.ENABLED;
 
+import androidx.annotation.Nullable;
+
+import com.android.launcher3.ConstantItem;
 import com.android.launcher3.config.FeatureFlags.BooleanFlag;
 import com.android.launcher3.config.FeatureFlags.FlagState;
 import com.android.launcher3.config.FeatureFlags.IntFlag;
@@ -55,6 +58,15 @@
     }
 
     /**
+     * Creates a new debug integer flag and it is saved in LauncherPrefs.
+     */
+    public static IntFlag getIntFlag(
+            int bugId, String key, int defaultValueInCode, String description,
+            @Nullable ConstantItem<Integer> launcherPrefFlag) {
+        return new IntFlag(defaultValueInCode);
+    }
+
+    /**
      * Dumps the current flags state to the print writer
      */
     public static void dump(PrintWriter pw) { }