diff options
| author | 2025-01-07 12:06:15 -0800 | |
|---|---|---|
| committer | 2025-01-07 12:06:15 -0800 | |
| commit | 235eac35431fc5bbafce9623e95b6008c922f1ce (patch) | |
| tree | 8fd703258f745b9b4ef2ad185675d51176f5ecad | |
| parent | 164c1cfe244a1731010abbe744f8b36363faaaa8 (diff) | |
| parent | ac5225c3a5d820e08edcec2ecc76cd060e535fcf (diff) | |
Merge "Plumb mouse scrolling speed settings" into main
8 files changed, 123 insertions, 0 deletions
diff --git a/core/java/android/hardware/input/InputSettings.java b/core/java/android/hardware/input/InputSettings.java index 8da630c95135..b380e259577c 100644 --- a/core/java/android/hardware/input/InputSettings.java +++ b/core/java/android/hardware/input/InputSettings.java @@ -78,6 +78,24 @@ public class InputSettings { public static final int DEFAULT_POINTER_SPEED = 0; /** + * Pointer Speed: The minimum (slowest) mouse scrolling speed (-7). + * @hide + */ + public static final int MIN_MOUSE_SCROLLING_SPEED = -7; + + /** + * Pointer Speed: The maximum (fastest) mouse scrolling speed (7). + * @hide + */ + public static final int MAX_MOUSE_SCROLLING_SPEED = 7; + + /** + * Pointer Speed: The default mouse scrolling speed (0). + * @hide + */ + public static final int DEFAULT_MOUSE_SCROLLING_SPEED = 0; + + /** * Bounce Keys Threshold: The default value of the threshold (500 ms). * * @hide @@ -650,6 +668,54 @@ public class InputSettings { } /** + * Gets the mouse scrolling speed. + * + * The returned value only applies when mouse scrolling acceleration is not enabled. + * + * @param context The application context. + * @return The mouse scrolling speed as a value between {@link #MIN_MOUSE_SCROLLING_SPEED} and + * {@link #MAX_MOUSE_SCROLLING_SPEED}, or the default value + * {@link #DEFAULT_MOUSE_SCROLLING_SPEED}. + * + * @hide + */ + public static int getMouseScrollingSpeed(@NonNull Context context) { + if (!isMouseScrollingAccelerationFeatureFlagEnabled()) { + return 0; + } + + return Settings.System.getIntForUser(context.getContentResolver(), + Settings.System.MOUSE_SCROLLING_SPEED, DEFAULT_MOUSE_SCROLLING_SPEED, + UserHandle.USER_CURRENT); + } + + /** + * Sets the mouse scrolling speed, and saves it in the settings. + * + * The new speed will only apply when mouse scrolling acceleration is not enabled. + * + * @param context The application context. + * @param speed The mouse scrolling speed as a value between {@link #MIN_MOUSE_SCROLLING_SPEED} + * and {@link #MAX_MOUSE_SCROLLING_SPEED}, or the default value + * {@link #DEFAULT_MOUSE_SCROLLING_SPEED}. + * + * @hide + */ + @RequiresPermission(Manifest.permission.WRITE_SETTINGS) + public static void setMouseScrollingSpeed(@NonNull Context context, int speed) { + if (isMouseScrollingAccelerationEnabled(context)) { + return; + } + + if (speed < MIN_MOUSE_SCROLLING_SPEED || speed > MAX_MOUSE_SCROLLING_SPEED) { + throw new IllegalArgumentException("speed out of range"); + } + + Settings.System.putIntForUser(context.getContentResolver(), + Settings.System.MOUSE_SCROLLING_SPEED, speed, UserHandle.USER_CURRENT); + } + + /** * Whether mouse vertical scrolling is reversed. This applies only to connected mice. * * @param context The application context. diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 0fe18a647f95..2656a7b58c8d 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -6372,6 +6372,19 @@ public final class Settings { "mouse_pointer_acceleration_enabled"; /** + * Mouse scrolling speed setting. + * + * This is an integer value in a range between -7 and +7, so there are 15 possible values. + * The setting only applies when mouse scrolling acceleration is not enabled. + * -7 = slowest + * 0 = default speed + * +7 = fastest + * + * @hide + */ + public static final String MOUSE_SCROLLING_SPEED = "mouse_scrolling_speed"; + + /** * Pointer fill style, specified by * {@link android.view.PointerIcon.PointerIconVectorStyleFill} constants. * @@ -6623,6 +6636,7 @@ public final class Settings { PRIVATE_SETTINGS.add(MOUSE_POINTER_ACCELERATION_ENABLED); PRIVATE_SETTINGS.add(PREFERRED_REGION); PRIVATE_SETTINGS.add(MOUSE_SCROLLING_ACCELERATION); + PRIVATE_SETTINGS.add(MOUSE_SCROLLING_SPEED); } /** diff --git a/core/proto/android/providers/settings/system.proto b/core/proto/android/providers/settings/system.proto index 0d99200f4e6f..64c9f540a97b 100644 --- a/core/proto/android/providers/settings/system.proto +++ b/core/proto/android/providers/settings/system.proto @@ -229,6 +229,7 @@ message SystemSettingsProto { 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 SettingProto scrolling_speed = 5 [ (android.privacy).dest = DEST_AUTOMATIC ]; } optional Mouse mouse = 38; diff --git a/packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java b/packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java index 5b4ee8bdb339..1f56f10cca7d 100644 --- a/packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java +++ b/packages/SettingsProvider/src/android/provider/settings/backup/SystemSettings.java @@ -109,6 +109,7 @@ public class SystemSettings { Settings.System.LOCALE_PREFERENCES, Settings.System.MOUSE_REVERSE_VERTICAL_SCROLLING, Settings.System.MOUSE_SCROLLING_ACCELERATION, + Settings.System.MOUSE_SCROLLING_SPEED, Settings.System.MOUSE_SWAP_PRIMARY_BUTTON, Settings.System.MOUSE_POINTER_ACCELERATION_ENABLED, Settings.System.TOUCHPAD_POINTER_SPEED, diff --git a/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java b/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java index 0432eeacec4d..4d98a11bdfe7 100644 --- a/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java +++ b/packages/SettingsProvider/src/android/provider/settings/validators/SystemSettingsValidators.java @@ -227,6 +227,7 @@ public class SystemSettingsValidators { 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.MOUSE_SCROLLING_SPEED, new InclusiveIntegerRangeValidator(-7, 7)); 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); diff --git a/services/core/java/com/android/server/input/InputSettingsObserver.java b/services/core/java/com/android/server/input/InputSettingsObserver.java index febf24edc294..e25ea4b43827 100644 --- a/services/core/java/com/android/server/input/InputSettingsObserver.java +++ b/services/core/java/com/android/server/input/InputSettingsObserver.java @@ -74,6 +74,8 @@ class InputSettingsObserver extends ContentObserver { Map.entry(Settings.System.getUriFor( Settings.System.MOUSE_POINTER_ACCELERATION_ENABLED), (reason) -> updateMouseAccelerationEnabled()), + Map.entry(Settings.System.getUriFor(Settings.System.MOUSE_SCROLLING_SPEED), + (reason) -> updateMouseScrollingSpeed()), Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_POINTER_SPEED), (reason) -> updateTouchpadPointerSpeed()), Map.entry(Settings.System.getUriFor(Settings.System.TOUCHPAD_NATURAL_SCROLLING), @@ -199,6 +201,11 @@ class InputSettingsObserver extends ContentObserver { InputSettings.isMousePointerAccelerationEnabled(mContext)); } + private void updateMouseScrollingSpeed() { + mNative.setMouseScrollingSpeed( + constrainPointerSpeedValue(InputSettings.getMouseScrollingSpeed(mContext))); + } + private void updateTouchpadPointerSpeed() { mNative.setTouchpadPointerSpeed( constrainPointerSpeedValue(InputSettings.getTouchpadPointerSpeed(mContext))); diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java index 7dbde64a6412..d426e8292f14 100644 --- a/services/core/java/com/android/server/input/NativeInputManagerService.java +++ b/services/core/java/com/android/server/input/NativeInputManagerService.java @@ -136,6 +136,8 @@ interface NativeInputManagerService { void setMouseScrollingAccelerationEnabled(boolean enabled); + void setMouseScrollingSpeed(int speed); + void setMouseSwapPrimaryButtonEnabled(boolean enabled); void setMouseAccelerationEnabled(boolean enabled); @@ -428,6 +430,9 @@ interface NativeInputManagerService { public native void setMouseScrollingAccelerationEnabled(boolean enabled); @Override + public native void setMouseScrollingSpeed(int speed); + + @Override public native void setMouseSwapPrimaryButtonEnabled(boolean enabled); @Override diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index 65cf4ee733dd..379e312e58c0 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -346,6 +346,7 @@ public: void setMousePointerAccelerationEnabled(ui::LogicalDisplayId displayId, bool enabled); void setMouseReverseVerticalScrollingEnabled(bool enabled); void setMouseScrollingAccelerationEnabled(bool enabled); + void setMouseScrollingSpeed(int32_t speed); void setMouseSwapPrimaryButtonEnabled(bool enabled); void setMouseAccelerationEnabled(bool enabled); void setTouchpadPointerSpeed(int32_t speed); @@ -500,6 +501,9 @@ private: // True if mouse scrolling acceleration is enabled. bool mouseScrollingAccelerationEnabled{true}; + // The mouse scrolling speed, as a number from -7 (slowest) to 7 (fastest). + int32_t mouseScrollingSpeed{0}; + // True if mouse vertical scrolling is reversed. bool mouseReverseVerticalScrollingEnabled{false}; @@ -843,6 +847,9 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon mLocked.mouseScrollingAccelerationEnabled ? android::os::IInputConstants::DEFAULT_MOUSE_WHEEL_ACCELERATION : 1; + outConfig->wheelVelocityControlParameters.scale = mLocked.mouseScrollingAccelerationEnabled + ? 1 + : exp2f(mLocked.mouseScrollingSpeed * POINTER_SPEED_EXPONENT); outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled; outConfig->pointerCaptureRequest = mLocked.pointerCaptureRequest; @@ -1451,6 +1458,21 @@ void NativeInputManager::setMouseScrollingAccelerationEnabled(bool enabled) { InputReaderConfiguration::Change::POINTER_SPEED); } +void NativeInputManager::setMouseScrollingSpeed(int32_t speed) { + { // acquire lock + std::scoped_lock _l(mLock); + + if (mLocked.mouseScrollingSpeed == speed) { + return; + } + + mLocked.mouseScrollingSpeed = speed; + } // release lock + + mInputManager->getReader().requestRefreshConfiguration( + InputReaderConfiguration::Change::POINTER_SPEED); +} + void NativeInputManager::setMouseSwapPrimaryButtonEnabled(bool enabled) { { // acquire lock std::scoped_lock _l(mLock); @@ -3243,6 +3265,11 @@ static void nativeSetMouseScrollingAccelerationEnabled(JNIEnv* env, jobject nati im->setMouseScrollingAccelerationEnabled(enabled); } +static void nativeSetMouseScrollingSpeed(JNIEnv* env, jobject nativeImplObj, jint speed) { + NativeInputManager* im = getNativeInputManager(env, nativeImplObj); + im->setMouseScrollingSpeed(speed); +} + static void nativeSetMouseReverseVerticalScrollingEnabled(JNIEnv* env, jobject nativeImplObj, bool enabled) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); @@ -3319,6 +3346,7 @@ static const JNINativeMethod gInputManagerMethods[] = { (void*)nativeSetMouseReverseVerticalScrollingEnabled}, {"setMouseScrollingAccelerationEnabled", "(Z)V", (void*)nativeSetMouseScrollingAccelerationEnabled}, + {"setMouseScrollingSpeed", "(I)V", (void*)nativeSetMouseScrollingSpeed}, {"setMouseSwapPrimaryButtonEnabled", "(Z)V", (void*)nativeSetMouseSwapPrimaryButtonEnabled}, {"setMouseAccelerationEnabled", "(Z)V", (void*)nativeSetMouseAccelerationEnabled}, {"setTouchpadPointerSpeed", "(I)V", (void*)nativeSetTouchpadPointerSpeed}, |