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

Commit 195c5f80 authored by Harry Cutts's avatar Harry Cutts
Browse files

Touchpad: correct HardwareState::touch_cnt for palms

The palm filtering logic previously only reduced the
HardwareState::finger_cnt field when the touchpad had identified palms,
not touch_cnt. I suspect that this was leading the Gestures library to
go into T5R2 mode (for touchpads that sometimes report more touches than
they can track), meaning that palms sometimes caused tap-to-clicks. I
can't reproduce this exact issue myself, but correcting this
inconsistency is good to do anyway.

Bug: 275616121
Test: atest inputflinger_tests:HardwareStateConverterTest
Test: check debug logs to verify palms don't cause touch_cnt to increase
Change-Id: Ic7b22864214351875afe9969fdbaab42db9d7877
parent f30d7a20
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -81,11 +81,16 @@ SelfContainedHardwareState HardwareStateConverter::produceHardwareState(nsecs_t
    }

    schs.fingers.clear();
    size_t numPalms = 0;
    for (size_t i = 0; i < mMotionAccumulator.getSlotCount(); i++) {
        MultiTouchMotionAccumulator::Slot slot = mMotionAccumulator.getSlot(i);
        if (!slot.isInUse()) {
            continue;
        }
        // Some touchpads continue to report contacts even after they've identified them as palms.
        // We want to exclude these contacts from the HardwareStates.
        if (!slot.isInUse() || slot.getToolType() == ToolType::PALM) {
        if (slot.getToolType() == ToolType::PALM) {
            numPalms++;
            continue;
        }

@@ -103,7 +108,7 @@ SelfContainedHardwareState HardwareStateConverter::produceHardwareState(nsecs_t
    }
    schs.state.fingers = schs.fingers.data();
    schs.state.finger_cnt = schs.fingers.size();
    schs.state.touch_cnt = mTouchButtonAccumulator.getTouchCount();
    schs.state.touch_cnt = mTouchButtonAccumulator.getTouchCount() - numPalms;
    return schs;
}

+7 −0
Original line number Diff line number Diff line
@@ -196,8 +196,10 @@ TEST_F(HardwareStateConverterTest, OnePalm) {
    processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 100);

    processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOUCH, 1);
    processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOOL_FINGER, 1);
    std::optional<SelfContainedHardwareState> schs = processSync(ARBITRARY_TIME);
    ASSERT_TRUE(schs.has_value());
    EXPECT_EQ(0, schs->state.touch_cnt);
    EXPECT_EQ(0, schs->state.finger_cnt);
}

@@ -209,9 +211,11 @@ TEST_F(HardwareStateConverterTest, OneFingerTurningIntoAPalm) {
    processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 100);

    processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOUCH, 1);
    processAxis(ARBITRARY_TIME, EV_KEY, BTN_TOOL_FINGER, 1);

    std::optional<SelfContainedHardwareState> schs = processSync(ARBITRARY_TIME);
    ASSERT_TRUE(schs.has_value());
    EXPECT_EQ(1, schs->state.touch_cnt);
    EXPECT_EQ(1, schs->state.finger_cnt);

    processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_PALM);
@@ -220,6 +224,7 @@ TEST_F(HardwareStateConverterTest, OneFingerTurningIntoAPalm) {

    schs = processSync(ARBITRARY_TIME);
    ASSERT_TRUE(schs.has_value());
    EXPECT_EQ(0, schs->state.touch_cnt);
    ASSERT_EQ(0, schs->state.finger_cnt);

    processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_X, 53);
@@ -227,6 +232,7 @@ TEST_F(HardwareStateConverterTest, OneFingerTurningIntoAPalm) {

    schs = processSync(ARBITRARY_TIME);
    ASSERT_TRUE(schs.has_value());
    EXPECT_EQ(0, schs->state.touch_cnt);
    EXPECT_EQ(0, schs->state.finger_cnt);

    processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_TOOL_TYPE, MT_TOOL_FINGER);
@@ -234,6 +240,7 @@ TEST_F(HardwareStateConverterTest, OneFingerTurningIntoAPalm) {
    processAxis(ARBITRARY_TIME, EV_ABS, ABS_MT_POSITION_Y, 95);
    schs = processSync(ARBITRARY_TIME);
    ASSERT_TRUE(schs.has_value());
    EXPECT_EQ(1, schs->state.touch_cnt);
    ASSERT_EQ(1, schs->state.finger_cnt);
    const FingerState& newFinger = schs->state.fingers[0];
    EXPECT_EQ(123, newFinger.tracking_id);