diff options
author | 2025-01-02 03:14:52 +0000 | |
---|---|---|
committer | 2025-01-17 16:54:34 +0000 | |
commit | cac8d9920584a37798fa97b4548484199eeaacce (patch) | |
tree | cd4c84de5d9c31b98d334bcdf524d14e92585f75 | |
parent | a1635a6f52610fd4847f62c3c149dfdb73dfb5fb (diff) |
Add support to disable touchpad acceleration
Bug: 387184135
Test: atest TouchpadInputMapperUnitTest
Flag: com.android.hardware.input.pointer_acceleration
Change-Id: I4e2c8a1fa79c680573ed5632965093c8ad7a478d
4 files changed, 88 insertions, 2 deletions
diff --git a/services/inputflinger/include/InputReaderBase.h b/services/inputflinger/include/InputReaderBase.h index 404a509247..0eef14f309 100644 --- a/services/inputflinger/include/InputReaderBase.h +++ b/services/inputflinger/include/InputReaderBase.h @@ -150,6 +150,11 @@ struct InputReaderConfiguration { // speed setting still affects the scaling factor. bool mousePointerAccelerationEnabled; + // True if the touchpad should exhibit pointer acceleration. If false, + // a flat acceleration curve (linear scaling) is used, but the user's pointer + // speed setting still affects the scaling factor. + bool touchpadAccelerationEnabled; + // Velocity control parameters for touchpad pointer movements on the old touchpad stack (based // on TouchInputMapper). // @@ -284,6 +289,7 @@ struct InputReaderConfiguration { mousePointerSpeed(0), displaysWithMousePointerAccelerationDisabled(), mousePointerAccelerationEnabled(true), + touchpadAccelerationEnabled(true), pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, static_cast<float>( android::os::IInputConstants:: diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp index 0c094e6cce..0df3364644 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp @@ -59,9 +59,11 @@ const bool DEBUG_TOUCHPAD_GESTURES = ANDROID_LOG_INFO); std::vector<double> createAccelerationCurveForSensitivity(int32_t sensitivity, + bool accelerationEnabled, size_t propertySize) { - std::vector<AccelerationCurveSegment> segments = - createAccelerationCurveForPointerSensitivity(sensitivity); + std::vector<AccelerationCurveSegment> segments = accelerationEnabled + ? createAccelerationCurveForPointerSensitivity(sensitivity) + : createFlatAccelerationCurve(sensitivity); LOG_ALWAYS_FATAL_IF(propertySize < 4 * segments.size()); std::vector<double> output(propertySize, 0); @@ -358,12 +360,14 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when, GesturesProp accelCurveProp = mPropertyProvider.getProperty("Pointer Accel Curve"); accelCurveProp.setRealValues( createAccelerationCurveForSensitivity(config.touchpadPointerSpeed, + config.touchpadAccelerationEnabled, accelCurveProp.getCount())); mPropertyProvider.getProperty("Use Custom Touchpad Scroll Accel Curve") .setBoolValues({true}); GesturesProp scrollCurveProp = mPropertyProvider.getProperty("Scroll Accel Curve"); scrollCurveProp.setRealValues( createAccelerationCurveForSensitivity(config.touchpadPointerSpeed, + config.touchpadAccelerationEnabled, scrollCurveProp.getCount())); mPropertyProvider.getProperty("Scroll X Out Scale").setRealValues({1.0}); mPropertyProvider.getProperty("Scroll Y Out Scale").setRealValues({1.0}); @@ -510,4 +514,12 @@ std::optional<HardwareProperties> TouchpadInputMapper::getTouchpadHardwareProper return mHardwareProperties; } +std::optional<GesturesProp> TouchpadInputMapper::getGesturePropertyForTesting( + const std::string& name) { + if (!mPropertyProvider.hasProperty(name)) { + return std::nullopt; + } + return mPropertyProvider.getProperty(name); +} + } // namespace android diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h index a2c4be9e50..56553c9eea 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h @@ -70,6 +70,8 @@ public: std::optional<HardwareProperties> getTouchpadHardwareProperties() override; + std::optional<GesturesProp> getGesturePropertyForTesting(const std::string& name); + private: void resetGestureInterpreter(nsecs_t when); explicit TouchpadInputMapper(InputDeviceContext& deviceContext, diff --git a/services/inputflinger/tests/TouchpadInputMapper_test.cpp b/services/inputflinger/tests/TouchpadInputMapper_test.cpp index ea69fffeaa..07891145bf 100644 --- a/services/inputflinger/tests/TouchpadInputMapper_test.cpp +++ b/services/inputflinger/tests/TouchpadInputMapper_test.cpp @@ -18,10 +18,13 @@ #include <android-base/logging.h> #include <gtest/gtest.h> +#include <input/AccelerationCurve.h> +#include <log/log.h> #include <thread> #include "InputMapperTest.h" #include "InterfaceMocks.h" +#include "TestConstants.h" #include "TestEventMatchers.h" #define TAG "TouchpadInputMapper_test" @@ -190,4 +193,67 @@ TEST_F(TouchpadInputMapperTest, TouchpadHardwareState) { mFakePolicy->assertTouchpadHardwareStateNotified(); } +TEST_F(TouchpadInputMapperTest, TouchpadAccelerationDisabled) { + mReaderConfiguration.touchpadAccelerationEnabled = false; + mReaderConfiguration.touchpadPointerSpeed = 3; + + std::list<NotifyArgs> args = + mMapper->reconfigure(ARBITRARY_TIME, mReaderConfiguration, + InputReaderConfiguration::Change::TOUCHPAD_SETTINGS); + auto* touchpadMapper = static_cast<TouchpadInputMapper*>(mMapper.get()); + + const auto accelCurvePropsDisabled = + touchpadMapper->getGesturePropertyForTesting("Pointer Accel Curve"); + ASSERT_TRUE(accelCurvePropsDisabled.has_value()); + std::vector<double> curveValuesDisabled = accelCurvePropsDisabled.value().getRealValues(); + std::vector<AccelerationCurveSegment> curve = + createFlatAccelerationCurve(mReaderConfiguration.touchpadPointerSpeed); + double expectedBaseGain = curve[0].baseGain; + ASSERT_EQ(curveValuesDisabled[0], std::numeric_limits<double>::infinity()); + ASSERT_EQ(curveValuesDisabled[1], 0); + ASSERT_NEAR(curveValuesDisabled[2], expectedBaseGain, EPSILON); + ASSERT_EQ(curveValuesDisabled[3], 0); +} + +TEST_F(TouchpadInputMapperTest, TouchpadAccelerationEnabled) { + // Enable touchpad acceleration. + mReaderConfiguration.touchpadAccelerationEnabled = true; + mReaderConfiguration.touchpadPointerSpeed = 3; + + std::list<NotifyArgs> args = + mMapper->reconfigure(ARBITRARY_TIME, mReaderConfiguration, + InputReaderConfiguration::Change::TOUCHPAD_SETTINGS); + ASSERT_THAT(args, testing::IsEmpty()); + + auto* touchpadMapper = static_cast<TouchpadInputMapper*>(mMapper.get()); + + // Get the acceleration curve properties when acceleration is enabled. + const auto accelCurvePropsEnabled = + touchpadMapper->getGesturePropertyForTesting("Pointer Accel Curve"); + ASSERT_TRUE(accelCurvePropsEnabled.has_value()); + + // Get the curve values. + std::vector<double> curveValuesEnabled = accelCurvePropsEnabled.value().getRealValues(); + + // Use createAccelerationCurveForPointerSensitivity to get expected curve segments. + std::vector<AccelerationCurveSegment> expectedCurveSegments = + createAccelerationCurveForPointerSensitivity(mReaderConfiguration.touchpadPointerSpeed); + + // Iterate through the segments and compare the values. + for (size_t i = 0; i < expectedCurveSegments.size(); ++i) { + // Check max speed. + if (std::isinf(expectedCurveSegments[i].maxPointerSpeedMmPerS)) { + ASSERT_TRUE(std::isinf(curveValuesEnabled[i * 4 + 0])); + } else { + ASSERT_NEAR(curveValuesEnabled[i * 4 + 0], + expectedCurveSegments[i].maxPointerSpeedMmPerS, EPSILON); + } + + // Check that the x^2 term is zero. + ASSERT_NEAR(curveValuesEnabled[i * 4 + 1], 0, EPSILON); + ASSERT_NEAR(curveValuesEnabled[i * 4 + 2], expectedCurveSegments[i].baseGain, EPSILON); + ASSERT_NEAR(curveValuesEnabled[i * 4 + 3], expectedCurveSegments[i].reciprocal, EPSILON); + } +} + } // namespace android |