Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43a826c5 authored by Anushree Ganjam's avatar Anushree Ganjam Committed by Android (Google) Code Review
Browse files

Merge "Fix the Int value to reflect shared preferences value in TouchInteractionService." into main

parents ac1c83e6 eb5cb757
Loading
Loading
Loading
Loading
+54 −21
Original line number Diff line number Diff line
@@ -21,14 +21,14 @@ import static android.view.View.GONE;
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.provider.Settings;
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 @@ public class DeveloperOptionsUI {

    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 @@ public class DeveloperOptionsUI {
        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 @@ public class DeveloperOptionsUI {
    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 @@ public class DeveloperOptionsUI {
                "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 @@ public class DeveloperOptionsUI {
            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);
+12 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import androidx.preference.PreferenceGroup;
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 @@ public final class FlagTogglerPrefUi implements ActivityLifecycleCallbacksAdapte
        switchPreference.setSummary(Html.fromHtml(summary + flag.description));
    }

    private void updateMenu() {
    public void updateMenu() {
        mFlagsApplyButton.setVisibility(anyChanged() ? View.VISIBLE : View.INVISIBLE);
    }

@@ -161,12 +162,22 @@ public final class FlagTogglerPrefUi implements ActivityLifecycleCallbacksAdapte
        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;
    }
}
+40 −5
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import static com.android.launcher3.config.FeatureFlags.FlagState.DISABLED;
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.provider.DeviceConfig.Properties;
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 class FlagsFactory {
    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 class FlagsFactory {
     */
    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 @@ public class FlagsFactory {
        }
    }

    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 @@ public class FlagsFactory {
            }
        }
        pw.println("  IntFlags:");
        synchronized (sIntFlags) {
            for (IntFlag flag : sIntFlags) {
        synchronized (sIntDebugFlags) {
            for (IntFlag flag : sIntDebugFlags) {
                pw.println("    " + flag);
            }
        }
+9 −2
Original line number Diff line number Diff line
@@ -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
+1 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
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.BinderThread;
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 @@ public class RecentsAnimationDeviceState implements DisplayInfoChangeListener {

        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;
Loading