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

Commit aa449c9c authored by Michael Wright's avatar Michael Wright
Browse files

Scale the pressure range's max value.

Since the pressure scale is configurable via a idc property, it isn't
guaranteed to always be [0, 1.0]. Unfortunately, we didn't scale the max
value of the MotionRange so we'd incorrectly return a max pressure of
1.0 for all devices, even when they might exceed that range.

Test: adb push \
    $(gettop)/out/target/product/taimen/data/nativetest/inputflinger_tests/InputReader_test \
    /data/nativetest/inputflinger_tests/InputReader_test &&
    adb shell /data/nativetest/inputflinger_tests/InputReader_test

Change-Id: I7ef174941c4faa7d7efdaa3d69107740f58afd2a
parent 3a74e142
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -3705,11 +3705,13 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {


        // Pressure factors.
        // Pressure factors.
        mPressureScale = 0;
        mPressureScale = 0;
        float pressureMax = 1.0;
        if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_PHYSICAL
        if (mCalibration.pressureCalibration == Calibration::PRESSURE_CALIBRATION_PHYSICAL
                || mCalibration.pressureCalibration
                || mCalibration.pressureCalibration
                        == Calibration::PRESSURE_CALIBRATION_AMPLITUDE) {
                        == Calibration::PRESSURE_CALIBRATION_AMPLITUDE) {
            if (mCalibration.havePressureScale) {
            if (mCalibration.havePressureScale) {
                mPressureScale = mCalibration.pressureScale;
                mPressureScale = mCalibration.pressureScale;
                pressureMax = mPressureScale * mRawPointerAxes.pressure.maxValue;
            } else if (mRawPointerAxes.pressure.valid
            } else if (mRawPointerAxes.pressure.valid
                    && mRawPointerAxes.pressure.maxValue != 0) {
                    && mRawPointerAxes.pressure.maxValue != 0) {
                mPressureScale = 1.0f / mRawPointerAxes.pressure.maxValue;
                mPressureScale = 1.0f / mRawPointerAxes.pressure.maxValue;
@@ -3719,7 +3721,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
        mOrientedRanges.pressure.axis = AMOTION_EVENT_AXIS_PRESSURE;
        mOrientedRanges.pressure.axis = AMOTION_EVENT_AXIS_PRESSURE;
        mOrientedRanges.pressure.source = mSource;
        mOrientedRanges.pressure.source = mSource;
        mOrientedRanges.pressure.min = 0;
        mOrientedRanges.pressure.min = 0;
        mOrientedRanges.pressure.max = 1.0;
        mOrientedRanges.pressure.max = pressureMax;
        mOrientedRanges.pressure.flat = 0;
        mOrientedRanges.pressure.flat = 0;
        mOrientedRanges.pressure.fuzz = 0;
        mOrientedRanges.pressure.fuzz = 0;
        mOrientedRanges.pressure.resolution = 0;
        mOrientedRanges.pressure.resolution = 0;
+8 −2
Original line number Original line Diff line number Diff line
@@ -2954,8 +2954,8 @@ const int32_t TouchInputMapperTest::RAW_TOUCH_MIN = 0;
const int32_t TouchInputMapperTest::RAW_TOUCH_MAX = 31;
const int32_t TouchInputMapperTest::RAW_TOUCH_MAX = 31;
const int32_t TouchInputMapperTest::RAW_TOOL_MIN = 0;
const int32_t TouchInputMapperTest::RAW_TOOL_MIN = 0;
const int32_t TouchInputMapperTest::RAW_TOOL_MAX = 15;
const int32_t TouchInputMapperTest::RAW_TOOL_MAX = 15;
const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = RAW_TOUCH_MIN;
const int32_t TouchInputMapperTest::RAW_PRESSURE_MIN = 0;
const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = RAW_TOUCH_MAX;
const int32_t TouchInputMapperTest::RAW_PRESSURE_MAX = 255;
const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7;
const int32_t TouchInputMapperTest::RAW_ORIENTATION_MIN = -7;
const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7;
const int32_t TouchInputMapperTest::RAW_ORIENTATION_MAX = 7;
const int32_t TouchInputMapperTest::RAW_DISTANCE_MIN = 0;
const int32_t TouchInputMapperTest::RAW_DISTANCE_MIN = 0;
@@ -5316,6 +5316,12 @@ TEST_F(MultiTouchInputMapperTest, Process_PressureAxis_AmplitudeCalibration) {
    addConfigurationProperty("touch.pressure.scale", "0.01");
    addConfigurationProperty("touch.pressure.scale", "0.01");
    addMapperAndConfigure(mapper);
    addMapperAndConfigure(mapper);


    InputDeviceInfo info;
    mapper->populateDeviceInfo(&info);
    ASSERT_NO_FATAL_FAILURE(assertMotionRange(info,
            AINPUT_MOTION_RANGE_PRESSURE, AINPUT_SOURCE_TOUCHSCREEN,
            0.0f, RAW_PRESSURE_MAX * 0.01, 0.0f, 0.0f));

    // These calculations are based on the input device calibration documentation.
    // These calculations are based on the input device calibration documentation.
    int32_t rawX = 100;
    int32_t rawX = 100;
    int32_t rawY = 200;
    int32_t rawY = 200;