From 13acbd2e715a2ae8433c920dc6c843e503153fc2 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Tue, 14 May 2024 22:36:40 +0000 Subject: 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 --- .../reader/mapper/gestures/GestureConverter.cpp | 1 + .../inputflinger/tests/GestureConverter_test.cpp | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp index ff95857e96..e8e7376e92 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp @@ -331,6 +331,7 @@ std::list 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 = diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index 1132e9284c..64223afbba 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -440,6 +440,43 @@ TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) { EXPECT_THAT(std::get(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 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( + WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT)), + VariantWith( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), + WithCoords(0, 0), + WithGestureScrollDistance(0, 0, EPSILON))), + VariantWith( + 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); -- cgit v1.2.3-59-g8ed1b