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

Commit 13acbd2e authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

GestureConverter: Reset fake finger on scroll start

The following recent cleanup CL introduced a bug where the fake finger
position was not being reset after a scroll gesture ends:
I02bd7c8f4c4126c9ae7d2fdffd94175b37478925

Fix the newly introduced bug and add a test case.

Fixes: 340417860
Test: atest inputflinger_tests
Change-Id: I747ba4ace6d09424c10925cdd7a1f4b0ad6a6249
parent 018faea1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -331,6 +331,7 @@ std::list<NotifyArgs> GestureConverter::handleScroll(nsecs_t when, nsecs_t readT
        out += exitHover(when, readTime);

        mCurrentClassification = MotionClassification::TWO_FINGER_SWIPE;
        coords.clear();
        coords.setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 1.0f);
        mDownTime = when;
        NotifyMotionArgs args =
+37 −0
Original line number Diff line number Diff line
@@ -440,6 +440,43 @@ TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
    EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
}

TEST_F(GestureConverterTest, Scroll_ClearsFakeFingerPositionOnSubsequentScrollGestures) {
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
    converter.setDisplayId(ui::LogicalDisplayId::DEFAULT);

    Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 15, -10);
    std::list<NotifyArgs> args =
            converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);

    Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -2, -5);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);

    Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
                         GESTURES_FLING_START);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
    Gesture flingGestureEnd(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, 0,
                            GESTURES_FLING_TAP_DOWN);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGestureEnd);

    // Start a second scoll gesture, and ensure the fake finger is reset to (0, 0), instead of
    // continuing from the position where the last scroll gesture's fake finger ended.
    Gesture secondScrollStart(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 2,
                              14);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, secondScrollStart);
    ASSERT_THAT(args,
                ElementsAre(VariantWith<NotifyMotionArgs>(
                                    WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)),
                            VariantWith<NotifyMotionArgs>(
                                    AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
                                          WithCoords(0, 0),
                                          WithGestureScrollDistance(0, 0, EPSILON))),
                            VariantWith<NotifyMotionArgs>(
                                    AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
                                          WithCoords(2, 14),
                                          WithGestureScrollDistance(-2, -14, EPSILON)))));
}

TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);