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

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

Merge "Add support to disable touchpad acceleration" into main

parents c3aee781 cac8d992
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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),
            displaysWithMouseScalingDisabled(),
            mousePointerAccelerationEnabled(true),
            touchpadAccelerationEnabled(true),
            pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f,
                                             static_cast<float>(
                                                     android::os::IInputConstants::
+14 −2
Original line number Diff line number Diff line
@@ -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
+2 −0
Original line number Diff line number Diff line
@@ -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,
+66 −0
Original line number Diff line number Diff line
@@ -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