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

Commit 1ac357ab authored by Michael Checo's avatar Michael Checo Committed by Android (Google) Code Review
Browse files

Merge "InputSettings: Add mouse acceleration setting" into main

parents d6295092 5105f728
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ 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.pointerAcceleration;
import static com.android.hardware.input.Flags.touchpadSystemGestureDisable;
import static com.android.hardware.input.Flags.touchpadThreeFingerTapShortcut;
import static com.android.hardware.input.Flags.touchpadVisualizer;
@@ -417,6 +418,15 @@ public class InputSettings {
        return mouseSwapPrimaryButton();
    }

    /**
     * Returns true if the feature flag for the pointer acceleration toggle is
     * enabled.
     * @hide
     */
    public static boolean isPointerAccelerationFeatureFlagEnabled() {
        return pointerAcceleration();
    }

    /**
     * Returns true if the touchpad visualizer is allowed to appear.
     *
@@ -719,6 +729,47 @@ public class InputSettings {
                UserHandle.USER_CURRENT);
    }

    /**
     * Whether cursor acceleration is enabled or not for connected mice.
     *
     * @param context The application context.
     *
     * @hide
     */
    public static boolean isMousePointerAccelerationEnabled(@NonNull Context context) {
        if (!isPointerAccelerationFeatureFlagEnabled()) {
            return false;
        }

        return Settings.System.getIntForUser(context.getContentResolver(),
                Settings.System.MOUSE_POINTER_ACCELERATION_ENABLED, 1, UserHandle.USER_CURRENT)
                == 1;
    }

   /**
    * Sets whether mouse acceleration is enabled.
    *
    * When enabled, the mouse cursor moves farther when it is moved faster.
    * When disabled, the mouse cursor speed becomes directly proportional to
    * the speed at which the mouse is moved.
    *
    * @param context The application context.
    * @param enabled Will enable mouse acceleration if true, disable it if
    *                false.
    * @hide
    */
    @RequiresPermission(Manifest.permission.WRITE_SETTINGS)
    public static void setMouseAccelerationEnabled(@NonNull Context context,
            boolean enabled) {
        if (!isPointerAccelerationFeatureFlagEnabled()) {
            return;
        }
        Settings.System.putIntForUser(context.getContentResolver(),
                Settings.System.MOUSE_POINTER_ACCELERATION_ENABLED, enabled ? 1 : 0,
                UserHandle.USER_CURRENT);
    }


    /**
     * Whether Accessibility bounce keys feature is enabled.
     *
+11 −0
Original line number Diff line number Diff line
@@ -6361,6 +6361,16 @@ public final class Settings {
         */
        public static final String MOUSE_SCROLLING_ACCELERATION = "mouse_scrolling_acceleration";
        /**
         * Whether mouse acceleration is enabled.
         *
         * When enabled, the mouse cursor will accelerate as the mouse moves faster.
         *
         * @hide
         */
        public static final String MOUSE_POINTER_ACCELERATION_ENABLED =
                "mouse_pointer_acceleration_enabled";
        /**
         * Pointer fill style, specified by
         * {@link android.view.PointerIcon.PointerIconVectorStyleFill} constants.
@@ -6610,6 +6620,7 @@ public final class Settings {
            PRIVATE_SETTINGS.add(DEFAULT_DEVICE_FONT_SCALE);
            PRIVATE_SETTINGS.add(MOUSE_REVERSE_VERTICAL_SCROLLING);
            PRIVATE_SETTINGS.add(MOUSE_SWAP_PRIMARY_BUTTON);
            PRIVATE_SETTINGS.add(MOUSE_POINTER_ACCELERATION_ENABLED);
            PRIVATE_SETTINGS.add(PREFERRED_REGION);
            PRIVATE_SETTINGS.add(MOUSE_SCROLLING_ACCELERATION);
        }
+1 −0
Original line number Diff line number Diff line
@@ -228,6 +228,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 SettingProto pointer_acceleration_enabled = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
    }

    optional Mouse mouse = 38;
+1 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ public class SystemSettings {
                Settings.System.MOUSE_REVERSE_VERTICAL_SCROLLING,
                Settings.System.MOUSE_SCROLLING_ACCELERATION,
                Settings.System.MOUSE_SWAP_PRIMARY_BUTTON,
                Settings.System.MOUSE_POINTER_ACCELERATION_ENABLED,
                Settings.System.TOUCHPAD_POINTER_SPEED,
                Settings.System.TOUCHPAD_NATURAL_SCROLLING,
                Settings.System.TOUCHPAD_TAP_TO_CLICK,
+1 −0
Original line number Diff line number Diff line
@@ -226,6 +226,7 @@ public class SystemSettingsValidators {
        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.MOUSE_POINTER_ACCELERATION_ENABLED, 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