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

Commit cac8d992 authored by Michael Checo's avatar Michael Checo
Browse files

Add support to disable touchpad acceleration

Bug: 387184135
Test: atest TouchpadInputMapperUnitTest
Flag: com.android.hardware.input.pointer_acceleration
Change-Id: I4e2c8a1fa79c680573ed5632965093c8ad7a478d
parent a1635a6f
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -150,6 +150,11 @@ struct InputReaderConfiguration {
    // speed setting still affects the scaling factor.
    // speed setting still affects the scaling factor.
    bool mousePointerAccelerationEnabled;
    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
    // Velocity control parameters for touchpad pointer movements on the old touchpad stack (based
    // on TouchInputMapper).
    // on TouchInputMapper).
    //
    //
@@ -284,6 +289,7 @@ struct InputReaderConfiguration {
            mousePointerSpeed(0),
            mousePointerSpeed(0),
            displaysWithMousePointerAccelerationDisabled(),
            displaysWithMousePointerAccelerationDisabled(),
            mousePointerAccelerationEnabled(true),
            mousePointerAccelerationEnabled(true),
            touchpadAccelerationEnabled(true),
            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f,
            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f,
                                             static_cast<float>(
                                             static_cast<float>(
                                                     android::os::IInputConstants::
                                                     android::os::IInputConstants::
+14 −2
Original line number Original line Diff line number Diff line
@@ -59,9 +59,11 @@ const bool DEBUG_TOUCHPAD_GESTURES =
                                  ANDROID_LOG_INFO);
                                  ANDROID_LOG_INFO);


std::vector<double> createAccelerationCurveForSensitivity(int32_t sensitivity,
std::vector<double> createAccelerationCurveForSensitivity(int32_t sensitivity,
                                                          bool accelerationEnabled,
                                                          size_t propertySize) {
                                                          size_t propertySize) {
    std::vector<AccelerationCurveSegment> segments =
    std::vector<AccelerationCurveSegment> segments = accelerationEnabled
            createAccelerationCurveForPointerSensitivity(sensitivity);
            ? createAccelerationCurveForPointerSensitivity(sensitivity)
            : createFlatAccelerationCurve(sensitivity);
    LOG_ALWAYS_FATAL_IF(propertySize < 4 * segments.size());
    LOG_ALWAYS_FATAL_IF(propertySize < 4 * segments.size());
    std::vector<double> output(propertySize, 0);
    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");
        GesturesProp accelCurveProp = mPropertyProvider.getProperty("Pointer Accel Curve");
        accelCurveProp.setRealValues(
        accelCurveProp.setRealValues(
                createAccelerationCurveForSensitivity(config.touchpadPointerSpeed,
                createAccelerationCurveForSensitivity(config.touchpadPointerSpeed,
                                                      config.touchpadAccelerationEnabled,
                                                      accelCurveProp.getCount()));
                                                      accelCurveProp.getCount()));
        mPropertyProvider.getProperty("Use Custom Touchpad Scroll Accel Curve")
        mPropertyProvider.getProperty("Use Custom Touchpad Scroll Accel Curve")
                .setBoolValues({true});
                .setBoolValues({true});
        GesturesProp scrollCurveProp = mPropertyProvider.getProperty("Scroll Accel Curve");
        GesturesProp scrollCurveProp = mPropertyProvider.getProperty("Scroll Accel Curve");
        scrollCurveProp.setRealValues(
        scrollCurveProp.setRealValues(
                createAccelerationCurveForSensitivity(config.touchpadPointerSpeed,
                createAccelerationCurveForSensitivity(config.touchpadPointerSpeed,
                                                      config.touchpadAccelerationEnabled,
                                                      scrollCurveProp.getCount()));
                                                      scrollCurveProp.getCount()));
        mPropertyProvider.getProperty("Scroll X Out Scale").setRealValues({1.0});
        mPropertyProvider.getProperty("Scroll X Out Scale").setRealValues({1.0});
        mPropertyProvider.getProperty("Scroll Y 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;
    return mHardwareProperties;
}
}


std::optional<GesturesProp> TouchpadInputMapper::getGesturePropertyForTesting(
        const std::string& name) {
    if (!mPropertyProvider.hasProperty(name)) {
        return std::nullopt;
    }
    return mPropertyProvider.getProperty(name);
}

} // namespace android
} // namespace android
+2 −0
Original line number Original line Diff line number Diff line
@@ -70,6 +70,8 @@ public:


    std::optional<HardwareProperties> getTouchpadHardwareProperties() override;
    std::optional<HardwareProperties> getTouchpadHardwareProperties() override;


    std::optional<GesturesProp> getGesturePropertyForTesting(const std::string& name);

private:
private:
    void resetGestureInterpreter(nsecs_t when);
    void resetGestureInterpreter(nsecs_t when);
    explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
    explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
+66 −0
Original line number Original line Diff line number Diff line
@@ -18,10 +18,13 @@


#include <android-base/logging.h>
#include <android-base/logging.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <input/AccelerationCurve.h>


#include <log/log.h>
#include <thread>
#include <thread>
#include "InputMapperTest.h"
#include "InputMapperTest.h"
#include "InterfaceMocks.h"
#include "InterfaceMocks.h"
#include "TestConstants.h"
#include "TestEventMatchers.h"
#include "TestEventMatchers.h"


#define TAG "TouchpadInputMapper_test"
#define TAG "TouchpadInputMapper_test"
@@ -190,4 +193,67 @@ TEST_F(TouchpadInputMapperTest, TouchpadHardwareState) {
    mFakePolicy->assertTouchpadHardwareStateNotified();
    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
} // namespace android