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

Commit 9ef9d947 authored by YuhanYang's avatar YuhanYang
Browse files

Plumb mouse scrolling acceleration settings

Settings intake request: b/384795606

Bug: 383555305
Bug: 384795606
Test: Local DUT with aconfig flags enabled, verified settings
      updated mouse scrolling acceleration.
Flag: com.android.hardware.input.mouse_scrolling_acceleration
Change-Id: Ia8d9155ed1885cc2875b58ca6de6e5d8947d908b
parent 9039cd29
Loading
Loading
Loading
Loading
+48 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static com.android.hardware.input.Flags.keyboardA11yBounceKeysFlag;
import static com.android.hardware.input.Flags.keyboardA11yMouseKeys;
import static com.android.hardware.input.Flags.keyboardA11ySlowKeysFlag;
import static com.android.hardware.input.Flags.keyboardA11yStickyKeysFlag;
import static com.android.hardware.input.Flags.mouseScrollingAcceleration;
import static com.android.hardware.input.Flags.mouseReverseVerticalScrolling;
import static com.android.hardware.input.Flags.mouseSwapPrimaryButton;
import static com.android.hardware.input.Flags.touchpadSystemGestureDisable;
@@ -391,6 +392,15 @@ public class InputSettings {
        return isCustomizableInputGesturesFeatureFlagEnabled() && touchpadThreeFingerTapShortcut();
    }

    /**
     * Returns true if the feature flag for toggling the mouse scrolling acceleration is enabled.
     *
     * @hide
     */
    public static boolean isMouseScrollingAccelerationFeatureFlagEnabled() {
        return mouseScrollingAcceleration();
    }

    /**
     * Returns true if the feature flag for mouse reverse vertical scrolling is enabled.
     * @hide
@@ -593,7 +603,44 @@ public class InputSettings {
    }

    /**
     * Whether mouse vertical scrolling is enabled, this applies only to connected mice.
     * Whether mouse scrolling acceleration is enabled. This applies only to connected mice.
     *
     * @param context The application context.
     * @return Whether the mouse scrolling is accelerated based on the user's scrolling speed.
     *
     * @hide
     */
    public static boolean isMouseScrollingAccelerationEnabled(@NonNull Context context) {
        if (!isMouseScrollingAccelerationFeatureFlagEnabled()) {
            return true;
        }

        return Settings.System.getIntForUser(context.getContentResolver(),
            Settings.System.MOUSE_SCROLLING_ACCELERATION, 0, UserHandle.USER_CURRENT) != 0;
    }

    /**
     * Sets whether the connected mouse scrolling acceleration is enabled.
     *
     * @param context The application context.
     * @param scrollingAcceleration Whether mouse scrolling acceleration is enabled.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setMouseScrollingAcceleration(@NonNull Context context,
            boolean scrollingAcceleration) {
        if (!isMouseScrollingAccelerationFeatureFlagEnabled()) {
            return;
        }

        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.MOUSE_SCROLLING_ACCELERATION, scrollingAcceleration ? 1 : 0,
                UserHandle.USER_CURRENT);
    }

    /**
     * Whether mouse vertical scrolling is reversed. This applies only to connected mice.
     *
     * @param context The application context.
     * @return Whether the mouse will have its vertical scrolling reversed
+11 −0
Original line number Diff line number Diff line
@@ -6351,6 +6351,16 @@ public final class Settings {
        public static final String MOUSE_SWAP_PRIMARY_BUTTON =
                "mouse_swap_primary_button";
        /**
         * Whether to enable mouse scrolling acceleration.
         *
         * When enabled, mouse scrolling is accelerated based on the user's scrolling speed.
         * When disabled, mouse scrolling speed becomes directly proportional to the speed at which
         * the wheel is turned.
         * @hide
         */
        public static final String MOUSE_SCROLLING_ACCELERATION = "mouse_scrolling_acceleration";
        /**
         * Pointer fill style, specified by
         * {@link android.view.PointerIcon.PointerIconVectorStyleFill} constants.
@@ -6601,6 +6611,7 @@ public final class Settings {
            PRIVATE_SETTINGS.add(MOUSE_REVERSE_VERTICAL_SCROLLING);
            PRIVATE_SETTINGS.add(MOUSE_SWAP_PRIMARY_BUTTON);
            PRIVATE_SETTINGS.add(PREFERRED_REGION);
            PRIVATE_SETTINGS.add(MOUSE_SCROLLING_ACCELERATION);
        }
        /**
+1 −0
Original line number Diff line number Diff line
@@ -227,6 +227,7 @@ message SystemSettingsProto {

        optional SettingProto reverse_vertical_scrolling = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
        optional SettingProto swap_primary_button = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
        optional SettingProto scrolling_acceleration = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
    }

    optional Mouse mouse = 38;
+1 −0
Original line number Diff line number Diff line
@@ -108,6 +108,7 @@ public class SystemSettings {
                Settings.System.AUTO_LAUNCH_MEDIA_CONTROLS,
                Settings.System.LOCALE_PREFERENCES,
                Settings.System.MOUSE_REVERSE_VERTICAL_SCROLLING,
                Settings.System.MOUSE_SCROLLING_ACCELERATION,
                Settings.System.MOUSE_SWAP_PRIMARY_BUTTON,
                Settings.System.TOUCHPAD_POINTER_SPEED,
                Settings.System.TOUCHPAD_NATURAL_SCROLLING,
+1 −0
Original line number Diff line number Diff line
@@ -225,6 +225,7 @@ public class SystemSettingsValidators {
                new InclusiveFloatRangeValidator(DEFAULT_POINTER_SCALE, LARGE_POINTER_SCALE));
        VALIDATORS.put(System.MOUSE_REVERSE_VERTICAL_SCROLLING, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.MOUSE_SWAP_PRIMARY_BUTTON, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.MOUSE_SCROLLING_ACCELERATION, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.TOUCHPAD_POINTER_SPEED, new InclusiveIntegerRangeValidator(-7, 7));
        VALIDATORS.put(System.TOUCHPAD_NATURAL_SCROLLING, BOOLEAN_VALIDATOR);
        VALIDATORS.put(System.TOUCHPAD_TAP_TO_CLICK, BOOLEAN_VALIDATOR);
Loading