diff options
| author | 2024-01-19 21:03:11 +0000 | |
|---|---|---|
| committer | 2024-01-19 21:03:11 +0000 | |
| commit | a60c6735939fca6982e397c0dc49614c409a9d11 (patch) | |
| tree | fad9c8999549a6cf7ff6d2bd6c9118a36a3aec72 | |
| parent | 03ab62b17ea470379a1781440eb41433f69989ed (diff) | |
Pointer Icon Refactor: Integrate mouse pointer acceleration
Before the refactoring, there could only be one mouse pointer globally,
so we only needed a boolean toggle for controlling pointer acceleration.
Now, since we can have multiple mouse pointers on different displays, we
need to be able to configure pointer acceleration on a per-display
basis.
Bug: 311651709
Test: atest inputflinger_tests
Test: atest InputManagerServiceTests
Change-Id: I60a8017ac734a392223a661210c8b0c980ca5004
4 files changed, 43 insertions, 31 deletions
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index c1d5ebf6c4ec..67c23fc4db12 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -3475,6 +3475,10 @@ public class InputManagerService extends IInputManager.Stub private void applyAdditionalDisplayInputPropertiesLocked( AdditionalDisplayInputProperties properties) { // Handle changes to each of the individual properties. + // TODO(b/293587049): This approach for updating pointer display properties is only for when + // PointerChoreographer is disabled. Remove this logic when PointerChoreographer is + // permanently enabled. + if (properties.pointerIconVisible != mCurrentDisplayProperties.pointerIconVisible) { mCurrentDisplayProperties.pointerIconVisible = properties.pointerIconVisible; if (properties.pointerIconVisible) { @@ -3493,7 +3497,6 @@ public class InputManagerService extends IInputManager.Stub != mCurrentDisplayProperties.mousePointerAccelerationEnabled) { mCurrentDisplayProperties.mousePointerAccelerationEnabled = properties.mousePointerAccelerationEnabled; - mNative.setMousePointerAccelerationEnabled(properties.mousePointerAccelerationEnabled); } } @@ -3507,10 +3510,15 @@ public class InputManagerService extends IInputManager.Stub mAdditionalDisplayInputProperties.put(displayId, properties); } final boolean oldPointerIconVisible = properties.pointerIconVisible; + final boolean oldMouseAccelerationEnabled = properties.mousePointerAccelerationEnabled; updater.accept(properties); if (oldPointerIconVisible != properties.pointerIconVisible) { mNative.setPointerIconVisibility(displayId, properties.pointerIconVisible); } + if (oldMouseAccelerationEnabled != properties.mousePointerAccelerationEnabled) { + mNative.setMousePointerAccelerationEnabled(displayId, + properties.mousePointerAccelerationEnabled); + } if (properties.allDefaults()) { mAdditionalDisplayInputProperties.remove(displayId); } diff --git a/services/core/java/com/android/server/input/NativeInputManagerService.java b/services/core/java/com/android/server/input/NativeInputManagerService.java index 706db3d37bba..6f5202029998 100644 --- a/services/core/java/com/android/server/input/NativeInputManagerService.java +++ b/services/core/java/com/android/server/input/NativeInputManagerService.java @@ -119,7 +119,7 @@ interface NativeInputManagerService { void setPointerSpeed(int speed); - void setMousePointerAccelerationEnabled(boolean enabled); + void setMousePointerAccelerationEnabled(int displayId, boolean enabled); void setTouchpadPointerSpeed(int speed); @@ -354,7 +354,7 @@ interface NativeInputManagerService { public native void setPointerSpeed(int speed); @Override - public native void setMousePointerAccelerationEnabled(boolean enabled); + public native void setMousePointerAccelerationEnabled(int displayId, boolean enabled); @Override public native void setTouchpadPointerSpeed(int speed); diff --git a/services/core/jni/com_android_server_input_InputManagerService.cpp b/services/core/jni/com_android_server_input_InputManagerService.cpp index ce0efe1aba49..2049331e8efe 100644 --- a/services/core/jni/com_android_server_input_InputManagerService.cpp +++ b/services/core/jni/com_android_server_input_InputManagerService.cpp @@ -46,6 +46,7 @@ #include <com_android_input_flags.h> #include <input/Input.h> #include <input/PointerController.h> +#include <input/PrintTools.h> #include <input/SpriteController.h> #include <inputflinger/InputManager.h> #include <limits.h> @@ -230,10 +231,6 @@ inline static T max(const T& a, const T& b) { return a > b ? a : b; } -static inline const char* toString(bool value) { - return value ? "true" : "false"; -} - static SpriteIcon toSpriteIcon(PointerIcon pointerIcon) { // As a minor optimization, do not make a copy of the PointerIcon bitmap here. The loaded // PointerIcons are only cached by InputManagerService in java, so we can safely assume they @@ -288,7 +285,7 @@ public: void setSystemUiLightsOut(bool lightsOut); void setPointerDisplayId(int32_t displayId); void setPointerSpeed(int32_t speed); - void setMousePointerAccelerationEnabled(bool enabled); + void setMousePointerAccelerationEnabled(int32_t displayId, bool enabled); void setTouchpadPointerSpeed(int32_t speed); void setTouchpadNaturalScrollingEnabled(bool enabled); void setTouchpadTapToClickEnabled(bool enabled); @@ -401,8 +398,8 @@ private: // Pointer speed. int32_t pointerSpeed{0}; - // True if pointer acceleration is enabled for mice. - bool mousePointerAccelerationEnabled{true}; + // Displays on which its associated mice will have pointer acceleration disabled. + std::set<int32_t> displaysWithMousePointerAccelerationDisabled{}; // True if pointer gestures are enabled. bool pointerGesturesEnabled{true}; @@ -493,8 +490,8 @@ void NativeInputManager::dump(std::string& dump) { dump += StringPrintf(INDENT "System UI Lights Out: %s\n", toString(mLocked.systemUiLightsOut)); dump += StringPrintf(INDENT "Pointer Speed: %" PRId32 "\n", mLocked.pointerSpeed); - dump += StringPrintf(INDENT "Mouse Pointer Acceleration: %s\n", - mLocked.mousePointerAccelerationEnabled ? "Enabled" : "Disabled"); + dump += StringPrintf(INDENT "Display with Mouse Pointer Acceleration Disabled: %s\n", + dumpSet(mLocked.displaysWithMousePointerAccelerationDisabled).c_str()); dump += StringPrintf(INDENT "Pointer Gestures Enabled: %s\n", toString(mLocked.pointerGesturesEnabled)); dump += StringPrintf(INDENT "Show Touches: %s\n", toString(mLocked.showTouches)); @@ -677,11 +674,13 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon std::scoped_lock _l(mLock); outConfig->mousePointerSpeed = mLocked.pointerSpeed; - outConfig->mousePointerAccelerationEnabled = mLocked.mousePointerAccelerationEnabled; - outConfig->pointerVelocityControlParameters.scale = exp2f(mLocked.pointerSpeed - * POINTER_SPEED_EXPONENT); + outConfig->displaysWithMousePointerAccelerationDisabled = + mLocked.displaysWithMousePointerAccelerationDisabled; + outConfig->pointerVelocityControlParameters.scale = + exp2f(mLocked.pointerSpeed * POINTER_SPEED_EXPONENT); outConfig->pointerVelocityControlParameters.acceleration = - mLocked.mousePointerAccelerationEnabled + mLocked.displaysWithMousePointerAccelerationDisabled.count( + mLocked.pointerDisplayId) == 0 ? android::os::IInputConstants::DEFAULT_POINTER_ACCELERATION : 1; outConfig->pointerGesturesEnabled = mLocked.pointerGesturesEnabled; @@ -1225,16 +1224,23 @@ void NativeInputManager::setPointerSpeed(int32_t speed) { InputReaderConfiguration::Change::POINTER_SPEED); } -void NativeInputManager::setMousePointerAccelerationEnabled(bool enabled) { +void NativeInputManager::setMousePointerAccelerationEnabled(int32_t displayId, bool enabled) { { // acquire lock std::scoped_lock _l(mLock); - if (mLocked.mousePointerAccelerationEnabled == enabled) { + const bool oldEnabled = + mLocked.displaysWithMousePointerAccelerationDisabled.count(displayId) == 0; + if (oldEnabled == enabled) { return; } - ALOGI("Setting mouse pointer acceleration to %s", toString(enabled)); - mLocked.mousePointerAccelerationEnabled = enabled; + ALOGI("Setting mouse pointer acceleration to %s on display %d", toString(enabled), + displayId); + if (enabled) { + mLocked.displaysWithMousePointerAccelerationDisabled.erase(displayId); + } else { + mLocked.displaysWithMousePointerAccelerationDisabled.emplace(displayId); + } } // release lock mInputManager->getReader().requestRefreshConfiguration( @@ -2176,10 +2182,10 @@ static void nativeSetPointerSpeed(JNIEnv* env, jobject nativeImplObj, jint speed } static void nativeSetMousePointerAccelerationEnabled(JNIEnv* env, jobject nativeImplObj, - jboolean enabled) { + jint displayId, jboolean enabled) { NativeInputManager* im = getNativeInputManager(env, nativeImplObj); - im->setMousePointerAccelerationEnabled(enabled); + im->setMousePointerAccelerationEnabled(displayId, enabled); } static void nativeSetTouchpadPointerSpeed(JNIEnv* env, jobject nativeImplObj, jint speed) { @@ -2806,7 +2812,7 @@ static const JNINativeMethod gInputManagerMethods[] = { (void*)nativeTransferTouchFocus}, {"transferTouch", "(Landroid/os/IBinder;I)Z", (void*)nativeTransferTouch}, {"setPointerSpeed", "(I)V", (void*)nativeSetPointerSpeed}, - {"setMousePointerAccelerationEnabled", "(Z)V", + {"setMousePointerAccelerationEnabled", "(IZ)V", (void*)nativeSetMousePointerAccelerationEnabled}, {"setTouchpadPointerSpeed", "(I)V", (void*)nativeSetTouchpadPointerSpeed}, {"setTouchpadNaturalScrollingEnabled", "(Z)V", diff --git a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt index 60a9f0b4332b..256a4696b763 100644 --- a/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt +++ b/tests/Input/src/com/android/server/input/InputManagerServiceTests.kt @@ -295,13 +295,13 @@ class InputManagerServiceTests { verify(native).setPointerIconVisibility(10, false) verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL)) localService.setMousePointerAccelerationEnabled(false, 10) - verify(native).setMousePointerAccelerationEnabled(eq(false)) + verify(native).setMousePointerAccelerationEnabled(10, false) service.onDisplayRemoved(10) verify(native).setPointerIconVisibility(10, true) verify(native).displayRemoved(eq(10)) verify(native).setPointerIconType(eq(PointerIcon.TYPE_NOT_SPECIFIED)) - verify(native).setMousePointerAccelerationEnabled(true) + verify(native).setMousePointerAccelerationEnabled(10, true) verifyNoMoreInteractions(native) // This call should not block because the virtual mouse pointer override was never removed. @@ -319,26 +319,24 @@ class InputManagerServiceTests { verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL)) verify(native).setPointerIconVisibility(10, false) localService.setMousePointerAccelerationEnabled(false, 10) - verify(native).setMousePointerAccelerationEnabled(eq(false)) + verify(native).setMousePointerAccelerationEnabled(10, false) localService.setPointerIconVisible(true, 10) verify(native).setPointerIconType(eq(PointerIcon.TYPE_NOT_SPECIFIED)) verify(native).setPointerIconVisibility(10, true) localService.setMousePointerAccelerationEnabled(true, 10) - verify(native).setMousePointerAccelerationEnabled(eq(true)) + verify(native).setMousePointerAccelerationEnabled(10, true) - // Verify that setting properties on a different display is not propagated until the - // pointer is moved to that display. localService.setPointerIconVisible(false, 20) verify(native).setPointerIconVisibility(20, false) localService.setMousePointerAccelerationEnabled(false, 20) + verify(native).setMousePointerAccelerationEnabled(20, false) verifyNoMoreInteractions(native) clearInvocations(native) setVirtualMousePointerDisplayIdAndVerify(20) verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL)) - verify(native).setMousePointerAccelerationEnabled(eq(false)) } @Test @@ -347,12 +345,12 @@ class InputManagerServiceTests { localService.setMousePointerAccelerationEnabled(false, 10) verify(native).setPointerIconVisibility(10, false) + verify(native).setMousePointerAccelerationEnabled(10, false) verifyNoMoreInteractions(native) setVirtualMousePointerDisplayIdAndVerify(10) verify(native).setPointerIconType(eq(PointerIcon.TYPE_NULL)) - verify(native).setMousePointerAccelerationEnabled(eq(false)) } @Test |