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

Commit 9892a300 authored by Harry Cutts's avatar Harry Cutts
Browse files

Fix touchpad palm filtering logic

When I added this logic [0], I was under the mistaken impression that
the Gesture library required touches that were leaving the pad to be
reported as FingerStates with a tracking ID of -1. It turns out that it
doesn't, and in fact such FingerStates shouldn't be sent to it [1]. This
makes the palm filtering logic simpler, since we can just always ignore
a slot if it has the palm tool type, rather than having to make one last
FingerState for it if was previously a finger.

[0]: Change ID I7d898889d4bf4e8068194d22150c02a69b59c435
[1]: https://crrev.com/c/4360158

Bug: 251196347
Bug: 270041770
Test: atest inputflinger_tests:HardwareStateConverterTest
Test: limited manual testing
Change-Id: I7f70f1b677ba19a472fd1670918a82dfe65c6f39
parent c9572db2
Loading
Loading
Loading
Loading
+6 −14
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@
 * limitations under the License.
 */

// clang-format off
#include "../Macros.h"
// clang-format on
#include "gestures/HardwareStateConverter.h"

#include <chrono>
@@ -80,14 +83,9 @@ SelfContainedHardwareState HardwareStateConverter::produceHardwareState(nsecs_t
    schs.fingers.clear();
    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, but still need to report a
        // tracking ID of -1 if a finger turns into a palm.
        const bool isPalm = slot.getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM;
        if (isPalm && mFingerSlots.find(i) == mFingerSlots.end()) {
        // We want to exclude these contacts from the HardwareStates.
        if (!slot.isInUse() || slot.getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) {
            continue;
        }

@@ -101,12 +99,7 @@ SelfContainedHardwareState HardwareStateConverter::produceHardwareState(nsecs_t
        fingerState.orientation = slot.getOrientation();
        fingerState.position_x = slot.getX();
        fingerState.position_y = slot.getY();
        fingerState.tracking_id = isPalm ? -1 : slot.getTrackingId();
        if (fingerState.tracking_id == -1) {
            mFingerSlots.erase(i);
        } else {
            mFingerSlots.insert(i);
        }
        fingerState.tracking_id = slot.getTrackingId();
    }
    schs.state.fingers = schs.fingers.data();
    schs.state.finger_cnt = schs.fingers.size();
@@ -117,7 +110,6 @@ SelfContainedHardwareState HardwareStateConverter::produceHardwareState(nsecs_t
void HardwareStateConverter::reset() {
    mCursorButtonAccumulator.reset(mDeviceContext);
    mTouchButtonAccumulator.reset();
    mFingerSlots.clear();
    mMscTimestamp = 0;
}

+0 −1
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ private:
    MultiTouchMotionAccumulator mMotionAccumulator;
    TouchButtonAccumulator mTouchButtonAccumulator;
    int32_t mMscTimestamp = 0;
    std::set<size_t> mFingerSlots;
};

} // namespace android
+1 −2
Original line number Diff line number Diff line
@@ -231,8 +231,7 @@ TEST_F(HardwareStateConverterTest, OneFingerTurningIntoAPalm) {

    schs = processSync(conv, time);
    ASSERT_TRUE(schs.has_value());
    ASSERT_EQ(1, schs->state.finger_cnt);
    EXPECT_EQ(-1, schs->state.fingers[0].tracking_id);
    ASSERT_EQ(0, schs->state.finger_cnt);

    processAxis(conv, time, EV_ABS, ABS_MT_POSITION_X, 53);
    processAxis(conv, time, EV_ABS, ABS_MT_POSITION_Y, 97);