blob: 69772af6b3159344047f1d044dbf56e92996c079 [file] [log] [blame]
Harry Cutts4fb941a2022-12-14 19:14:04 +00001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <memory>
18
Arpit Singh3d84add2023-10-10 19:08:29 +000019#include <com_android_input_flags.h>
20#include <flag_macros.h>
Harry Cutts4fb941a2022-12-14 19:14:04 +000021#include <gestures/GestureConverter.h>
22#include <gtest/gtest.h>
Josep del Riod0746382023-07-29 13:18:25 +000023#include <gui/constants.h>
Harry Cutts4fb941a2022-12-14 19:14:04 +000024
25#include "FakeEventHub.h"
26#include "FakeInputReaderPolicy.h"
27#include "FakePointerController.h"
28#include "InstrumentedInputReader.h"
29#include "NotifyArgs.h"
30#include "TestConstants.h"
Prabir Pradhane3b28dd2023-10-06 04:19:29 +000031#include "TestEventMatchers.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000032#include "TestInputListener.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000033#include "include/gestures.h"
Harry Cuttsedf6ce72023-01-04 12:15:53 +000034#include "ui/Rotation.h"
Harry Cutts4fb941a2022-12-14 19:14:04 +000035
36namespace android {
37
Byoungho Jungee6268f2023-10-30 17:27:26 +090038namespace input_flags = com::android::input::flags;
39
Arpit Singh3d84add2023-10-10 19:08:29 +000040namespace {
41
42const auto TOUCHPAD_PALM_REJECTION =
Byoungho Jungee6268f2023-10-30 17:27:26 +090043 ACONFIG_FLAG(input_flags, enable_touchpad_typing_palm_rejection);
Arpit Singh33a10a62023-10-12 13:06:54 +000044const auto TOUCHPAD_PALM_REJECTION_V2 =
45 ACONFIG_FLAG(input_flags, enable_v2_touchpad_typing_palm_rejection);
Arpit Singh3d84add2023-10-10 19:08:29 +000046
47} // namespace
48
Harry Cutts4fb941a2022-12-14 19:14:04 +000049using testing::AllOf;
Harry Cutts5f26e952023-11-30 18:20:27 +000050using testing::ElementsAre;
51using testing::VariantWith;
Harry Cutts4fb941a2022-12-14 19:14:04 +000052
Byoungho Jungee6268f2023-10-30 17:27:26 +090053class GestureConverterTestBase : public testing::Test {
Harry Cutts4fb941a2022-12-14 19:14:04 +000054protected:
55 static constexpr int32_t DEVICE_ID = END_RESERVED_ID + 1000;
Harry Cuttsc5748d12022-12-02 17:30:18 +000056 static constexpr int32_t EVENTHUB_ID = 1;
Harry Cutts4fb941a2022-12-14 19:14:04 +000057 static constexpr stime_t ARBITRARY_GESTURE_TIME = 1.2;
Harry Cuttsb1e83552022-12-20 11:02:26 +000058 static constexpr float POINTER_X = 500;
Harry Cutts4fb941a2022-12-14 19:14:04 +000059 static constexpr float POINTER_Y = 200;
60
61 void SetUp() {
62 mFakeEventHub = std::make_unique<FakeEventHub>();
63 mFakePolicy = sp<FakeInputReaderPolicy>::make();
64 mFakeListener = std::make_unique<TestInputListener>();
65 mReader = std::make_unique<InstrumentedInputReader>(mFakeEventHub, mFakePolicy,
66 *mFakeListener);
Harry Cuttsc5748d12022-12-02 17:30:18 +000067 mDevice = newDevice();
68 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_X, -500, 500, 0, 0, 20);
69 mFakeEventHub->addAbsoluteAxis(EVENTHUB_ID, ABS_MT_POSITION_Y, -500, 500, 0, 0, 20);
Harry Cutts4fb941a2022-12-14 19:14:04 +000070
71 mFakePointerController = std::make_shared<FakePointerController>();
72 mFakePointerController->setBounds(0, 0, 800 - 1, 480 - 1);
73 mFakePointerController->setPosition(POINTER_X, POINTER_Y);
74 mFakePolicy->setPointerController(mFakePointerController);
75 }
76
Harry Cuttsc5748d12022-12-02 17:30:18 +000077 std::shared_ptr<InputDevice> newDevice() {
78 InputDeviceIdentifier identifier;
79 identifier.name = "device";
80 identifier.location = "USB1";
81 identifier.bus = 0;
82 std::shared_ptr<InputDevice> device =
83 std::make_shared<InputDevice>(mReader->getContext(), DEVICE_ID, /* generation= */ 2,
84 identifier);
85 mReader->pushNextDevice(device);
86 mFakeEventHub->addDevice(EVENTHUB_ID, identifier.name, InputDeviceClass::TOUCHPAD,
87 identifier.bus);
88 mReader->loopOnce();
89 return device;
90 }
91
Harry Cutts4fb941a2022-12-14 19:14:04 +000092 std::shared_ptr<FakeEventHub> mFakeEventHub;
93 sp<FakeInputReaderPolicy> mFakePolicy;
94 std::unique_ptr<TestInputListener> mFakeListener;
95 std::unique_ptr<InstrumentedInputReader> mReader;
Harry Cuttsc5748d12022-12-02 17:30:18 +000096 std::shared_ptr<InputDevice> mDevice;
Harry Cutts4fb941a2022-12-14 19:14:04 +000097 std::shared_ptr<FakePointerController> mFakePointerController;
98};
99
Byoungho Jungee6268f2023-10-30 17:27:26 +0900100class GestureConverterTest : public GestureConverterTestBase {
101protected:
102 void SetUp() override {
103 input_flags::enable_pointer_choreographer(false);
104 GestureConverterTestBase::SetUp();
105 }
106};
107
Harry Cutts4fb941a2022-12-14 19:14:04 +0000108TEST_F(GestureConverterTest, Move) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000109 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
110 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000111 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000112
113 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000114 std::list<NotifyArgs> args =
115 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000116 ASSERT_THAT(args,
117 ElementsAre(VariantWith<NotifyMotionArgs>(
118 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
119 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
120 WithToolType(ToolType::FINGER), WithButtonState(0),
121 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000122
Harry Cuttsb1e83552022-12-20 11:02:26 +0000123 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000124}
125
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000126TEST_F(GestureConverterTest, Move_Rotated) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000127 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
128 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000129 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000130 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000131
132 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000133 std::list<NotifyArgs> args =
134 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000135 ASSERT_THAT(args,
136 ElementsAre(VariantWith<NotifyMotionArgs>(
137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
138 WithCoords(POINTER_X + 10, POINTER_Y + 5), WithRelativeMotion(10, 5),
139 WithToolType(ToolType::FINGER), WithButtonState(0),
140 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000141
Harry Cuttsb1e83552022-12-20 11:02:26 +0000142 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5));
Harry Cuttsedf6ce72023-01-04 12:15:53 +0000143}
144
Harry Cutts4fb941a2022-12-14 19:14:04 +0000145TEST_F(GestureConverterTest, ButtonsChange) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000146 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
147 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000148 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000149
150 // Press left and right buttons at once
151 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
152 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
153 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000154 std::list<NotifyArgs> args =
155 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000156 ASSERT_EQ(3u, args.size());
157
Harry Cutts5f26e952023-11-30 18:20:27 +0000158 ASSERT_THAT(args,
159 ElementsAre(VariantWith<NotifyMotionArgs>(
160 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
161 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
162 AMOTION_EVENT_BUTTON_SECONDARY),
163 WithCoords(POINTER_X, POINTER_Y),
164 WithToolType(ToolType::FINGER),
165 WithDisplayId(ADISPLAY_ID_DEFAULT))),
166 VariantWith<NotifyMotionArgs>(
167 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
168 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
169 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
170 WithCoords(POINTER_X, POINTER_Y),
171 WithToolType(ToolType::FINGER),
172 WithDisplayId(ADISPLAY_ID_DEFAULT))),
173 VariantWith<NotifyMotionArgs>(
174 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
175 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
176 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
177 AMOTION_EVENT_BUTTON_SECONDARY),
178 WithCoords(POINTER_X, POINTER_Y),
179 WithToolType(ToolType::FINGER),
180 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000181
182 // Then release the left button
183 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
184 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
185 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000186 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000187 ASSERT_THAT(args,
188 ElementsAre(VariantWith<NotifyMotionArgs>(
189 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
190 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
191 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
192 WithCoords(POINTER_X, POINTER_Y), WithToolType(ToolType::FINGER),
193 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000194
195 // Finally release the right button
196 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
197 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
198 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000199 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000200 ASSERT_THAT(args,
201 ElementsAre(VariantWith<NotifyMotionArgs>(
202 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
203 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
204 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
205 WithToolType(ToolType::FINGER),
206 WithDisplayId(ADISPLAY_ID_DEFAULT))),
207 VariantWith<NotifyMotionArgs>(
208 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
209 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
210 WithToolType(ToolType::FINGER),
211 WithDisplayId(ADISPLAY_ID_DEFAULT))),
212 VariantWith<NotifyMotionArgs>(
213 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
214 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
215 WithToolType(ToolType::FINGER),
216 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000217}
218
219TEST_F(GestureConverterTest, DragWithButton) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000220 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
221 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000222 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts4fb941a2022-12-14 19:14:04 +0000223
224 // Press the button
225 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
226 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
227 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000228 std::list<NotifyArgs> args =
229 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000230 ASSERT_THAT(args,
231 ElementsAre(VariantWith<NotifyMotionArgs>(
232 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
233 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
234 WithCoords(POINTER_X, POINTER_Y),
235 WithToolType(ToolType::FINGER),
236 WithDisplayId(ADISPLAY_ID_DEFAULT))),
237 VariantWith<NotifyMotionArgs>(
238 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
239 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
240 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
241 WithCoords(POINTER_X, POINTER_Y),
242 WithToolType(ToolType::FINGER),
243 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000244
245 // Move
246 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000247 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000248 ASSERT_THAT(args,
249 ElementsAre(VariantWith<NotifyMotionArgs>(
250 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
251 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
252 WithToolType(ToolType::FINGER),
253 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
254 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000255
Harry Cuttsb1e83552022-12-20 11:02:26 +0000256 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000257
258 // Release the button
259 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
260 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
261 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000262 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000263 ASSERT_THAT(args,
264 ElementsAre(VariantWith<NotifyMotionArgs>(
265 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
266 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
267 WithButtonState(0),
268 WithCoords(POINTER_X - 5, POINTER_Y + 10),
269 WithToolType(ToolType::FINGER),
270 WithDisplayId(ADISPLAY_ID_DEFAULT))),
271 VariantWith<NotifyMotionArgs>(
272 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
273 WithButtonState(0),
274 WithCoords(POINTER_X - 5, POINTER_Y + 10),
275 WithToolType(ToolType::FINGER),
276 WithDisplayId(ADISPLAY_ID_DEFAULT))),
277 VariantWith<NotifyMotionArgs>(
278 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
279 WithButtonState(0),
280 WithCoords(POINTER_X - 5, POINTER_Y + 10),
281 WithToolType(ToolType::FINGER),
282 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts4fb941a2022-12-14 19:14:04 +0000283}
284
Harry Cuttsef400b22022-12-16 21:26:24 +0000285TEST_F(GestureConverterTest, Scroll) {
286 const nsecs_t downTime = 12345;
287 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
288 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000289 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000290
Harry Cuttsa546ba82023-01-13 17:21:00 +0000291 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000292 std::list<NotifyArgs> args =
293 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000294 ASSERT_THAT(args,
295 ElementsAre(VariantWith<NotifyMotionArgs>(
296 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
297 WithCoords(POINTER_X, POINTER_Y),
298 WithGestureScrollDistance(0, 0, EPSILON),
299 WithMotionClassification(
300 MotionClassification::TWO_FINGER_SWIPE),
301 WithToolType(ToolType::FINGER), WithDownTime(downTime),
302 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
303 WithDisplayId(ADISPLAY_ID_DEFAULT))),
304 VariantWith<NotifyMotionArgs>(
305 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
306 WithCoords(POINTER_X, POINTER_Y - 10),
307 WithGestureScrollDistance(0, 10, EPSILON),
308 WithMotionClassification(
309 MotionClassification::TWO_FINGER_SWIPE),
310 WithToolType(ToolType::FINGER),
311 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
312 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000313
Harry Cuttsa546ba82023-01-13 17:21:00 +0000314 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000315 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000316 ASSERT_THAT(args,
317 ElementsAre(VariantWith<NotifyMotionArgs>(
318 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
319 WithCoords(POINTER_X, POINTER_Y - 15),
320 WithGestureScrollDistance(0, 5, EPSILON),
321 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
322 WithToolType(ToolType::FINGER),
323 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
324 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000325
326 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
327 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000328 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000329 ASSERT_THAT(args,
330 ElementsAre(VariantWith<NotifyMotionArgs>(
331 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
332 WithCoords(POINTER_X, POINTER_Y - 15),
333 WithGestureScrollDistance(0, 0, EPSILON),
334 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
335 WithToolType(ToolType::FINGER),
336 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
337 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000338}
339
340TEST_F(GestureConverterTest, Scroll_Rotated) {
341 const nsecs_t downTime = 12345;
342 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
343 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
344 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000345 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000346
Harry Cuttsa546ba82023-01-13 17:21:00 +0000347 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000348 std::list<NotifyArgs> args =
349 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000350 ASSERT_THAT(args,
351 ElementsAre(VariantWith<NotifyMotionArgs>(
352 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
353 WithCoords(POINTER_X, POINTER_Y),
354 WithGestureScrollDistance(0, 0, EPSILON),
355 WithMotionClassification(
356 MotionClassification::TWO_FINGER_SWIPE),
357 WithToolType(ToolType::FINGER), WithDownTime(downTime),
358 WithDisplayId(ADISPLAY_ID_DEFAULT))),
359 VariantWith<NotifyMotionArgs>(
360 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
361 WithCoords(POINTER_X - 10, POINTER_Y),
362 WithGestureScrollDistance(0, 10, EPSILON),
363 WithMotionClassification(
364 MotionClassification::TWO_FINGER_SWIPE),
365 WithToolType(ToolType::FINGER),
366 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000367
Harry Cuttsa546ba82023-01-13 17:21:00 +0000368 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000369 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000370 ASSERT_THAT(args,
371 ElementsAre(VariantWith<NotifyMotionArgs>(
372 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
373 WithCoords(POINTER_X - 15, POINTER_Y),
374 WithGestureScrollDistance(0, 5, EPSILON),
375 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
376 WithToolType(ToolType::FINGER),
377 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000378 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
379 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000380 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000381 ASSERT_THAT(args,
382 ElementsAre(VariantWith<NotifyMotionArgs>(
383 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
384 WithCoords(POINTER_X - 15, POINTER_Y),
385 WithGestureScrollDistance(0, 0, EPSILON),
386 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
387 WithToolType(ToolType::FINGER),
388 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000389}
390
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000391TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
Harry Cuttsef400b22022-12-16 21:26:24 +0000392 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
393 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000394 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsef400b22022-12-16 21:26:24 +0000395
Harry Cuttsa546ba82023-01-13 17:21:00 +0000396 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000397 std::list<NotifyArgs> args =
398 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000399
Harry Cuttsa546ba82023-01-13 17:21:00 +0000400 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000401 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000402
403 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
404 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000405 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsef400b22022-12-16 21:26:24 +0000406
407 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000408 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000409 ASSERT_THAT(args,
410 ElementsAre(VariantWith<NotifyMotionArgs>(
411 AllOf(WithMotionClassification(MotionClassification::NONE),
412 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsef400b22022-12-16 21:26:24 +0000413}
414
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000415TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
Harry Cuttsc5748d12022-12-02 17:30:18 +0000416 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
417 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000418 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000419
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000420 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000421 std::list<NotifyArgs> args =
422 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000423
424 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000425 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000426
427 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
428 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000429 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000430
431 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
432 // need to use another gesture type, like pinch.
433 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
434 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000435 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000436 ASSERT_FALSE(args.empty());
437 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
438}
439
440TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
441 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
442 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000443 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000444
445 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
446 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000447 std::list<NotifyArgs> args =
448 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000449
450 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000451 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000452
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000453 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
454 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000455 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000456 ASSERT_EQ(1u, args.size());
Harry Cutts5f26e952023-11-30 18:20:27 +0000457 ASSERT_THAT(args,
458 ElementsAre(VariantWith<NotifyMotionArgs>(
459 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000460}
461
Harry Cutts8743f182023-05-17 12:03:49 +0000462TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000463 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
464 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000465 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000466
467 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
468 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000469 std::list<NotifyArgs> args =
470 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000471
472 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000473 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000474
475 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
476 // need to use another gesture type, like pinch.
477 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
478 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000479 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000480 ASSERT_FALSE(args.empty());
Harry Cutts8743f182023-05-17 12:03:49 +0000481 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
482 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000483}
484
485TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
486 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
487 // start swiping up and then start moving left or right, it'll return gesture events with only Y
488 // deltas until you lift your fingers and start swiping again. That's why each of these tests
489 // only checks movement in one dimension.
490 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
491 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000492 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000493
494 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
495 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000496 std::list<NotifyArgs> args =
497 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000498 ASSERT_EQ(4u, args.size());
499
500 // Three fake fingers should be created. We don't actually care where they are, so long as they
501 // move appropriately.
502 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
503 ASSERT_THAT(arg,
504 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000505 WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000506 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000507 WithPointerCount(1u), WithToolType(ToolType::FINGER),
508 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000509 PointerCoords finger0Start = arg.pointerCoords[0];
510 args.pop_front();
511 arg = std::get<NotifyMotionArgs>(args.front());
512 ASSERT_THAT(arg,
513 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
514 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000515 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000516 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000517 WithPointerCount(2u), WithToolType(ToolType::FINGER),
518 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000519 PointerCoords finger1Start = arg.pointerCoords[1];
520 args.pop_front();
521 arg = std::get<NotifyMotionArgs>(args.front());
522 ASSERT_THAT(arg,
523 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
524 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000525 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000526 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000527 WithPointerCount(3u), WithToolType(ToolType::FINGER),
528 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000529 PointerCoords finger2Start = arg.pointerCoords[2];
530 args.pop_front();
531
532 arg = std::get<NotifyMotionArgs>(args.front());
533 ASSERT_THAT(arg,
534 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000535 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000536 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000537 WithPointerCount(3u), WithToolType(ToolType::FINGER),
538 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000539 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
540 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
541 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
542 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
543 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
544 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
545
546 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
547 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000548 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000549 ASSERT_EQ(1u, args.size());
550 arg = std::get<NotifyMotionArgs>(args.front());
551 ASSERT_THAT(arg,
552 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000553 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000554 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000555 WithPointerCount(3u), WithToolType(ToolType::FINGER),
556 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000557 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
558 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
559 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
560 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
561 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
562 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
563
564 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000565 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000566 ASSERT_THAT(args,
567 ElementsAre(VariantWith<NotifyMotionArgs>(
568 AllOf(WithMotionAction(
569 AMOTION_EVENT_ACTION_POINTER_UP |
570 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
571 WithGestureOffset(0, 0, EPSILON),
572 WithGestureSwipeFingerCount(3),
573 WithMotionClassification(
574 MotionClassification::MULTI_FINGER_SWIPE),
575 WithPointerCount(3u), WithToolType(ToolType::FINGER),
576 WithDisplayId(ADISPLAY_ID_DEFAULT))),
577 VariantWith<NotifyMotionArgs>(
578 AllOf(WithMotionAction(
579 AMOTION_EVENT_ACTION_POINTER_UP |
580 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
581 WithGestureOffset(0, 0, EPSILON),
582 WithGestureSwipeFingerCount(3),
583 WithMotionClassification(
584 MotionClassification::MULTI_FINGER_SWIPE),
585 WithPointerCount(2u), WithToolType(ToolType::FINGER),
586 WithDisplayId(ADISPLAY_ID_DEFAULT))),
587 VariantWith<NotifyMotionArgs>(
588 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
589 WithGestureOffset(0, 0, EPSILON),
590 WithGestureSwipeFingerCount(3),
591 WithMotionClassification(
592 MotionClassification::MULTI_FINGER_SWIPE),
593 WithPointerCount(1u), WithToolType(ToolType::FINGER),
594 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000595}
596
Harry Cutts94f5bd52023-01-06 18:02:18 +0000597TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) {
598 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
599 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
600 converter.setOrientation(ui::ROTATION_90);
Josep del Riod0746382023-07-29 13:18:25 +0000601 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000602
603 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
604 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000605 std::list<NotifyArgs> args =
606 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000607 ASSERT_EQ(4u, args.size());
608
609 // Three fake fingers should be created. We don't actually care where they are, so long as they
610 // move appropriately.
611 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
612 ASSERT_THAT(arg,
613 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Josep del Riod0746382023-07-29 13:18:25 +0000614 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000615 PointerCoords finger0Start = arg.pointerCoords[0];
616 args.pop_front();
617 arg = std::get<NotifyMotionArgs>(args.front());
618 ASSERT_THAT(arg,
619 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
620 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000621 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
622 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000623 PointerCoords finger1Start = arg.pointerCoords[1];
624 args.pop_front();
625 arg = std::get<NotifyMotionArgs>(args.front());
626 ASSERT_THAT(arg,
627 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
628 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Josep del Riod0746382023-07-29 13:18:25 +0000629 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
630 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000631 PointerCoords finger2Start = arg.pointerCoords[2];
632 args.pop_front();
633
634 arg = std::get<NotifyMotionArgs>(args.front());
635 ASSERT_THAT(arg,
636 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000637 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
638 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000639 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
640 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
641 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
642 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
643 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
644 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
645
646 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
647 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +0000648 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts94f5bd52023-01-06 18:02:18 +0000649 ASSERT_EQ(1u, args.size());
650 arg = std::get<NotifyMotionArgs>(args.front());
651 ASSERT_THAT(arg,
652 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Josep del Riod0746382023-07-29 13:18:25 +0000653 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
654 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000655 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
656 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
657 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
658 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
659 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
660 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
661
662 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000663 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000664 ASSERT_THAT(args,
665 ElementsAre(VariantWith<NotifyMotionArgs>(
666 AllOf(WithMotionAction(
667 AMOTION_EVENT_ACTION_POINTER_UP |
668 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
669 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
670 WithDisplayId(ADISPLAY_ID_DEFAULT))),
671 VariantWith<NotifyMotionArgs>(
672 AllOf(WithMotionAction(
673 AMOTION_EVENT_ACTION_POINTER_UP |
674 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
675 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
676 WithDisplayId(ADISPLAY_ID_DEFAULT))),
677 VariantWith<NotifyMotionArgs>(
678 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
679 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u),
680 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cutts94f5bd52023-01-06 18:02:18 +0000681}
682
Harry Cuttsc5748d12022-12-02 17:30:18 +0000683TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
684 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
685 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000686 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000687
688 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
689 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000690 std::list<NotifyArgs> args =
691 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000692 ASSERT_EQ(5u, args.size());
693
694 // Four fake fingers should be created. We don't actually care where they are, so long as they
695 // move appropriately.
696 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
697 ASSERT_THAT(arg,
698 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
Harry Cutts8743f182023-05-17 12:03:49 +0000699 WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000700 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000701 WithPointerCount(1u), WithToolType(ToolType::FINGER),
702 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000703 PointerCoords finger0Start = arg.pointerCoords[0];
704 args.pop_front();
705 arg = std::get<NotifyMotionArgs>(args.front());
706 ASSERT_THAT(arg,
707 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
708 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000709 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000710 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000711 WithPointerCount(2u), WithToolType(ToolType::FINGER),
712 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000713 PointerCoords finger1Start = arg.pointerCoords[1];
714 args.pop_front();
715 arg = std::get<NotifyMotionArgs>(args.front());
716 ASSERT_THAT(arg,
717 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
718 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000719 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000720 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000721 WithPointerCount(3u), WithToolType(ToolType::FINGER),
722 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000723 PointerCoords finger2Start = arg.pointerCoords[2];
724 args.pop_front();
725 arg = std::get<NotifyMotionArgs>(args.front());
726 ASSERT_THAT(arg,
727 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
728 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
Harry Cutts8743f182023-05-17 12:03:49 +0000729 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000730 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000731 WithPointerCount(4u), WithToolType(ToolType::FINGER),
732 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000733 PointerCoords finger3Start = arg.pointerCoords[3];
734 args.pop_front();
735
736 arg = std::get<NotifyMotionArgs>(args.front());
737 ASSERT_THAT(arg,
738 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000739 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000740 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000741 WithPointerCount(4u), WithToolType(ToolType::FINGER),
742 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000743 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
744 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
745 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
746 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
747 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
748 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
749 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
750 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
751
752 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
753 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000754 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cuttsc5748d12022-12-02 17:30:18 +0000755 ASSERT_EQ(1u, args.size());
756 arg = std::get<NotifyMotionArgs>(args.front());
757 ASSERT_THAT(arg,
758 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
Harry Cutts8743f182023-05-17 12:03:49 +0000759 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
Harry Cuttsc5748d12022-12-02 17:30:18 +0000760 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
Josep del Riod0746382023-07-29 13:18:25 +0000761 WithPointerCount(4u), WithToolType(ToolType::FINGER),
762 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000763 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
764 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
765 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
766 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
767 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
768 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
769 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
770 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
771
772 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +0000773 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000774 ASSERT_THAT(args,
775 ElementsAre(VariantWith<NotifyMotionArgs>(
776 AllOf(WithMotionAction(
777 AMOTION_EVENT_ACTION_POINTER_UP |
778 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
779 WithGestureOffset(0, 0, EPSILON),
780 WithGestureSwipeFingerCount(4),
781 WithMotionClassification(
782 MotionClassification::MULTI_FINGER_SWIPE),
783 WithPointerCount(4u), WithToolType(ToolType::FINGER),
784 WithDisplayId(ADISPLAY_ID_DEFAULT))),
785 VariantWith<NotifyMotionArgs>(
786 AllOf(WithMotionAction(
787 AMOTION_EVENT_ACTION_POINTER_UP |
788 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
789 WithGestureOffset(0, 0, EPSILON),
790 WithGestureSwipeFingerCount(4),
791 WithMotionClassification(
792 MotionClassification::MULTI_FINGER_SWIPE),
793 WithPointerCount(3u), WithToolType(ToolType::FINGER),
794 WithDisplayId(ADISPLAY_ID_DEFAULT))),
795 VariantWith<NotifyMotionArgs>(
796 AllOf(WithMotionAction(
797 AMOTION_EVENT_ACTION_POINTER_UP |
798 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
799 WithGestureOffset(0, 0, EPSILON),
800 WithGestureSwipeFingerCount(4),
801 WithMotionClassification(
802 MotionClassification::MULTI_FINGER_SWIPE),
803 WithPointerCount(2u), WithToolType(ToolType::FINGER),
804 WithDisplayId(ADISPLAY_ID_DEFAULT))),
805 VariantWith<NotifyMotionArgs>(
806 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
807 WithGestureOffset(0, 0, EPSILON),
808 WithGestureSwipeFingerCount(4),
809 WithMotionClassification(
810 MotionClassification::MULTI_FINGER_SWIPE),
811 WithPointerCount(1u), WithToolType(ToolType::FINGER),
812 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsc5748d12022-12-02 17:30:18 +0000813}
814
Harry Cuttsb1e83552022-12-20 11:02:26 +0000815TEST_F(GestureConverterTest, Pinch_Inwards) {
816 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
817 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000818 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000819
820 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
821 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000822 std::list<NotifyArgs> args =
823 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000824 ASSERT_THAT(args,
825 ElementsAre(VariantWith<NotifyMotionArgs>(
826 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
827 WithMotionClassification(MotionClassification::PINCH),
828 WithGesturePinchScaleFactor(1.0f, EPSILON),
829 WithCoords(POINTER_X - 100, POINTER_Y),
830 WithPointerCount(1u), WithToolType(ToolType::FINGER),
831 WithDisplayId(ADISPLAY_ID_DEFAULT))),
832 VariantWith<NotifyMotionArgs>(
833 AllOf(WithMotionAction(
834 AMOTION_EVENT_ACTION_POINTER_DOWN |
835 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
836 WithMotionClassification(MotionClassification::PINCH),
837 WithGesturePinchScaleFactor(1.0f, EPSILON),
838 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
839 WithPointerCount(2u), WithToolType(ToolType::FINGER),
840 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000841
842 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
843 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000844 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000845 ASSERT_THAT(args,
846 ElementsAre(VariantWith<NotifyMotionArgs>(
847 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
848 WithMotionClassification(MotionClassification::PINCH),
849 WithGesturePinchScaleFactor(0.8f, EPSILON),
850 WithPointerCoords(0, POINTER_X - 80, POINTER_Y),
851 WithPointerCoords(1, POINTER_X + 80, POINTER_Y), WithPointerCount(2u),
852 WithToolType(ToolType::FINGER),
853 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000854
855 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
856 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000857 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000858 ASSERT_THAT(args,
859 ElementsAre(VariantWith<NotifyMotionArgs>(
860 AllOf(WithMotionAction(
861 AMOTION_EVENT_ACTION_POINTER_UP |
862 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
863 WithMotionClassification(MotionClassification::PINCH),
864 WithGesturePinchScaleFactor(1.0f, EPSILON),
865 WithPointerCount(2u), WithToolType(ToolType::FINGER),
866 WithDisplayId(ADISPLAY_ID_DEFAULT))),
867 VariantWith<NotifyMotionArgs>(
868 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
869 WithMotionClassification(MotionClassification::PINCH),
870 WithGesturePinchScaleFactor(1.0f, EPSILON),
871 WithPointerCount(1u), WithToolType(ToolType::FINGER),
872 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000873}
874
875TEST_F(GestureConverterTest, Pinch_Outwards) {
876 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
877 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000878 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000879
880 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
881 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000882 std::list<NotifyArgs> args =
883 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000884 ASSERT_THAT(args,
885 ElementsAre(VariantWith<NotifyMotionArgs>(
886 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
887 WithMotionClassification(MotionClassification::PINCH),
888 WithGesturePinchScaleFactor(1.0f, EPSILON),
889 WithCoords(POINTER_X - 100, POINTER_Y),
890 WithPointerCount(1u), WithToolType(ToolType::FINGER),
891 WithDisplayId(ADISPLAY_ID_DEFAULT))),
892 VariantWith<NotifyMotionArgs>(
893 AllOf(WithMotionAction(
894 AMOTION_EVENT_ACTION_POINTER_DOWN |
895 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
896 WithMotionClassification(MotionClassification::PINCH),
897 WithGesturePinchScaleFactor(1.0f, EPSILON),
898 WithPointerCoords(1, POINTER_X + 100, POINTER_Y),
899 WithPointerCount(2u), WithToolType(ToolType::FINGER),
900 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000901
902 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
903 /* dz= */ 1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000904 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000905 ASSERT_THAT(args,
906 ElementsAre(VariantWith<NotifyMotionArgs>(
907 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
908 WithMotionClassification(MotionClassification::PINCH),
909 WithGesturePinchScaleFactor(1.2f, EPSILON),
910 WithPointerCoords(0, POINTER_X - 120, POINTER_Y),
911 WithPointerCoords(1, POINTER_X + 120, POINTER_Y),
912 WithPointerCount(2u), WithToolType(ToolType::FINGER),
913 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000914
915 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
916 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000917 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000918 ASSERT_THAT(args,
919 ElementsAre(VariantWith<NotifyMotionArgs>(
920 AllOf(WithMotionAction(
921 AMOTION_EVENT_ACTION_POINTER_UP |
922 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
923 WithMotionClassification(MotionClassification::PINCH),
924 WithGesturePinchScaleFactor(1.0f, EPSILON),
925 WithPointerCount(2u), WithToolType(ToolType::FINGER),
926 WithDisplayId(ADISPLAY_ID_DEFAULT))),
927 VariantWith<NotifyMotionArgs>(
928 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
929 WithMotionClassification(MotionClassification::PINCH),
930 WithGesturePinchScaleFactor(1.0f, EPSILON),
931 WithPointerCount(1u), WithToolType(ToolType::FINGER),
932 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000933}
934
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000935TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
Harry Cuttsb1e83552022-12-20 11:02:26 +0000936 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
937 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000938 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000939
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000940 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000941 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000942 std::list<NotifyArgs> args =
943 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000944
945 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000946 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000947 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000948
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000949 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
Harry Cuttsb1e83552022-12-20 11:02:26 +0000950 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000951 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsb1e83552022-12-20 11:02:26 +0000952
953 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +0000954 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +0000955 ASSERT_THAT(args,
956 ElementsAre(VariantWith<NotifyMotionArgs>(
957 WithMotionClassification(MotionClassification::NONE))));
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000958}
959
960TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
961 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
962 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000963 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000964
965 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
966 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +0000967 std::list<NotifyArgs> args =
968 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000969
970 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
971 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +0000972 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000973
974 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
975 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +0000976 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000977
978 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
979 // need to use another gesture type, like scroll.
980 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
981 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +0000982 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Harry Cuttsa5f98c92023-05-17 15:05:44 +0000983 ASSERT_FALSE(args.empty());
984 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
Harry Cuttsb1e83552022-12-20 11:02:26 +0000985}
986
Harry Cuttse9b71422023-03-14 16:54:44 +0000987TEST_F(GestureConverterTest, ResetWithButtonPressed) {
988 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
989 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +0000990 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +0000991
992 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
993 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
994 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +0000995 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +0000996
997 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +0000998 ASSERT_THAT(args,
999 ElementsAre(VariantWith<NotifyMotionArgs>(
1000 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1001 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1002 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
1003 WithCoords(POINTER_X, POINTER_Y),
1004 WithToolType(ToolType::FINGER),
1005 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1006 VariantWith<NotifyMotionArgs>(
1007 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1008 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1009 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1010 WithToolType(ToolType::FINGER),
1011 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1012 VariantWith<NotifyMotionArgs>(
1013 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1014 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1015 WithToolType(ToolType::FINGER),
1016 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001017}
1018
1019TEST_F(GestureConverterTest, ResetDuringScroll) {
1020 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1021 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001022 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001023
1024 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001025 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001026
1027 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001028 ASSERT_THAT(args,
1029 ElementsAre(VariantWith<NotifyMotionArgs>(
1030 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1031 WithCoords(POINTER_X, POINTER_Y - 10),
1032 WithGestureScrollDistance(0, 0, EPSILON),
1033 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1034 WithToolType(ToolType::FINGER),
1035 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1036 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001037}
1038
1039TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) {
1040 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1041 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001042 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001043
1044 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1045 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001046 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001047
1048 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001049 ASSERT_THAT(args,
1050 ElementsAre(VariantWith<NotifyMotionArgs>(
1051 AllOf(WithMotionAction(
1052 AMOTION_EVENT_ACTION_POINTER_UP |
1053 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1054 WithGestureOffset(0, 0, EPSILON),
1055 WithMotionClassification(
1056 MotionClassification::MULTI_FINGER_SWIPE),
1057 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1058 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1059 VariantWith<NotifyMotionArgs>(
1060 AllOf(WithMotionAction(
1061 AMOTION_EVENT_ACTION_POINTER_UP |
1062 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1063 WithGestureOffset(0, 0, EPSILON),
1064 WithMotionClassification(
1065 MotionClassification::MULTI_FINGER_SWIPE),
1066 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1067 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1068 VariantWith<NotifyMotionArgs>(
1069 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1070 WithGestureOffset(0, 0, EPSILON),
1071 WithMotionClassification(
1072 MotionClassification::MULTI_FINGER_SWIPE),
1073 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1074 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001075}
1076
1077TEST_F(GestureConverterTest, ResetDuringPinch) {
1078 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1079 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001080 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Harry Cuttse9b71422023-03-14 16:54:44 +00001081
1082 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1083 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001084 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cuttse9b71422023-03-14 16:54:44 +00001085
1086 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00001087 ASSERT_THAT(args,
1088 ElementsAre(VariantWith<NotifyMotionArgs>(
1089 AllOf(WithMotionAction(
1090 AMOTION_EVENT_ACTION_POINTER_UP |
1091 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1092 WithMotionClassification(MotionClassification::PINCH),
1093 WithGesturePinchScaleFactor(1.0f, EPSILON),
1094 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1095 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1096 VariantWith<NotifyMotionArgs>(
1097 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1098 WithMotionClassification(MotionClassification::PINCH),
1099 WithGesturePinchScaleFactor(1.0f, EPSILON),
1100 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1101 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Harry Cuttse9b71422023-03-14 16:54:44 +00001102}
1103
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001104TEST_F(GestureConverterTest, FlingTapDown) {
1105 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1106 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001107 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001108
1109 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1110 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001111 std::list<NotifyArgs> args =
1112 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001113
1114 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1115 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1116 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0.f, 0.f),
Josep del Riod0746382023-07-29 13:18:25 +00001117 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1118 WithDisplayId(ADISPLAY_ID_DEFAULT)));
Prabir Pradhanf7c4b0e2023-05-10 21:25:16 +00001119
1120 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X, POINTER_Y));
1121 ASSERT_TRUE(mFakePointerController->isPointerShown());
1122}
1123
Arpit Singha5ea7c12023-07-05 15:39:25 +00001124TEST_F(GestureConverterTest, Tap) {
1125 // Tap should produce button press/release events
1126 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1127 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001128 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001129
1130 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1131 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001132 std::list<NotifyArgs> args =
1133 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001134
Harry Cutts5f26e952023-11-30 18:20:27 +00001135 ASSERT_THAT(args,
1136 ElementsAre(VariantWith<NotifyMotionArgs>(
1137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1138 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
1139 WithToolType(ToolType::FINGER), WithButtonState(0),
1140 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001141
1142 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1143 /* down= */ GESTURES_BUTTON_LEFT,
1144 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00001145 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001146
Harry Cutts5f26e952023-11-30 18:20:27 +00001147 ASSERT_THAT(args,
1148 ElementsAre(VariantWith<NotifyMotionArgs>(
1149 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1150 WithCoords(POINTER_X, POINTER_Y),
1151 WithRelativeMotion(0.f, 0.f),
1152 WithToolType(ToolType::FINGER),
1153 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1154 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1155 VariantWith<NotifyMotionArgs>(
1156 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1157 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1158 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1159 WithCoords(POINTER_X, POINTER_Y),
1160 WithRelativeMotion(0.f, 0.f),
1161 WithToolType(ToolType::FINGER),
1162 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1163 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1164 VariantWith<NotifyMotionArgs>(
1165 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1166 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1167 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1168 WithRelativeMotion(0.f, 0.f),
1169 WithToolType(ToolType::FINGER), WithButtonState(0),
1170 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1171 VariantWith<NotifyMotionArgs>(
1172 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1173 WithCoords(POINTER_X, POINTER_Y),
1174 WithRelativeMotion(0.f, 0.f),
1175 WithToolType(ToolType::FINGER), WithButtonState(0),
1176 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1177 VariantWith<NotifyMotionArgs>(
1178 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1179 WithCoords(POINTER_X, POINTER_Y),
1180 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1181 WithButtonState(0), WithPressure(0.0f),
1182 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001183}
1184
1185TEST_F(GestureConverterTest, Click) {
1186 // Click should produce button press/release events
1187 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1188 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001189 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001190
1191 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1192 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001193 std::list<NotifyArgs> args =
1194 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001195
Harry Cutts5f26e952023-11-30 18:20:27 +00001196 ASSERT_THAT(args,
1197 ElementsAre(VariantWith<NotifyMotionArgs>(
1198 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1199 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
1200 WithToolType(ToolType::FINGER), WithButtonState(0),
1201 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001202
1203 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1204 /* down= */ GESTURES_BUTTON_LEFT,
1205 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001206 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001207
Harry Cutts5f26e952023-11-30 18:20:27 +00001208 ASSERT_THAT(args,
1209 ElementsAre(VariantWith<NotifyMotionArgs>(
1210 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1211 WithCoords(POINTER_X, POINTER_Y),
1212 WithRelativeMotion(0.f, 0.f),
1213 WithToolType(ToolType::FINGER),
1214 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1215 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1216 VariantWith<NotifyMotionArgs>(
1217 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1218 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1219 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1220 WithCoords(POINTER_X, POINTER_Y),
1221 WithRelativeMotion(0.f, 0.f),
1222 WithToolType(ToolType::FINGER),
1223 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1224 WithPressure(1.0f),
1225 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001226
1227 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1228 /* down= */ GESTURES_BUTTON_NONE,
1229 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001230 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001231 ASSERT_THAT(args,
1232 ElementsAre(VariantWith<NotifyMotionArgs>(
1233 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1234 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1235 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1236 WithRelativeMotion(0.f, 0.f),
1237 WithToolType(ToolType::FINGER), WithButtonState(0),
1238 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1239 VariantWith<NotifyMotionArgs>(
1240 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1241 WithCoords(POINTER_X, POINTER_Y),
1242 WithRelativeMotion(0.f, 0.f),
1243 WithToolType(ToolType::FINGER), WithButtonState(0),
1244 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1245 VariantWith<NotifyMotionArgs>(
1246 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1247 WithCoords(POINTER_X, POINTER_Y),
1248 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1249 WithButtonState(0), WithPressure(0.0f),
1250 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001251}
1252
Arpit Singh3d84add2023-10-10 19:08:29 +00001253TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00001254 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
1255 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1256 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1257
Arpit Singha5ea7c12023-07-05 15:39:25 +00001258 // Tap should be ignored when disabled
1259 mReader->getContext()->setPreventingTouchpadTaps(true);
1260
1261 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1262 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001263 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001264
Arpit Singh82b27a02023-10-16 11:02:19 +00001265 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001266 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001267 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00001268 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001269
Harry Cutts5f26e952023-11-30 18:20:27 +00001270 ASSERT_THAT(args,
1271 ElementsAre(VariantWith<NotifyMotionArgs>(
1272 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1273 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
1274 WithToolType(ToolType::FINGER), WithButtonState(0),
1275 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001276
Arpit Singh82b27a02023-10-16 11:02:19 +00001277 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Arpit Singha5ea7c12023-07-05 15:39:25 +00001278 /* down= */ GESTURES_BUTTON_LEFT,
1279 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00001280 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001281
1282 // no events should be generated
1283 ASSERT_EQ(0u, args.size());
1284
1285 // Future taps should be re-enabled
1286 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1287}
1288
Arpit Singh82b27a02023-10-16 11:02:19 +00001289TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay,
1290 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1291 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
1292
1293 // Tap should be ignored when disabled
1294 mReader->getContext()->setPreventingTouchpadTaps(true);
1295
1296 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1297 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1298 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1299
1300 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1301 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1302 std::list<NotifyArgs> args =
1303 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1304
1305 ASSERT_EQ(1u, args.size());
1306 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1307 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1308 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
1309 WithToolType(ToolType::FINGER), WithButtonState(0), WithPressure(0.0f),
1310 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1311
1312 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
1313 /* down= */ GESTURES_BUTTON_LEFT,
1314 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1315 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1316
1317 // no events should be generated
1318 ASSERT_EQ(0u, args.size());
1319
1320 // Future taps should be re-enabled
1321 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1322
1323 // taps before the threshold should still be ignored
1324 currentTime += TAP_ENABLE_DELAY_NANOS.count();
1325 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1326 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1327 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1328
1329 ASSERT_EQ(1u, args.size());
1330 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1331 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1332
1333 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1334 /* down= */ GESTURES_BUTTON_LEFT,
1335 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1336 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1337
1338 // no events should be generated
1339 ASSERT_EQ(0u, args.size());
1340
1341 // taps after the threshold should be recognised
1342 currentTime += 1;
1343 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
1344 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
1345 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
1346
1347 ASSERT_EQ(1u, args.size());
1348 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1349 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
1350
1351 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
1352 /* down= */ GESTURES_BUTTON_LEFT,
1353 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
1354 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
1355
1356 ASSERT_EQ(5u, args.size());
1357 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1358 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
1359 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
1360 args.pop_front();
1361 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1362 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1363 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
1364 WithRelativeMotion(0.f, 0.f)));
1365 args.pop_front();
1366 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1367 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1368 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
1369 WithRelativeMotion(0.f, 0.f)));
1370 args.pop_front();
1371 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1372 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
1373 WithButtonState(0)));
1374 args.pop_front();
1375 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
1376 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0),
1377 WithButtonState(0)));
1378}
1379
Arpit Singh3d84add2023-10-10 19:08:29 +00001380TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled,
1381 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001382 // Click should still produce button press/release events
1383 mReader->getContext()->setPreventingTouchpadTaps(true);
1384
1385 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1386 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001387 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001388
1389 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
1390 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00001391 std::list<NotifyArgs> args =
1392 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001393
Harry Cutts5f26e952023-11-30 18:20:27 +00001394 ASSERT_THAT(args,
1395 ElementsAre(VariantWith<NotifyMotionArgs>(
1396 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1397 WithCoords(POINTER_X, POINTER_Y), WithRelativeMotion(0, 0),
1398 WithToolType(ToolType::FINGER), WithButtonState(0),
1399 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001400
1401 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1402 /* down= */ GESTURES_BUTTON_LEFT,
1403 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001404 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001405 ASSERT_THAT(args,
1406 ElementsAre(VariantWith<NotifyMotionArgs>(
1407 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1408 WithCoords(POINTER_X, POINTER_Y),
1409 WithRelativeMotion(0.f, 0.f),
1410 WithToolType(ToolType::FINGER),
1411 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1412 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1413 VariantWith<NotifyMotionArgs>(
1414 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1415 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1416 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1417 WithCoords(POINTER_X, POINTER_Y),
1418 WithRelativeMotion(0.f, 0.f),
1419 WithToolType(ToolType::FINGER),
1420 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1421 WithPressure(1.0f),
1422 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001423
1424 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1425 /* down= */ GESTURES_BUTTON_NONE,
1426 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001427 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001428
Harry Cutts5f26e952023-11-30 18:20:27 +00001429 ASSERT_THAT(args,
1430 ElementsAre(VariantWith<NotifyMotionArgs>(
1431 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1432 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1433 WithButtonState(0), WithCoords(POINTER_X, POINTER_Y),
1434 WithRelativeMotion(0.f, 0.f),
1435 WithToolType(ToolType::FINGER), WithButtonState(0),
1436 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1437 VariantWith<NotifyMotionArgs>(
1438 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1439 WithCoords(POINTER_X, POINTER_Y),
1440 WithRelativeMotion(0.f, 0.f),
1441 WithToolType(ToolType::FINGER), WithButtonState(0),
1442 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
1443 VariantWith<NotifyMotionArgs>(
1444 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1445 WithCoords(POINTER_X, POINTER_Y),
1446 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
1447 WithButtonState(0), WithPressure(0.0f),
1448 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001449
1450 // Future taps should be re-enabled
1451 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1452}
1453
Arpit Singh3d84add2023-10-10 19:08:29 +00001454TEST_F_WITH_FLAGS(GestureConverterTest, MoveEnablesTapToClick,
1455 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
Arpit Singha5ea7c12023-07-05 15:39:25 +00001456 // initially disable tap-to-click
1457 mReader->getContext()->setPreventingTouchpadTaps(true);
1458
1459 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1460 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
Josep del Riod0746382023-07-29 13:18:25 +00001461 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
Arpit Singha5ea7c12023-07-05 15:39:25 +00001462
1463 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001464 std::list<NotifyArgs> args =
1465 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001466 ASSERT_THAT(args,
1467 ElementsAre(VariantWith<NotifyMotionArgs>(
1468 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1469 WithCoords(POINTER_X - 5, POINTER_Y + 10), WithRelativeMotion(-5, 10),
1470 WithToolType(ToolType::FINGER), WithButtonState(0),
1471 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Arpit Singha5ea7c12023-07-05 15:39:25 +00001472
1473 ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10));
1474
1475 // Future taps should be re-enabled
1476 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
1477}
1478
Arpit Singh33a10a62023-10-12 13:06:54 +00001479TEST_F_WITH_FLAGS(GestureConverterTest, KeypressCancelsHoverMove,
1480 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
1481 const nsecs_t gestureStartTime = 1000;
1482 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1483 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1484 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1485
1486 // Start a move gesture at gestureStartTime
1487 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
1488 std::list<NotifyArgs> args =
1489 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001490 ASSERT_THAT(args,
1491 ElementsAre(VariantWith<NotifyMotionArgs>(
1492 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001493
1494 // Key presses with IME connection should cancel ongoing move gesture
1495 nsecs_t currentTime = gestureStartTime + 100;
1496 mFakePolicy->setIsInputMethodConnectionActive(true);
1497 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
1498 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1499 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001500 ASSERT_THAT(args,
1501 ElementsAre(VariantWith<NotifyMotionArgs>(
1502 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001503
1504 // any updates in existing move gesture should be ignored
1505 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1506 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
1507 ASSERT_EQ(0u, args.size());
1508
1509 // New gesture should not be affected
1510 currentTime += 100;
1511 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
1512 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001513 ASSERT_THAT(args,
1514 ElementsAre(VariantWith<NotifyMotionArgs>(
1515 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00001516}
1517
Prabir Pradhancc7268a2023-11-16 18:54:13 +00001518// TODO(b/311416205): De-duplicate the test cases after the refactoring is complete and the flagging
1519// logic can be removed.
Byoungho Jungee6268f2023-10-30 17:27:26 +09001520class GestureConverterTestWithChoreographer : public GestureConverterTestBase {
1521protected:
1522 void SetUp() override {
1523 input_flags::enable_pointer_choreographer(true);
1524 GestureConverterTestBase::SetUp();
1525 }
1526};
1527
1528TEST_F(GestureConverterTestWithChoreographer, Move) {
1529 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1530 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1531 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1532
1533 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001534 std::list<NotifyArgs> args =
1535 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001536 ASSERT_THAT(args,
1537 ElementsAre(VariantWith<NotifyMotionArgs>(
1538 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1539 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1540 WithButtonState(0), WithPressure(0.0f),
1541 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001542}
1543
1544TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) {
1545 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1546 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1547 converter.setOrientation(ui::ROTATION_90);
1548 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1549
1550 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001551 std::list<NotifyArgs> args =
1552 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001553 ASSERT_THAT(args,
1554 ElementsAre(VariantWith<NotifyMotionArgs>(
1555 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
1556 WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER),
1557 WithButtonState(0), WithPressure(0.0f),
1558 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001559}
1560
1561TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) {
1562 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1563 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1564 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1565
1566 // Press left and right buttons at once
1567 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1568 /* down= */ GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
1569 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001570 std::list<NotifyArgs> args =
1571 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001572 ASSERT_THAT(args,
1573 ElementsAre(VariantWith<NotifyMotionArgs>(
1574 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1575 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1576 AMOTION_EVENT_BUTTON_SECONDARY),
1577 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1578 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1579 VariantWith<NotifyMotionArgs>(
1580 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1581 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1582 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1583 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1584 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1585 VariantWith<NotifyMotionArgs>(
1586 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1587 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1588 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY |
1589 AMOTION_EVENT_BUTTON_SECONDARY),
1590 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1591 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001592
1593 // Then release the left button
1594 Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1595 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1596 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001597 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, leftUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001598 ASSERT_THAT(args,
1599 ElementsAre(VariantWith<NotifyMotionArgs>(
1600 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1601 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1602 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), WithCoords(0, 0),
1603 WithToolType(ToolType::FINGER),
1604 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001605
1606 // Finally release the right button
1607 Gesture rightUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1608 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_RIGHT,
1609 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001610 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, rightUpGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001611 ASSERT_THAT(args,
1612 ElementsAre(VariantWith<NotifyMotionArgs>(
1613 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1614 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
1615 WithButtonState(0), WithCoords(0, 0),
1616 WithToolType(ToolType::FINGER),
1617 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1618 VariantWith<NotifyMotionArgs>(
1619 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1620 WithButtonState(0), WithCoords(0, 0),
1621 WithToolType(ToolType::FINGER),
1622 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1623 VariantWith<NotifyMotionArgs>(
1624 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1625 WithButtonState(0), WithCoords(0, 0),
1626 WithToolType(ToolType::FINGER),
1627 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001628}
1629
1630TEST_F(GestureConverterTestWithChoreographer, DragWithButton) {
1631 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1632 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1633 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1634
1635 // Press the button
1636 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1637 /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_NONE,
1638 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001639 std::list<NotifyArgs> args =
1640 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001641 ASSERT_THAT(args,
1642 ElementsAre(VariantWith<NotifyMotionArgs>(
1643 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1644 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1645 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1646 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1647 VariantWith<NotifyMotionArgs>(
1648 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
1649 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1650 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
1651 WithCoords(0, 0), WithToolType(ToolType::FINGER),
1652 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001653
1654 // Move
1655 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001656 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001657 ASSERT_THAT(args,
1658 ElementsAre(VariantWith<NotifyMotionArgs>(
1659 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, 0),
1660 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
1661 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), WithPressure(1.0f),
1662 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001663
1664 // Release the button
1665 Gesture upGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1666 /* down= */ GESTURES_BUTTON_NONE, /* up= */ GESTURES_BUTTON_LEFT,
1667 /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00001668 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, upGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001669 ASSERT_THAT(args,
1670 ElementsAre(VariantWith<NotifyMotionArgs>(
1671 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
1672 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
1673 WithButtonState(0), WithCoords(0, 0),
1674 WithToolType(ToolType::FINGER),
1675 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1676 VariantWith<NotifyMotionArgs>(
1677 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1678 WithButtonState(0), WithCoords(0, 0),
1679 WithToolType(ToolType::FINGER),
1680 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1681 VariantWith<NotifyMotionArgs>(
1682 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
1683 WithButtonState(0), WithCoords(0, 0),
1684 WithToolType(ToolType::FINGER),
1685 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001686}
1687
1688TEST_F(GestureConverterTestWithChoreographer, Scroll) {
1689 const nsecs_t downTime = 12345;
1690 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1691 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1692 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1693
1694 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001695 std::list<NotifyArgs> args =
1696 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001697 ASSERT_THAT(args,
1698 ElementsAre(VariantWith<NotifyMotionArgs>(
1699 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1700 WithCoords(0, 0),
1701 WithGestureScrollDistance(0, 0, EPSILON),
1702 WithMotionClassification(
1703 MotionClassification::TWO_FINGER_SWIPE),
1704 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1705 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1706 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1707 VariantWith<NotifyMotionArgs>(
1708 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1709 WithCoords(0, -10),
1710 WithGestureScrollDistance(0, 10, EPSILON),
1711 WithMotionClassification(
1712 MotionClassification::TWO_FINGER_SWIPE),
1713 WithToolType(ToolType::FINGER),
1714 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1715 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001716
1717 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001718 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001719 ASSERT_THAT(args,
1720 ElementsAre(VariantWith<NotifyMotionArgs>(
1721 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -15),
1722 WithGestureScrollDistance(0, 5, EPSILON),
1723 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1724 WithToolType(ToolType::FINGER),
1725 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1726 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001727
1728 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1729 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001730 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001731 ASSERT_THAT(args,
1732 ElementsAre(VariantWith<NotifyMotionArgs>(
1733 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, 0 - 15),
1734 WithGestureScrollDistance(0, 0, EPSILON),
1735 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1736 WithToolType(ToolType::FINGER),
1737 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
1738 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001739}
1740
1741TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) {
1742 const nsecs_t downTime = 12345;
1743 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1744 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1745 converter.setOrientation(ui::ROTATION_90);
1746 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1747
1748 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001749 std::list<NotifyArgs> args =
1750 converter.handleGesture(downTime, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001751 ASSERT_THAT(args,
1752 ElementsAre(VariantWith<NotifyMotionArgs>(
1753 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
1754 WithCoords(0, 0),
1755 WithGestureScrollDistance(0, 0, EPSILON),
1756 WithMotionClassification(
1757 MotionClassification::TWO_FINGER_SWIPE),
1758 WithToolType(ToolType::FINGER), WithDownTime(downTime),
1759 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1760 VariantWith<NotifyMotionArgs>(
1761 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1762 WithCoords(-10, 0),
1763 WithGestureScrollDistance(0, 10, EPSILON),
1764 WithMotionClassification(
1765 MotionClassification::TWO_FINGER_SWIPE),
1766 WithToolType(ToolType::FINGER),
1767 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001768
1769 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001770 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001771 ASSERT_THAT(args,
1772 ElementsAre(VariantWith<NotifyMotionArgs>(
1773 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-15, 0),
1774 WithGestureScrollDistance(0, 5, EPSILON),
1775 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1776 WithToolType(ToolType::FINGER),
1777 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001778
1779 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1780 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001781 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001782 ASSERT_THAT(args,
1783 ElementsAre(VariantWith<NotifyMotionArgs>(
1784 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(-15, 0),
1785 WithGestureScrollDistance(0, 0, EPSILON),
1786 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
1787 WithToolType(ToolType::FINGER),
1788 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001789}
1790
1791TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) {
1792 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1793 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1794 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1795
1796 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001797 std::list<NotifyArgs> args =
1798 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001799
1800 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001801 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001802
1803 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1804 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001805 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001806
1807 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001808 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001809 ASSERT_THAT(args,
1810 ElementsAre(VariantWith<NotifyMotionArgs>(
1811 AllOf(WithMotionClassification(MotionClassification::NONE),
1812 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001813}
1814
1815TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsScrollDistanceAfterGesture) {
1816 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1817 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1818 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1819
1820 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001821 std::list<NotifyArgs> args =
1822 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001823
1824 Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001825 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001826
1827 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
1828 GESTURES_FLING_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001829 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001830
1831 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1832 // need to use another gesture type, like pinch.
1833 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1834 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001835 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001836 ASSERT_FALSE(args.empty());
1837 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
1838}
1839
1840TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
1841 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1842 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1843 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1844
1845 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
1846 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00001847 std::list<NotifyArgs> args =
1848 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001849
1850 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001851 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001852
1853 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5,
1854 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001855 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001856 ASSERT_THAT(args,
1857 ElementsAre(VariantWith<NotifyMotionArgs>(
1858 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001859}
1860
1861TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_ClearsGestureAxesAfterGesture) {
1862 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1863 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1864 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1865
1866 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
1867 /*dy=*/5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001868 std::list<NotifyArgs> args =
1869 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001870
1871 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001872 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001873
1874 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
1875 // need to use another gesture type, like pinch.
1876 Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
1877 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00001878 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, pinchGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001879 ASSERT_FALSE(args.empty());
1880 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
1881 AllOf(WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(0)));
1882}
1883
1884TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) {
1885 // The gestures library will "lock" a swipe into the dimension it starts in. For example, if you
1886 // start swiping up and then start moving left or right, it'll return gesture events with only Y
1887 // deltas until you lift your fingers and start swiping again. That's why each of these tests
1888 // only checks movement in one dimension.
1889 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1890 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1891 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
1892
1893 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
1894 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00001895 std::list<NotifyArgs> args =
1896 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001897 ASSERT_EQ(4u, args.size());
1898
1899 // Three fake fingers should be created. We don't actually care where they are, so long as they
1900 // move appropriately.
1901 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
1902 ASSERT_THAT(arg,
1903 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
1904 WithGestureSwipeFingerCount(3),
1905 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1906 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1907 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1908 PointerCoords finger0Start = arg.pointerCoords[0];
1909 args.pop_front();
1910 arg = std::get<NotifyMotionArgs>(args.front());
1911 ASSERT_THAT(arg,
1912 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1913 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1914 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1915 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1916 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1917 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1918 PointerCoords finger1Start = arg.pointerCoords[1];
1919 args.pop_front();
1920 arg = std::get<NotifyMotionArgs>(args.front());
1921 ASSERT_THAT(arg,
1922 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
1923 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1924 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3),
1925 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1926 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1927 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1928 PointerCoords finger2Start = arg.pointerCoords[2];
1929 args.pop_front();
1930
1931 arg = std::get<NotifyMotionArgs>(args.front());
1932 ASSERT_THAT(arg,
1933 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1934 WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3),
1935 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1936 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1937 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1938 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1939 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1940 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1941 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 10);
1942 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 10);
1943 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 10);
1944
1945 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
1946 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00001947 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09001948 ASSERT_EQ(1u, args.size());
1949 arg = std::get<NotifyMotionArgs>(args.front());
1950 ASSERT_THAT(arg,
1951 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
1952 WithGestureOffset(0, -0.005, EPSILON), WithGestureSwipeFingerCount(3),
1953 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
1954 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1955 WithDisplayId(ADISPLAY_ID_DEFAULT)));
1956 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX());
1957 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX());
1958 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX());
1959 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY() - 15);
1960 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY() - 15);
1961 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY() - 15);
1962
1963 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00001964 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00001965 ASSERT_THAT(args,
1966 ElementsAre(VariantWith<NotifyMotionArgs>(
1967 AllOf(WithMotionAction(
1968 AMOTION_EVENT_ACTION_POINTER_UP |
1969 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1970 WithGestureOffset(0, 0, EPSILON),
1971 WithGestureSwipeFingerCount(3),
1972 WithMotionClassification(
1973 MotionClassification::MULTI_FINGER_SWIPE),
1974 WithPointerCount(3u), WithToolType(ToolType::FINGER),
1975 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1976 VariantWith<NotifyMotionArgs>(
1977 AllOf(WithMotionAction(
1978 AMOTION_EVENT_ACTION_POINTER_UP |
1979 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
1980 WithGestureOffset(0, 0, EPSILON),
1981 WithGestureSwipeFingerCount(3),
1982 WithMotionClassification(
1983 MotionClassification::MULTI_FINGER_SWIPE),
1984 WithPointerCount(2u), WithToolType(ToolType::FINGER),
1985 WithDisplayId(ADISPLAY_ID_DEFAULT))),
1986 VariantWith<NotifyMotionArgs>(
1987 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
1988 WithGestureOffset(0, 0, EPSILON),
1989 WithGestureSwipeFingerCount(3),
1990 WithMotionClassification(
1991 MotionClassification::MULTI_FINGER_SWIPE),
1992 WithPointerCount(1u), WithToolType(ToolType::FINGER),
1993 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09001994}
1995
1996TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) {
1997 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
1998 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
1999 converter.setOrientation(ui::ROTATION_90);
2000 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2001
2002 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx= */ 0,
2003 /* dy= */ 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002004 std::list<NotifyArgs> args =
2005 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002006 ASSERT_EQ(4u, args.size());
2007
2008 // Three fake fingers should be created. We don't actually care where they are, so long as they
2009 // move appropriately.
2010 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2011 ASSERT_THAT(arg,
2012 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2013 WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2014 PointerCoords finger0Start = arg.pointerCoords[0];
2015 args.pop_front();
2016 arg = std::get<NotifyMotionArgs>(args.front());
2017 ASSERT_THAT(arg,
2018 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2019 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2020 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2021 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2022 PointerCoords finger1Start = arg.pointerCoords[1];
2023 args.pop_front();
2024 arg = std::get<NotifyMotionArgs>(args.front());
2025 ASSERT_THAT(arg,
2026 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2027 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2028 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2029 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2030 PointerCoords finger2Start = arg.pointerCoords[2];
2031 args.pop_front();
2032
2033 arg = std::get<NotifyMotionArgs>(args.front());
2034 ASSERT_THAT(arg,
2035 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2036 WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u),
2037 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2038 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10);
2039 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10);
2040 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10);
2041 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2042 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2043 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2044
2045 Gesture continueGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2046 /* dx= */ 0, /* dy= */ 5);
Arpit Singh33a10a62023-10-12 13:06:54 +00002047 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002048 ASSERT_EQ(1u, args.size());
2049 arg = std::get<NotifyMotionArgs>(args.front());
2050 ASSERT_THAT(arg,
2051 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2052 WithGestureOffset(0, -0.005, EPSILON), WithPointerCount(3u),
2053 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2054 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 15);
2055 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 15);
2056 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 15);
2057 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2058 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2059 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2060
2061 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002062 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002063 ASSERT_THAT(args,
2064 ElementsAre(VariantWith<NotifyMotionArgs>(
2065 AllOf(WithMotionAction(
2066 AMOTION_EVENT_ACTION_POINTER_UP |
2067 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2068 WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u),
2069 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2070 VariantWith<NotifyMotionArgs>(
2071 AllOf(WithMotionAction(
2072 AMOTION_EVENT_ACTION_POINTER_UP |
2073 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2074 WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u),
2075 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2076 VariantWith<NotifyMotionArgs>(
2077 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2078 WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u),
2079 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002080}
2081
2082TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) {
2083 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2084 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2085 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2086
2087 Gesture startGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2088 /* dx= */ 10, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002089 std::list<NotifyArgs> args =
2090 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002091 ASSERT_EQ(5u, args.size());
2092
2093 // Four fake fingers should be created. We don't actually care where they are, so long as they
2094 // move appropriately.
2095 NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front());
2096 ASSERT_THAT(arg,
2097 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON),
2098 WithGestureSwipeFingerCount(4),
2099 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2100 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2101 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2102 PointerCoords finger0Start = arg.pointerCoords[0];
2103 args.pop_front();
2104 arg = std::get<NotifyMotionArgs>(args.front());
2105 ASSERT_THAT(arg,
2106 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2107 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2108 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2109 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2110 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2111 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2112 PointerCoords finger1Start = arg.pointerCoords[1];
2113 args.pop_front();
2114 arg = std::get<NotifyMotionArgs>(args.front());
2115 ASSERT_THAT(arg,
2116 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2117 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2118 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2119 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2120 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2121 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2122 PointerCoords finger2Start = arg.pointerCoords[2];
2123 args.pop_front();
2124 arg = std::get<NotifyMotionArgs>(args.front());
2125 ASSERT_THAT(arg,
2126 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN |
2127 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2128 WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4),
2129 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2130 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2131 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2132 PointerCoords finger3Start = arg.pointerCoords[3];
2133 args.pop_front();
2134
2135 arg = std::get<NotifyMotionArgs>(args.front());
2136 ASSERT_THAT(arg,
2137 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2138 WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4),
2139 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2140 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2141 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2142 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10);
2143 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10);
2144 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10);
2145 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 10);
2146 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2147 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2148 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2149 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2150
2151 Gesture continueGesture(kGestureFourFingerSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2152 /* dx= */ 5, /* dy= */ 0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002153 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002154 ASSERT_EQ(1u, args.size());
2155 arg = std::get<NotifyMotionArgs>(args.front());
2156 ASSERT_THAT(arg,
2157 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2158 WithGestureOffset(0.005, 0, EPSILON), WithGestureSwipeFingerCount(4),
2159 WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE),
2160 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2161 WithDisplayId(ADISPLAY_ID_DEFAULT)));
2162 EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 15);
2163 EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 15);
2164 EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 15);
2165 EXPECT_EQ(arg.pointerCoords[3].getX(), finger3Start.getX() + 15);
2166 EXPECT_EQ(arg.pointerCoords[0].getY(), finger0Start.getY());
2167 EXPECT_EQ(arg.pointerCoords[1].getY(), finger1Start.getY());
2168 EXPECT_EQ(arg.pointerCoords[2].getY(), finger2Start.getY());
2169 EXPECT_EQ(arg.pointerCoords[3].getY(), finger3Start.getY());
2170
2171 Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
Arpit Singh33a10a62023-10-12 13:06:54 +00002172 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002173 ASSERT_THAT(args,
2174 ElementsAre(VariantWith<NotifyMotionArgs>(
2175 AllOf(WithMotionAction(
2176 AMOTION_EVENT_ACTION_POINTER_UP |
2177 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2178 WithGestureOffset(0, 0, EPSILON),
2179 WithGestureSwipeFingerCount(4),
2180 WithMotionClassification(
2181 MotionClassification::MULTI_FINGER_SWIPE),
2182 WithPointerCount(4u), WithToolType(ToolType::FINGER),
2183 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2184 VariantWith<NotifyMotionArgs>(
2185 AllOf(WithMotionAction(
2186 AMOTION_EVENT_ACTION_POINTER_UP |
2187 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2188 WithGestureOffset(0, 0, EPSILON),
2189 WithGestureSwipeFingerCount(4),
2190 WithMotionClassification(
2191 MotionClassification::MULTI_FINGER_SWIPE),
2192 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2193 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2194 VariantWith<NotifyMotionArgs>(
2195 AllOf(WithMotionAction(
2196 AMOTION_EVENT_ACTION_POINTER_UP |
2197 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2198 WithGestureOffset(0, 0, EPSILON),
2199 WithGestureSwipeFingerCount(4),
2200 WithMotionClassification(
2201 MotionClassification::MULTI_FINGER_SWIPE),
2202 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2203 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2204 VariantWith<NotifyMotionArgs>(
2205 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2206 WithGestureOffset(0, 0, EPSILON),
2207 WithGestureSwipeFingerCount(4),
2208 WithMotionClassification(
2209 MotionClassification::MULTI_FINGER_SWIPE),
2210 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2211 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002212}
2213
2214TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) {
2215 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2216 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2217 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2218
2219 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2220 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002221 std::list<NotifyArgs> args =
2222 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002223 ASSERT_THAT(args,
2224 ElementsAre(VariantWith<NotifyMotionArgs>(
2225 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2226 WithMotionClassification(MotionClassification::PINCH),
2227 WithGesturePinchScaleFactor(1.0f, EPSILON),
2228 WithCoords(-100, 0), WithPointerCount(1u),
2229 WithToolType(ToolType::FINGER),
2230 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2231 VariantWith<NotifyMotionArgs>(
2232 AllOf(WithMotionAction(
2233 AMOTION_EVENT_ACTION_POINTER_DOWN |
2234 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2235 WithMotionClassification(MotionClassification::PINCH),
2236 WithGesturePinchScaleFactor(1.0f, EPSILON),
2237 WithPointerCoords(1, 100, 0), WithPointerCount(2u),
2238 WithToolType(ToolType::FINGER),
2239 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002240
2241 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2242 /* dz= */ 0.8, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002243 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002244 ASSERT_THAT(args,
2245 ElementsAre(VariantWith<NotifyMotionArgs>(
2246 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2247 WithMotionClassification(MotionClassification::PINCH),
2248 WithGesturePinchScaleFactor(0.8f, EPSILON),
2249 WithPointerCoords(0, -80, 0), WithPointerCoords(1, 80, 0),
2250 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2251 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002252
2253 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2254 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002255 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002256 ASSERT_THAT(args,
2257 ElementsAre(VariantWith<NotifyMotionArgs>(
2258 AllOf(WithMotionAction(
2259 AMOTION_EVENT_ACTION_POINTER_UP |
2260 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2261 WithMotionClassification(MotionClassification::PINCH),
2262 WithGesturePinchScaleFactor(1.0f, EPSILON),
2263 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2264 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2265 VariantWith<NotifyMotionArgs>(
2266 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2267 WithMotionClassification(MotionClassification::PINCH),
2268 WithGesturePinchScaleFactor(1.0f, EPSILON),
2269 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2270 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002271}
2272
2273TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) {
2274 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2275 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2276 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2277
2278 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2279 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002280 std::list<NotifyArgs> args =
2281 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002282 ASSERT_THAT(args,
2283 ElementsAre(VariantWith<NotifyMotionArgs>(
2284 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2285 WithMotionClassification(MotionClassification::PINCH),
2286 WithGesturePinchScaleFactor(1.0f, EPSILON),
2287 WithCoords(-100, 0), WithPointerCount(1u),
2288 WithToolType(ToolType::FINGER),
2289 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2290 VariantWith<NotifyMotionArgs>(
2291 AllOf(WithMotionAction(
2292 AMOTION_EVENT_ACTION_POINTER_DOWN |
2293 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2294 WithMotionClassification(MotionClassification::PINCH),
2295 WithGesturePinchScaleFactor(1.0f, EPSILON),
2296 WithPointerCoords(1, 100, 0), WithPointerCount(2u),
2297 WithToolType(ToolType::FINGER),
2298 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002299
2300 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2301 /* dz= */ 1.1, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002302 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002303 ASSERT_THAT(args,
2304 ElementsAre(VariantWith<NotifyMotionArgs>(
2305 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
2306 WithMotionClassification(MotionClassification::PINCH),
2307 WithGesturePinchScaleFactor(1.1f, EPSILON),
2308 WithPointerCoords(0, -110, 0), WithPointerCoords(1, 110, 0),
2309 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2310 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002311
2312 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1,
2313 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002314 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002315 ASSERT_THAT(args,
2316 ElementsAre(VariantWith<NotifyMotionArgs>(
2317 AllOf(WithMotionAction(
2318 AMOTION_EVENT_ACTION_POINTER_UP |
2319 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2320 WithMotionClassification(MotionClassification::PINCH),
2321 WithGesturePinchScaleFactor(1.0f, EPSILON),
2322 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2323 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2324 VariantWith<NotifyMotionArgs>(
2325 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2326 WithMotionClassification(MotionClassification::PINCH),
2327 WithGesturePinchScaleFactor(1.0f, EPSILON),
2328 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2329 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002330}
2331
2332TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) {
2333 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2334 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2335 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2336
2337 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2338 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002339 std::list<NotifyArgs> args =
2340 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002341
2342 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2343 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002344 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002345
2346 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2347 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002348 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002349
2350 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002351 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002352 ASSERT_THAT(args,
2353 ElementsAre(VariantWith<NotifyMotionArgs>(
2354 WithMotionClassification(MotionClassification::NONE))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002355}
2356
2357TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsScaleFactorAfterGesture) {
2358 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2359 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2360 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2361
2362 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2363 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002364 std::list<NotifyArgs> args =
2365 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002366
2367 Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2368 /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
Arpit Singh33a10a62023-10-12 13:06:54 +00002369 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, updateGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002370
2371 Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2372 GESTURES_ZOOM_END);
Arpit Singh33a10a62023-10-12 13:06:54 +00002373 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, endGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002374
2375 // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
2376 // need to use another gesture type, like scroll.
2377 Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
2378 /*dy=*/0);
Arpit Singh33a10a62023-10-12 13:06:54 +00002379 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, scrollGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002380 ASSERT_FALSE(args.empty());
2381 EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
2382}
2383
2384TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) {
2385 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2386 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2387 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2388
2389 Gesture downGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2390 /*down=*/GESTURES_BUTTON_LEFT | GESTURES_BUTTON_RIGHT,
2391 /*up=*/GESTURES_BUTTON_NONE, /*is_tap=*/false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002392 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, downGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002393
2394 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002395 ASSERT_THAT(args,
2396 ElementsAre(VariantWith<NotifyMotionArgs>(
2397 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2398 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2399 WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY),
2400 WithCoords(0, 0), WithToolType(ToolType::FINGER),
2401 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2402 VariantWith<NotifyMotionArgs>(
2403 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2404 WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY),
2405 WithButtonState(0), WithCoords(0, 0),
2406 WithToolType(ToolType::FINGER),
2407 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2408 VariantWith<NotifyMotionArgs>(
2409 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2410 WithButtonState(0), WithCoords(0, 0),
2411 WithToolType(ToolType::FINGER),
2412 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002413}
2414
2415TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) {
2416 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2417 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2418 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2419
2420 Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002421 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002422
2423 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002424 ASSERT_THAT(args,
2425 ElementsAre(VariantWith<NotifyMotionArgs>(
2426 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithCoords(0, -10),
2427 WithGestureScrollDistance(0, 0, EPSILON),
2428 WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE),
2429 WithToolType(ToolType::FINGER),
2430 WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE),
2431 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002432}
2433
2434TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) {
2435 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2436 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2437 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2438
2439 Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/0,
2440 /*dy=*/10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002441 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002442
2443 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002444 ASSERT_THAT(args,
2445 ElementsAre(VariantWith<NotifyMotionArgs>(
2446 AllOf(WithMotionAction(
2447 AMOTION_EVENT_ACTION_POINTER_UP |
2448 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2449 WithGestureOffset(0, 0, EPSILON),
2450 WithMotionClassification(
2451 MotionClassification::MULTI_FINGER_SWIPE),
2452 WithPointerCount(3u), WithToolType(ToolType::FINGER),
2453 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2454 VariantWith<NotifyMotionArgs>(
2455 AllOf(WithMotionAction(
2456 AMOTION_EVENT_ACTION_POINTER_UP |
2457 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2458 WithGestureOffset(0, 0, EPSILON),
2459 WithMotionClassification(
2460 MotionClassification::MULTI_FINGER_SWIPE),
2461 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2462 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2463 VariantWith<NotifyMotionArgs>(
2464 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2465 WithGestureOffset(0, 0, EPSILON),
2466 WithMotionClassification(
2467 MotionClassification::MULTI_FINGER_SWIPE),
2468 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2469 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002470}
2471
2472TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) {
2473 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2474 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2475 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2476
2477 Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
2478 GESTURES_ZOOM_START);
Arpit Singh33a10a62023-10-12 13:06:54 +00002479 (void)converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002480
2481 std::list<NotifyArgs> args = converter.reset(ARBITRARY_TIME);
Harry Cutts5f26e952023-11-30 18:20:27 +00002482 ASSERT_THAT(args,
2483 ElementsAre(VariantWith<NotifyMotionArgs>(
2484 AllOf(WithMotionAction(
2485 AMOTION_EVENT_ACTION_POINTER_UP |
2486 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
2487 WithMotionClassification(MotionClassification::PINCH),
2488 WithGesturePinchScaleFactor(1.0f, EPSILON),
2489 WithPointerCount(2u), WithToolType(ToolType::FINGER),
2490 WithDisplayId(ADISPLAY_ID_DEFAULT))),
2491 VariantWith<NotifyMotionArgs>(
2492 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2493 WithMotionClassification(MotionClassification::PINCH),
2494 WithGesturePinchScaleFactor(1.0f, EPSILON),
2495 WithPointerCount(1u), WithToolType(ToolType::FINGER),
2496 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002497}
2498
2499TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) {
2500 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2501 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2502 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2503
2504 Gesture tapDownGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2505 /*vx=*/0.f, /*vy=*/0.f, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002506 std::list<NotifyArgs> args =
2507 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002508
2509 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2510 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2511 WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER),
2512 WithButtonState(0), WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2513}
2514
2515TEST_F(GestureConverterTestWithChoreographer, Tap) {
2516 // Tap should produce button press/release events
2517 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2518 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2519 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2520
2521 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2522 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002523 std::list<NotifyArgs> args =
2524 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002525
Harry Cutts5f26e952023-11-30 18:20:27 +00002526 ASSERT_THAT(args,
2527 ElementsAre(VariantWith<NotifyMotionArgs>(
2528 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2529 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
2530 WithButtonState(0), WithPressure(0.0f),
2531 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002532
2533 Gesture tapGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2534 /* down= */ GESTURES_BUTTON_LEFT,
2535 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh33a10a62023-10-12 13:06:54 +00002536 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002537
Harry Cutts5f26e952023-11-30 18:20:27 +00002538 ASSERT_THAT(args,
2539 ElementsAre(VariantWith<NotifyMotionArgs>(
2540 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2541 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2542 WithToolType(ToolType::FINGER),
2543 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2544 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2545 VariantWith<NotifyMotionArgs>(
2546 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2547 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2548 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2549 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2550 WithToolType(ToolType::FINGER),
2551 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2552 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2553 VariantWith<NotifyMotionArgs>(
2554 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2555 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2556 WithButtonState(0), WithCoords(0, 0),
2557 WithRelativeMotion(0.f, 0.f),
2558 WithToolType(ToolType::FINGER), WithButtonState(0),
2559 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2560 VariantWith<NotifyMotionArgs>(
2561 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2562 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2563 WithToolType(ToolType::FINGER), WithButtonState(0),
2564 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2565 VariantWith<NotifyMotionArgs>(
2566 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
2567 WithCoords(0, 0), WithRelativeMotion(0, 0),
2568 WithToolType(ToolType::FINGER), WithButtonState(0),
2569 WithPressure(0.0f),
2570 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002571}
2572
2573TEST_F(GestureConverterTestWithChoreographer, Click) {
2574 // Click should produce button press/release events
2575 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2576 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2577 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2578
2579 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2580 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002581 std::list<NotifyArgs> args =
2582 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002583
2584 ASSERT_EQ(1u, args.size());
2585 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2586 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2587 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2588 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2589
2590 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2591 /* down= */ GESTURES_BUTTON_LEFT,
2592 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002593 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002594
Harry Cutts5f26e952023-11-30 18:20:27 +00002595 ASSERT_THAT(args,
2596 ElementsAre(VariantWith<NotifyMotionArgs>(
2597 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2598 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2599 WithToolType(ToolType::FINGER),
2600 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2601 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2602 VariantWith<NotifyMotionArgs>(
2603 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2604 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2605 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2606 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2607 WithToolType(ToolType::FINGER),
2608 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2609 WithPressure(1.0f),
2610 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002611
2612 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2613 /* down= */ GESTURES_BUTTON_NONE,
2614 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002615 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002616
Harry Cutts5f26e952023-11-30 18:20:27 +00002617 ASSERT_THAT(args,
2618 ElementsAre(VariantWith<NotifyMotionArgs>(
2619 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2620 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2621 WithButtonState(0), WithCoords(0, 0),
2622 WithRelativeMotion(0.f, 0.f),
2623 WithToolType(ToolType::FINGER), WithButtonState(0),
2624 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2625 VariantWith<NotifyMotionArgs>(
2626 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2627 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2628 WithToolType(ToolType::FINGER), WithButtonState(0),
2629 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2630 VariantWith<NotifyMotionArgs>(
2631 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
2632 WithCoords(0, 0), WithRelativeMotion(0, 0),
2633 WithToolType(ToolType::FINGER), WithButtonState(0),
2634 WithPressure(0.0f),
2635 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002636}
2637
2638TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled,
Arpit Singh82b27a02023-10-16 11:02:19 +00002639 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION),
2640 REQUIRES_FLAGS_DISABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2641 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2642
Byoungho Jungee6268f2023-10-30 17:27:26 +09002643 // Tap should be ignored when disabled
2644 mReader->getContext()->setPreventingTouchpadTaps(true);
2645
2646 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2647 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2648 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2649
Arpit Singh82b27a02023-10-16 11:02:19 +00002650 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002651 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002652 std::list<NotifyArgs> args =
Arpit Singh82b27a02023-10-16 11:02:19 +00002653 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002654
Harry Cutts5f26e952023-11-30 18:20:27 +00002655 ASSERT_THAT(args,
2656 ElementsAre(VariantWith<NotifyMotionArgs>(
2657 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2658 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
2659 WithButtonState(0), WithPressure(0.0f),
2660 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002661
Arpit Singh82b27a02023-10-16 11:02:19 +00002662 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
Byoungho Jungee6268f2023-10-30 17:27:26 +09002663 /* down= */ GESTURES_BUTTON_LEFT,
2664 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
Arpit Singh82b27a02023-10-16 11:02:19 +00002665 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002666
2667 // no events should be generated
2668 ASSERT_EQ(0u, args.size());
2669
2670 // Future taps should be re-enabled
2671 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2672}
2673
Arpit Singh82b27a02023-10-16 11:02:19 +00002674TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabledWithDelay,
2675 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2676 nsecs_t currentTime = ARBITRARY_GESTURE_TIME;
2677
2678 // Tap should be ignored when disabled
2679 mReader->getContext()->setPreventingTouchpadTaps(true);
2680
2681 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2682 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2683 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2684
2685 Gesture flingGesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2686 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2687 std::list<NotifyArgs> args =
2688 converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2689
2690 ASSERT_EQ(1u, args.size());
2691 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2692 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2693 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), WithButtonState(0),
2694 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT)));
2695
2696 Gesture tapGesture(kGestureButtonsChange, currentTime, currentTime,
2697 /* down= */ GESTURES_BUTTON_LEFT,
2698 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2699 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2700
2701 // no events should be generated
2702 ASSERT_EQ(0u, args.size());
2703
2704 // Future taps should be re-enabled
2705 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2706
2707 // taps before the threshold should still be ignored
2708 currentTime += TAP_ENABLE_DELAY_NANOS.count();
2709 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2710 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2711 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2712
2713 ASSERT_EQ(1u, args.size());
2714 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2715 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2716
2717 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2718 /* down= */ GESTURES_BUTTON_LEFT,
2719 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2720 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2721
2722 // no events should be generated
2723 ASSERT_EQ(0u, args.size());
2724
2725 // taps after the threshold should be recognised
2726 currentTime += 1;
2727 flingGesture = Gesture(kGestureFling, currentTime, currentTime, /* vx= */ 0,
2728 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
2729 args = converter.handleGesture(currentTime, currentTime, currentTime, flingGesture);
2730
2731 ASSERT_EQ(1u, args.size());
2732 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2733 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0)));
2734
2735 tapGesture = Gesture(kGestureButtonsChange, currentTime, currentTime,
2736 /* down= */ GESTURES_BUTTON_LEFT,
2737 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true);
2738 args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture);
2739
2740 ASSERT_EQ(5u, args.size());
2741 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2742 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f),
2743 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY)));
2744 args.pop_front();
2745 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2746 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2747 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1),
2748 WithRelativeMotion(0.f, 0.f)));
2749 args.pop_front();
2750 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2751 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2752 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0),
2753 WithRelativeMotion(0.f, 0.f)));
2754 args.pop_front();
2755 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2756 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f),
2757 WithButtonState(0)));
2758 args.pop_front();
2759 ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
2760 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithRelativeMotion(0, 0),
2761 WithButtonState(0)));
2762}
2763
Byoungho Jungee6268f2023-10-30 17:27:26 +09002764TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled,
2765 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2766 // Click should still produce button press/release events
2767 mReader->getContext()->setPreventingTouchpadTaps(true);
2768
2769 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2770 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2771 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2772
2773 Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* vx= */ 0,
2774 /* vy= */ 0, GESTURES_FLING_TAP_DOWN);
Arpit Singh33a10a62023-10-12 13:06:54 +00002775 std::list<NotifyArgs> args =
2776 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, flingGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002777
Harry Cutts5f26e952023-11-30 18:20:27 +00002778 ASSERT_THAT(args,
2779 ElementsAre(VariantWith<NotifyMotionArgs>(
2780 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2781 WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER),
2782 WithButtonState(0), WithPressure(0.0f),
2783 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002784
2785 Gesture buttonDownGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2786 /* down= */ GESTURES_BUTTON_LEFT,
2787 /* up= */ GESTURES_BUTTON_NONE, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002788 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonDownGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002789
Harry Cutts5f26e952023-11-30 18:20:27 +00002790 ASSERT_THAT(args,
2791 ElementsAre(VariantWith<NotifyMotionArgs>(
2792 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
2793 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2794 WithToolType(ToolType::FINGER),
2795 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2796 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2797 VariantWith<NotifyMotionArgs>(
2798 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS),
2799 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2800 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2801 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2802 WithToolType(ToolType::FINGER),
2803 WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY),
2804 WithPressure(1.0f),
2805 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002806
2807 Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
2808 /* down= */ GESTURES_BUTTON_NONE,
2809 /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ false);
Arpit Singh33a10a62023-10-12 13:06:54 +00002810 args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, buttonUpGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002811
Harry Cutts5f26e952023-11-30 18:20:27 +00002812 ASSERT_THAT(args,
2813 ElementsAre(VariantWith<NotifyMotionArgs>(
2814 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE),
2815 WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY),
2816 WithButtonState(0), WithCoords(0, 0),
2817 WithRelativeMotion(0.f, 0.f),
2818 WithToolType(ToolType::FINGER), WithButtonState(0),
2819 WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2820 VariantWith<NotifyMotionArgs>(
2821 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP),
2822 WithCoords(0, 0), WithRelativeMotion(0.f, 0.f),
2823 WithToolType(ToolType::FINGER), WithButtonState(0),
2824 WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))),
2825 VariantWith<NotifyMotionArgs>(
2826 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE),
2827 WithCoords(0, 0), WithRelativeMotion(0, 0),
2828 WithToolType(ToolType::FINGER), WithButtonState(0),
2829 WithPressure(0.0f),
2830 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002831
2832 // Future taps should be re-enabled
2833 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2834}
2835
2836TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, MoveEnablesTapToClick,
2837 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION)) {
2838 // initially disable tap-to-click
2839 mReader->getContext()->setPreventingTouchpadTaps(true);
2840
2841 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2842 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2843 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2844
2845 Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
Arpit Singh33a10a62023-10-12 13:06:54 +00002846 std::list<NotifyArgs> args =
2847 converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
Byoungho Jungee6268f2023-10-30 17:27:26 +09002848
Harry Cutts5f26e952023-11-30 18:20:27 +00002849 ASSERT_THAT(args,
2850 ElementsAre(VariantWith<NotifyMotionArgs>(
2851 AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(0, 0),
2852 WithRelativeMotion(-5, 10), WithToolType(ToolType::FINGER),
2853 WithButtonState(0), WithPressure(0.0f),
2854 WithDisplayId(ADISPLAY_ID_DEFAULT)))));
Byoungho Jungee6268f2023-10-30 17:27:26 +09002855
2856 // Future taps should be re-enabled
2857 ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps());
2858}
2859
Arpit Singh33a10a62023-10-12 13:06:54 +00002860TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, KeypressCancelsHoverMove,
2861 REQUIRES_FLAGS_ENABLED(TOUCHPAD_PALM_REJECTION_V2)) {
2862 const nsecs_t gestureStartTime = 1000;
2863 InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
2864 GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);
2865 converter.setDisplayId(ADISPLAY_ID_DEFAULT);
2866
2867 // Start a move gesture at gestureStartTime
2868 Gesture moveGesture(kGestureMove, gestureStartTime, gestureStartTime, -5, 10);
2869 std::list<NotifyArgs> args =
2870 converter.handleGesture(gestureStartTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002871 ASSERT_THAT(args,
2872 ElementsAre(VariantWith<NotifyMotionArgs>(
2873 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002874
2875 // Key presses with IME connection should cancel ongoing move gesture
2876 nsecs_t currentTime = gestureStartTime + 100;
2877 mFakePolicy->setIsInputMethodConnectionActive(true);
2878 mReader->getContext()->setLastKeyDownTimestamp(currentTime);
2879 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2880 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002881 ASSERT_THAT(args,
2882 ElementsAre(VariantWith<NotifyMotionArgs>(
2883 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002884
2885 // any updates in existing move gesture should be ignored
2886 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2887 args = converter.handleGesture(currentTime, READ_TIME, gestureStartTime, moveGesture);
2888 ASSERT_EQ(0u, args.size());
2889
2890 // New gesture should not be affected
2891 currentTime += 100;
2892 moveGesture = Gesture(kGestureMove, currentTime, currentTime, -5, 10);
2893 args = converter.handleGesture(currentTime, READ_TIME, currentTime, moveGesture);
Harry Cutts5f26e952023-11-30 18:20:27 +00002894 ASSERT_THAT(args,
2895 ElementsAre(VariantWith<NotifyMotionArgs>(
2896 WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE))));
Arpit Singh33a10a62023-10-12 13:06:54 +00002897}
2898
Harry Cutts4fb941a2022-12-14 19:14:04 +00002899} // namespace android