blob: 526e4eb7c14d72eaadff594cf5e79b2ac305082d [file] [log] [blame]
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -07001/*
2 * Copyright (C) 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 "../UnwantedInteractionBlocker.h"
18#include <android-base/silent_death_test.h>
Siarhei Vishniakou88151b82022-08-11 00:53:38 +000019#include <gmock/gmock.h>
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070020#include <gtest/gtest.h>
21#include <gui/constants.h>
22#include <linux/input.h>
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -070023#include <thread>
Siarhei Vishniakou88151b82022-08-11 00:53:38 +000024#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter.h"
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070025
26#include "TestInputListener.h"
27
Siarhei Vishniakou88151b82022-08-11 00:53:38 +000028using ::testing::AllOf;
29
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070030namespace android {
31
32constexpr int32_t DEVICE_ID = 3;
33constexpr int32_t X_RESOLUTION = 11;
34constexpr int32_t Y_RESOLUTION = 11;
35constexpr int32_t MAJOR_RESOLUTION = 1;
36
Siarhei Vishniakou88151b82022-08-11 00:53:38 +000037const nsecs_t RESAMPLE_PERIOD = ::ui::kResamplePeriod.InNanoseconds();
38
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070039constexpr int POINTER_0_DOWN =
40 AMOTION_EVENT_ACTION_POINTER_DOWN | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
41constexpr int POINTER_1_DOWN =
42 AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
43constexpr int POINTER_2_DOWN =
44 AMOTION_EVENT_ACTION_POINTER_DOWN | (2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
45constexpr int POINTER_0_UP =
46 AMOTION_EVENT_ACTION_POINTER_UP | (0 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
47constexpr int POINTER_1_UP =
48 AMOTION_EVENT_ACTION_POINTER_UP | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
49constexpr int POINTER_2_UP =
50 AMOTION_EVENT_ACTION_POINTER_UP | (2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
51constexpr int DOWN = AMOTION_EVENT_ACTION_DOWN;
52constexpr int MOVE = AMOTION_EVENT_ACTION_MOVE;
53constexpr int UP = AMOTION_EVENT_ACTION_UP;
54constexpr int CANCEL = AMOTION_EVENT_ACTION_CANCEL;
55
Siarhei Vishniakou88151b82022-08-11 00:53:38 +000056constexpr int32_t FLAG_CANCELED = AMOTION_EVENT_FLAG_CANCELED;
57
58MATCHER_P(WithAction, action, "MotionEvent with specified action") {
59 bool result = true;
60 if (action == CANCEL) {
61 result &= (arg.flags & FLAG_CANCELED) != 0;
62 }
63 result &= arg.action == action;
64 *result_listener << "expected to receive " << MotionEvent::actionToString(action)
65 << " but received " << MotionEvent::actionToString(arg.action) << " instead.";
66 return result;
67}
68
Siarhei Vishniakou65735832022-08-09 19:18:37 +000069MATCHER_P(WithFlags, flags, "MotionEvent with specified flags") {
70 return arg.flags == flags;
71}
72
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -070073static nsecs_t toNs(std::chrono::nanoseconds duration) {
74 return duration.count();
75}
76
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -070077struct PointerData {
78 float x;
79 float y;
80 float major;
81};
82
83static NotifyMotionArgs generateMotionArgs(nsecs_t downTime, nsecs_t eventTime, int32_t action,
84 const std::vector<PointerData>& points) {
85 size_t pointerCount = points.size();
86 if (action == AMOTION_EVENT_ACTION_DOWN || action == AMOTION_EVENT_ACTION_UP) {
87 EXPECT_EQ(1U, pointerCount) << "Actions DOWN and UP can only contain a single pointer";
88 }
89
90 PointerProperties pointerProperties[pointerCount];
91 PointerCoords pointerCoords[pointerCount];
92
93 for (size_t i = 0; i < pointerCount; i++) {
94 pointerProperties[i].clear();
95 pointerProperties[i].id = i;
96 pointerProperties[i].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
97
98 pointerCoords[i].clear();
99 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, points[i].x);
100 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, points[i].y);
101 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, points[i].major);
102 }
103
104 // Define a valid motion event.
105 NotifyMotionArgs args(/* id */ 0, eventTime, 0 /*readTime*/, DEVICE_ID,
106 AINPUT_SOURCE_TOUCHSCREEN, 0 /*displayId*/, POLICY_FLAG_PASS_TO_USER,
107 action, /* actionButton */ 0,
108 /* flags */ 0, AMETA_NONE, /* buttonState */ 0,
109 MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, pointerCount,
110 pointerProperties, pointerCoords, /* xPrecision */ 0, /* yPrecision */ 0,
111 AMOTION_EVENT_INVALID_CURSOR_POSITION,
112 AMOTION_EVENT_INVALID_CURSOR_POSITION, downTime, /* videoFrames */ {});
113
114 return args;
115}
116
117static InputDeviceInfo generateTestDeviceInfo() {
118 InputDeviceIdentifier identifier;
119
120 auto info = InputDeviceInfo();
121 info.initialize(DEVICE_ID, /*generation*/ 1, /*controllerNumber*/ 1, identifier, "alias",
122 /*isExternal*/ false, /*hasMic*/ false);
123 info.addSource(AINPUT_SOURCE_TOUCHSCREEN);
124 info.addMotionRange(AMOTION_EVENT_AXIS_X, AINPUT_SOURCE_TOUCHSCREEN, 0, 1599, /*flat*/ 0,
125 /*fuzz*/ 0, X_RESOLUTION);
126 info.addMotionRange(AMOTION_EVENT_AXIS_Y, AINPUT_SOURCE_TOUCHSCREEN, 0, 2559, /*flat*/ 0,
127 /*fuzz*/ 0, Y_RESOLUTION);
128 info.addMotionRange(AMOTION_EVENT_AXIS_TOUCH_MAJOR, AINPUT_SOURCE_TOUCHSCREEN, 0, 255,
129 /*flat*/ 0, /*fuzz*/ 0, MAJOR_RESOLUTION);
130
131 return info;
132}
133
134static AndroidPalmFilterDeviceInfo generatePalmFilterDeviceInfo() {
135 InputDeviceInfo androidInfo = generateTestDeviceInfo();
136 std::optional<AndroidPalmFilterDeviceInfo> info = createPalmFilterDeviceInfo(androidInfo);
137 if (!info) {
138 ADD_FAILURE() << "Could not convert android device info to ::ui version";
139 return {};
140 }
141 return *info;
142}
143
144TEST(DeviceInfoConversionTest, TabletDeviceTest) {
145 AndroidPalmFilterDeviceInfo info = generatePalmFilterDeviceInfo();
146 ASSERT_EQ(X_RESOLUTION, info.x_res);
147 ASSERT_EQ(Y_RESOLUTION, info.y_res);
148 ASSERT_EQ(MAJOR_RESOLUTION, info.touch_major_res);
149 ASSERT_EQ(1599, info.max_x);
150 ASSERT_EQ(2559, info.max_y);
151}
152
153static void assertArgs(const NotifyMotionArgs& args, int32_t action,
154 const std::vector<std::pair<int32_t /*pointerId*/, PointerData>>& pointers) {
155 ASSERT_EQ(action, args.action);
156 ASSERT_EQ(pointers.size(), args.pointerCount);
157 for (size_t i = 0; i < args.pointerCount; i++) {
158 const auto& [pointerId, pointerData] = pointers[i];
159 ASSERT_EQ(pointerId, args.pointerProperties[i].id);
160 ASSERT_EQ(pointerData.x, args.pointerCoords[i].getX());
161 ASSERT_EQ(pointerData.y, args.pointerCoords[i].getY());
162 ASSERT_EQ(pointerData.major,
163 args.pointerCoords[i].getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR));
164 }
165}
166
167TEST(RemovePointerIdsTest, RemoveOnePointer) {
168 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0,
169 AMOTION_EVENT_ACTION_MOVE, {{1, 2, 3}, {4, 5, 6}});
170
171 NotifyMotionArgs pointer1Only = removePointerIds(args, {0});
172 assertArgs(pointer1Only, AMOTION_EVENT_ACTION_MOVE, {{1, {4, 5, 6}}});
173
174 NotifyMotionArgs pointer0Only = removePointerIds(args, {1});
175 assertArgs(pointer0Only, AMOTION_EVENT_ACTION_MOVE, {{0, {1, 2, 3}}});
176}
177
178/**
179 * Remove 2 out of 3 pointers during a MOVE event.
180 */
181TEST(RemovePointerIdsTest, RemoveTwoPointers) {
182 NotifyMotionArgs args =
183 generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, AMOTION_EVENT_ACTION_MOVE,
184 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
185
186 NotifyMotionArgs pointer1Only = removePointerIds(args, {0, 2});
187 assertArgs(pointer1Only, AMOTION_EVENT_ACTION_MOVE, {{1, {4, 5, 6}}});
188}
189
190/**
191 * Remove an active pointer during a POINTER_DOWN event, and also remove a non-active
192 * pointer during a POINTER_DOWN event.
193 */
194TEST(RemovePointerIdsTest, ActionPointerDown) {
195 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, POINTER_1_DOWN,
196 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
197
198 NotifyMotionArgs pointers0And2 = removePointerIds(args, {1});
199 assertArgs(pointers0And2, ACTION_UNKNOWN, {{0, {1, 2, 3}}, {2, {7, 8, 9}}});
200
201 NotifyMotionArgs pointers1And2 = removePointerIds(args, {0});
202 assertArgs(pointers1And2, POINTER_0_DOWN, {{1, {4, 5, 6}}, {2, {7, 8, 9}}});
203}
204
205/**
206 * Remove all pointers during a MOVE event.
207 */
208TEST(RemovePointerIdsTest, RemoveAllPointersDuringMove) {
209 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0,
210 AMOTION_EVENT_ACTION_MOVE, {{1, 2, 3}, {4, 5, 6}});
211
212 NotifyMotionArgs noPointers = removePointerIds(args, {0, 1});
213 ASSERT_EQ(0u, noPointers.pointerCount);
214}
215
216/**
217 * If we have ACTION_POINTER_DOWN, and we remove all pointers except for the active pointer,
218 * then we should just have ACTION_DOWN. Likewise, a POINTER_UP event should become an UP event.
219 */
220TEST(RemovePointerIdsTest, PointerDownBecomesDown) {
221 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, POINTER_1_DOWN,
222 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
223
224 NotifyMotionArgs pointer1 = removePointerIds(args, {0, 2});
225 assertArgs(pointer1, DOWN, {{1, {4, 5, 6}}});
226
227 args.action = POINTER_1_UP;
228 pointer1 = removePointerIds(args, {0, 2});
229 assertArgs(pointer1, UP, {{1, {4, 5, 6}}});
230}
231
232/**
233 * If a pointer that is now going down is canceled, then we can just drop the POINTER_DOWN event.
234 */
235TEST(CancelSuppressedPointersTest, CanceledPointerDownIsDropped) {
236 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, POINTER_1_DOWN,
237 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
238 std::vector<NotifyMotionArgs> result =
239 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {},
240 /*newSuppressedPointerIds*/ {1});
241 ASSERT_TRUE(result.empty());
242}
243
244/**
245 * If a pointer is already suppressed, the POINTER_UP event for this pointer should be dropped
246 */
247TEST(CancelSuppressedPointersTest, SuppressedPointerUpIsDropped) {
248 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, POINTER_1_UP,
249 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
250 std::vector<NotifyMotionArgs> result =
251 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {1},
252 /*newSuppressedPointerIds*/ {1});
253 ASSERT_TRUE(result.empty());
254}
255
256/**
257 * If a pointer is already suppressed, it should be removed from a MOVE event.
258 */
259TEST(CancelSuppressedPointersTest, SuppressedPointerIsRemovedDuringMove) {
260 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, MOVE,
261 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
262 std::vector<NotifyMotionArgs> result =
263 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {1},
264 /*newSuppressedPointerIds*/ {1});
265 ASSERT_EQ(1u, result.size());
266 assertArgs(result[0], MOVE, {{0, {1, 2, 3}}, {2, {7, 8, 9}}});
267}
268
269/**
270 * If a pointer just got canceled during a MOVE event, we should see two events:
271 * 1) ACTION_POINTER_UP with FLAG_CANCELED so that this pointer is lifted
272 * 2) A MOVE event without this pointer
273 */
274TEST(CancelSuppressedPointersTest, NewlySuppressedPointerIsCanceled) {
275 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, MOVE,
276 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
277 std::vector<NotifyMotionArgs> result =
278 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {},
279 /*newSuppressedPointerIds*/ {1});
280 ASSERT_EQ(2u, result.size());
281 assertArgs(result[0], POINTER_1_UP, {{0, {1, 2, 3}}, {1, {4, 5, 6}}, {2, {7, 8, 9}}});
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000282 ASSERT_EQ(FLAG_CANCELED, result[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700283 assertArgs(result[1], MOVE, {{0, {1, 2, 3}}, {2, {7, 8, 9}}});
284}
285
286/**
287 * If we have a single pointer that gets canceled during a MOVE, the entire gesture
288 * should be canceled with ACTION_CANCEL.
289 */
290TEST(CancelSuppressedPointersTest, SingleSuppressedPointerIsCanceled) {
291 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, MOVE, {{1, 2, 3}});
292 std::vector<NotifyMotionArgs> result =
293 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {},
294 /*newSuppressedPointerIds*/ {0});
295 ASSERT_EQ(1u, result.size());
296 assertArgs(result[0], CANCEL, {{0, {1, 2, 3}}});
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000297 ASSERT_EQ(FLAG_CANCELED, result[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700298}
299
300/**
301 * If one of 3 pointers gets canceled during a POINTER_UP event, we should proceed with POINTER_UP,
302 * but this event should also have FLAG_CANCELED to indicate that this pointer was unintentional.
303 */
304TEST(CancelSuppressedPointersTest, SuppressedPointer1GoingUpIsCanceled) {
305 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, POINTER_1_UP,
306 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
307 std::vector<NotifyMotionArgs> result =
308 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {},
309 /*newSuppressedPointerIds*/ {1});
310 ASSERT_EQ(1u, result.size());
311 assertArgs(result[0], POINTER_1_UP, {{0, {1, 2, 3}}, {1, {4, 5, 6}}, {2, {7, 8, 9}}});
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000312 ASSERT_EQ(FLAG_CANCELED, result[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700313}
314
315/**
316 * Same test as above, but we change the pointer's index to 0 instead of 1. This helps detect
317 * errors with handling pointer index inside the action.
318 */
319TEST(CancelSuppressedPointersTest, SuppressedPointer0GoingUpIsCanceled) {
320 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, POINTER_0_UP,
321 {{1, 2, 3}, {4, 5, 6}});
322 std::vector<NotifyMotionArgs> result =
323 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {},
324 /*newSuppressedPointerIds*/ {0});
325 ASSERT_EQ(1u, result.size());
326 assertArgs(result[0], POINTER_0_UP, {{0, {1, 2, 3}}, {1, {4, 5, 6}}});
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000327 ASSERT_EQ(FLAG_CANCELED, result[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700328}
329
330/**
331 * If two pointers are canceled simultaneously during MOVE, we should see a single ACTION_CANCEL
332 * event. This event would cancel the entire gesture.
333 */
334TEST(CancelSuppressedPointersTest, TwoNewlySuppressedPointersAreBothCanceled) {
335 NotifyMotionArgs args =
336 generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, MOVE, {{1, 2, 3}, {4, 5, 6}});
337 std::vector<NotifyMotionArgs> result =
338 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {},
339 /*newSuppressedPointerIds*/ {0, 1});
340 ASSERT_EQ(1u, result.size());
341 assertArgs(result[0], CANCEL, {{0, {1, 2, 3}}, {1, {4, 5, 6}}});
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000342 ASSERT_EQ(FLAG_CANCELED, result[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700343}
344
345/**
346 * Similar test to above. During a POINTER_UP event, both pointers are detected as 'palm' and
347 * therefore should be removed. In this case, we should send a single ACTION_CANCEL that
348 * would undo the entire gesture.
349 */
350TEST(CancelSuppressedPointersTest, TwoPointersAreCanceledDuringPointerUp) {
351 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, POINTER_1_UP,
352 {{1, 2, 3}, {4, 5, 6}});
353 std::vector<NotifyMotionArgs> result =
354 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {1},
355 /*newSuppressedPointerIds*/ {0, 1});
356 ASSERT_EQ(1u, result.size());
357 assertArgs(result[0], CANCEL, {{0, {1, 2, 3}}});
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000358 ASSERT_EQ(FLAG_CANCELED, result[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700359}
360
361/**
362 * When all pointers have been removed from the touch stream, and we have a new POINTER_DOWN,
363 * this should become a regular DOWN event because it's the only pointer that will be valid now.
364 */
365TEST(CancelSuppressedPointersTest, NewPointerDownBecomesDown) {
366 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, POINTER_2_DOWN,
367 {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}});
368 std::vector<NotifyMotionArgs> result =
369 cancelSuppressedPointers(args, /*oldSuppressedPointerIds*/ {0, 1},
370 /*newSuppressedPointerIds*/ {0, 1});
371 ASSERT_EQ(1u, result.size());
372 assertArgs(result[0], DOWN, {{2, {7, 8, 9}}});
373 ASSERT_EQ(0, result[0].flags);
374}
375
376/**
377 * Call 'getTouches' for a DOWN event and check that the resulting 'InProgressTouchEvdev'
378 * struct is populated as expected.
379 */
380TEST(GetTouchesTest, ConvertDownEvent) {
381 NotifyMotionArgs args = generateMotionArgs(/*downTime*/ 0, /*eventTime*/ 0, DOWN, {{1, 2, 3}});
382 AndroidPalmFilterDeviceInfo deviceInfo = generatePalmFilterDeviceInfo();
383 SlotState slotState;
384 SlotState oldSlotState = slotState;
385 slotState.update(args);
386 std::vector<::ui::InProgressTouchEvdev> touches =
387 getTouches(args, deviceInfo, oldSlotState, slotState);
388 ASSERT_EQ(1u, touches.size());
389 ::ui::InProgressTouchEvdev expected;
390
391 expected.major = 3;
392 expected.minor = 0;
393 expected.tool_type = MT_TOOL_FINGER;
394 expected.altered = true;
395 expected.was_cancelled = false;
396 expected.cancelled = false;
397 expected.delayed = false;
398 expected.was_delayed = false;
399 expected.held = false;
400 expected.was_held = false;
401 expected.was_touching = false;
402 expected.touching = true;
403 expected.x = 1;
404 expected.y = 2;
405 expected.tracking_id = 0;
406 std::optional<size_t> slot = slotState.getSlotForPointerId(0);
407 ASSERT_TRUE(slot);
408 expected.slot = *slot;
409 expected.pressure = 0;
410 expected.tool_code = BTN_TOOL_FINGER;
411 expected.reported_tool_type = ::ui::EventPointerType::kTouch;
412 expected.stylus_button = false;
413
Siarhei Vishniakou47494ef2022-07-06 15:42:57 -0700414 ASSERT_EQ(expected, touches[0]) << touches[0];
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700415}
416
417// --- UnwantedInteractionBlockerTest ---
418
419class UnwantedInteractionBlockerTest : public testing::Test {
420protected:
421 TestInputListener mTestListener;
422 std::unique_ptr<UnwantedInteractionBlockerInterface> mBlocker;
423
424 void SetUp() override {
425 mBlocker = std::make_unique<UnwantedInteractionBlocker>(mTestListener,
426 /*enablePalmRejection*/ true);
427 }
428};
429
430/**
Siarhei Vishniakou98996032022-08-03 11:54:47 -0700431 * Create a basic configuration change and send it to input processor.
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700432 * Expect that the event is received by the next input stage, unmodified.
433 */
434TEST_F(UnwantedInteractionBlockerTest, ConfigurationChangedIsPassedToNextListener) {
Siarhei Vishniakou98996032022-08-03 11:54:47 -0700435 // Create a basic configuration change and send to blocker
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700436 NotifyConfigurationChangedArgs args(1 /*sequenceNum*/, 2 /*eventTime*/);
437
438 mBlocker->notifyConfigurationChanged(&args);
439 NotifyConfigurationChangedArgs outArgs;
440 ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyConfigurationChangedWasCalled(&outArgs));
441 ASSERT_EQ(args, outArgs);
442}
443
444/**
445 * Keys are not handled in 'UnwantedInteractionBlocker' and should be passed
446 * to next stage unmodified.
447 */
448TEST_F(UnwantedInteractionBlockerTest, KeyIsPassedToNextListener) {
Siarhei Vishniakou98996032022-08-03 11:54:47 -0700449 // Create a basic key event and send to blocker
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700450 NotifyKeyArgs args(1 /*sequenceNum*/, 2 /*eventTime*/, 21 /*readTime*/, 3 /*deviceId*/,
451 AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_DEFAULT, 0 /*policyFlags*/,
452 AKEY_EVENT_ACTION_DOWN, 4 /*flags*/, AKEYCODE_HOME, 5 /*scanCode*/,
453 AMETA_NONE, 6 /*downTime*/);
454
455 mBlocker->notifyKey(&args);
456 NotifyKeyArgs outArgs;
457 ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyKeyWasCalled(&outArgs));
458 ASSERT_EQ(args, outArgs);
459}
460
461/**
462 * Create a basic motion event. Since it's just a DOWN event, it should not
463 * be detected as palm and should be sent to the next listener stage
464 * unmodified.
465 */
466TEST_F(UnwantedInteractionBlockerTest, DownEventIsPassedToNextListener) {
467 NotifyMotionArgs motionArgs =
468 generateMotionArgs(0 /*downTime*/, 0 /*eventTime*/, DOWN, {{1, 2, 3}});
469 mBlocker->notifyMotion(&motionArgs);
470 NotifyMotionArgs args;
471 ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyMotionWasCalled(&args));
472 ASSERT_EQ(motionArgs, args);
473}
474
475/**
476 * Create a basic switch event and send it to the UnwantedInteractionBlocker.
477 * Expect that the event is received by the next input stage, unmodified.
478 */
479TEST_F(UnwantedInteractionBlockerTest, SwitchIsPassedToNextListener) {
480 NotifySwitchArgs args(1 /*sequenceNum*/, 2 /*eventTime*/, 3 /*policyFlags*/, 4 /*switchValues*/,
481 5 /*switchMask*/);
482
483 mBlocker->notifySwitch(&args);
484 NotifySwitchArgs outArgs;
485 ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifySwitchWasCalled(&outArgs));
486 ASSERT_EQ(args, outArgs);
487}
488
489/**
490 * Create a basic device reset event and send it to UnwantedInteractionBlocker.
491 * Expect that the event is received by the next input stage, unmodified.
492 */
493TEST_F(UnwantedInteractionBlockerTest, DeviceResetIsPassedToNextListener) {
494 NotifyDeviceResetArgs args(1 /*sequenceNum*/, 2 /*eventTime*/, DEVICE_ID);
495
496 mBlocker->notifyDeviceReset(&args);
497 NotifyDeviceResetArgs outArgs;
498 ASSERT_NO_FATAL_FAILURE(mTestListener.assertNotifyDeviceResetWasCalled(&outArgs));
499 ASSERT_EQ(args, outArgs);
500}
501
502/**
503 * The state should be reset when device reset happens. That means, we can reset in the middle of a
504 * gesture, and start a new stream. There should be no crash. If the state wasn't reset correctly,
505 * a crash due to inconsistent event stream could have occurred.
506 */
507TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenResetHappens) {
508 NotifyMotionArgs args;
509 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
510 mBlocker->notifyMotion(
511 &(args = generateMotionArgs(0 /*downTime*/, 1 /*eventTime*/, DOWN, {{1, 2, 3}})));
512 mBlocker->notifyMotion(
513 &(args = generateMotionArgs(0 /*downTime*/, 2 /*eventTime*/, MOVE, {{4, 5, 6}})));
514 NotifyDeviceResetArgs resetArgs(1 /*sequenceNum*/, 3 /*eventTime*/, DEVICE_ID);
515 mBlocker->notifyDeviceReset(&resetArgs);
516 // Start a new gesture with a DOWN event, even though the previous event stream was incomplete.
517 mBlocker->notifyMotion(
518 &(args = generateMotionArgs(0 /*downTime*/, 4 /*eventTime*/, DOWN, {{7, 8, 9}})));
519}
520
Siarhei Vishniakou27568392022-03-08 11:06:34 -0800521TEST_F(UnwantedInteractionBlockerTest, NoCrashWhenStylusSourceWithFingerToolIsReceived) {
522 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
523 NotifyMotionArgs args = generateMotionArgs(0 /*downTime*/, 1 /*eventTime*/, DOWN, {{1, 2, 3}});
524 args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
525 args.source = AINPUT_SOURCE_STYLUS;
526 mBlocker->notifyMotion(&args);
527}
528
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700529/**
530 * If input devices have changed, but the important device info that's used by the
531 * UnwantedInteractionBlocker has not changed, there should not be a reset.
532 */
533TEST_F(UnwantedInteractionBlockerTest, NoResetIfDeviceInfoChanges) {
534 NotifyMotionArgs args;
535 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
536 mBlocker->notifyMotion(
537 &(args = generateMotionArgs(0 /*downTime*/, 1 /*eventTime*/, DOWN, {{1, 2, 3}})));
538 mBlocker->notifyMotion(
539 &(args = generateMotionArgs(0 /*downTime*/, 2 /*eventTime*/, MOVE, {{4, 5, 6}})));
540
541 // Now pretend the device changed, even though nothing is different for DEVICE_ID in practice.
542 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
543
544 // The MOVE event continues the gesture that started before 'devices changed', so it should not
545 // cause a crash.
546 mBlocker->notifyMotion(
547 &(args = generateMotionArgs(0 /*downTime*/, 4 /*eventTime*/, MOVE, {{7, 8, 9}})));
548}
549
Siarhei Vishniakoua6a660f2022-03-04 15:12:16 -0800550/**
551 * Send a touch event, and then a stylus event. Make sure that both work.
552 */
553TEST_F(UnwantedInteractionBlockerTest, StylusAfterTouchWorks) {
554 NotifyMotionArgs args;
555 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
556 args = generateMotionArgs(0 /*downTime*/, 0 /*eventTime*/, DOWN, {{1, 2, 3}});
557 mBlocker->notifyMotion(&args);
558 args = generateMotionArgs(0 /*downTime*/, 1 /*eventTime*/, MOVE, {{4, 5, 6}});
559 mBlocker->notifyMotion(&args);
560 args = generateMotionArgs(0 /*downTime*/, 2 /*eventTime*/, UP, {{4, 5, 6}});
561 mBlocker->notifyMotion(&args);
562
563 // Now touch down stylus
564 args = generateMotionArgs(3 /*downTime*/, 3 /*eventTime*/, DOWN, {{10, 20, 30}});
565 args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
566 args.source |= AINPUT_SOURCE_STYLUS;
567 mBlocker->notifyMotion(&args);
568 args = generateMotionArgs(3 /*downTime*/, 4 /*eventTime*/, MOVE, {{40, 50, 60}});
569 args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
570 args.source |= AINPUT_SOURCE_STYLUS;
571 mBlocker->notifyMotion(&args);
572 args = generateMotionArgs(3 /*downTime*/, 5 /*eventTime*/, UP, {{40, 50, 60}});
573 args.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
574 args.source |= AINPUT_SOURCE_STYLUS;
575 mBlocker->notifyMotion(&args);
576}
577
Siarhei Vishniakou9f330c52022-05-17 05:03:42 -0700578/**
579 * Call dump, and on another thread, try to send some motions. The blocker should
580 * not crash. On 2022 hardware, this test requires ~ 13K executions (about 20 seconds) to reproduce
581 * the original bug. This is meant to be run with "--gtest_repeat=100000 --gtest_break_on_failure"
582 * options
583 */
584TEST_F(UnwantedInteractionBlockerTest, DumpCanBeAccessedOnAnotherThread) {
585 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
586 NotifyMotionArgs args1 = generateMotionArgs(0 /*downTime*/, 0 /*eventTime*/, DOWN, {{1, 2, 3}});
587 mBlocker->notifyMotion(&args1);
588 std::thread dumpThread([this]() {
589 std::string dump;
590 mBlocker->dump(dump);
591 });
592 NotifyMotionArgs args2 = generateMotionArgs(0 /*downTime*/, 1 /*eventTime*/, MOVE, {{4, 5, 6}});
593 mBlocker->notifyMotion(&args2);
594 NotifyMotionArgs args3 = generateMotionArgs(0 /*downTime*/, 2 /*eventTime*/, UP, {{4, 5, 6}});
595 mBlocker->notifyMotion(&args3);
596 dumpThread.join();
597}
598
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000599/**
600 * Heuristic filter that's present in the palm rejection model blocks touches early if the size
601 * of the touch is large. This is an integration test that checks that this filter kicks in.
602 */
603TEST_F(UnwantedInteractionBlockerTest, HeuristicFilterWorks) {
604 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
605 // Small touch down
606 NotifyMotionArgs args1 = generateMotionArgs(0 /*downTime*/, 0 /*eventTime*/, DOWN, {{1, 2, 3}});
607 mBlocker->notifyMotion(&args1);
608 mTestListener.assertNotifyMotionWasCalled(WithAction(DOWN));
609
610 // Large touch oval on the next move
611 NotifyMotionArgs args2 =
612 generateMotionArgs(0 /*downTime*/, RESAMPLE_PERIOD, MOVE, {{4, 5, 200}});
613 mBlocker->notifyMotion(&args2);
614 mTestListener.assertNotifyMotionWasCalled(WithAction(MOVE));
615
616 // Lift up the touch to force the model to decide on whether it's a palm
617 NotifyMotionArgs args3 =
618 generateMotionArgs(0 /*downTime*/, 2 * RESAMPLE_PERIOD, UP, {{4, 5, 200}});
619 mBlocker->notifyMotion(&args3);
620 mTestListener.assertNotifyMotionWasCalled(WithAction(CANCEL));
621}
622
Siarhei Vishniakou65735832022-08-09 19:18:37 +0000623/**
624 * Send a stylus event that would have triggered the heuristic palm detector if it were a touch
625 * event. However, since it's a stylus event, it should propagate without being canceled through
626 * the blocker.
627 * This is similar to `HeuristicFilterWorks` test, but for stylus tool.
628 */
629TEST_F(UnwantedInteractionBlockerTest, StylusIsNotBlocked) {
630 InputDeviceInfo info = generateTestDeviceInfo();
631 info.addSource(AINPUT_SOURCE_STYLUS);
632 mBlocker->notifyInputDevicesChanged({info});
633 NotifyMotionArgs args1 = generateMotionArgs(0 /*downTime*/, 0 /*eventTime*/, DOWN, {{1, 2, 3}});
634 args1.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
635 mBlocker->notifyMotion(&args1);
636 mTestListener.assertNotifyMotionWasCalled(WithAction(DOWN));
637
638 // Move the stylus, setting large TOUCH_MAJOR/TOUCH_MINOR dimensions
639 NotifyMotionArgs args2 =
640 generateMotionArgs(0 /*downTime*/, RESAMPLE_PERIOD, MOVE, {{4, 5, 200}});
641 args2.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
642 mBlocker->notifyMotion(&args2);
643 mTestListener.assertNotifyMotionWasCalled(WithAction(MOVE));
644
645 // Lift up the stylus. If it were a touch event, this would force the model to decide on whether
646 // it's a palm.
647 NotifyMotionArgs args3 =
648 generateMotionArgs(0 /*downTime*/, 2 * RESAMPLE_PERIOD, UP, {{4, 5, 200}});
649 args3.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
650 mBlocker->notifyMotion(&args3);
651 mTestListener.assertNotifyMotionWasCalled(WithAction(UP));
652}
653
654/**
655 * Send a mixed touch and stylus event.
656 * The touch event goes first, and is a palm. The stylus event goes down after.
657 * Stylus event should continue to work even after touch is detected as a palm.
658 */
659TEST_F(UnwantedInteractionBlockerTest, TouchIsBlockedWhenMixedWithStylus) {
660 InputDeviceInfo info = generateTestDeviceInfo();
661 info.addSource(AINPUT_SOURCE_STYLUS);
662 mBlocker->notifyInputDevicesChanged({info});
663
664 // Touch down
665 NotifyMotionArgs args1 = generateMotionArgs(0 /*downTime*/, 0 /*eventTime*/, DOWN, {{1, 2, 3}});
666 mBlocker->notifyMotion(&args1);
667 mTestListener.assertNotifyMotionWasCalled(WithAction(DOWN));
668
669 // Stylus pointer down
670 NotifyMotionArgs args2 = generateMotionArgs(0 /*downTime*/, RESAMPLE_PERIOD, POINTER_1_DOWN,
671 {{1, 2, 3}, {10, 20, 30}});
672 args2.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
673 mBlocker->notifyMotion(&args2);
674 mTestListener.assertNotifyMotionWasCalled(WithAction(POINTER_1_DOWN));
675
676 // Large touch oval on the next finger move
677 NotifyMotionArgs args3 = generateMotionArgs(0 /*downTime*/, 2 * RESAMPLE_PERIOD, MOVE,
678 {{1, 2, 300}, {11, 21, 30}});
679 args3.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
680 mBlocker->notifyMotion(&args3);
681 mTestListener.assertNotifyMotionWasCalled(WithAction(MOVE));
682
683 // Lift up the finger pointer. It should be canceled due to the heuristic filter.
684 NotifyMotionArgs args4 = generateMotionArgs(0 /*downTime*/, 3 * RESAMPLE_PERIOD, POINTER_0_UP,
685 {{1, 2, 300}, {11, 21, 30}});
686 args4.pointerProperties[1].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
687 mBlocker->notifyMotion(&args4);
688 mTestListener.assertNotifyMotionWasCalled(
689 AllOf(WithAction(POINTER_0_UP), WithFlags(FLAG_CANCELED)));
690
691 NotifyMotionArgs args5 =
692 generateMotionArgs(0 /*downTime*/, 4 * RESAMPLE_PERIOD, MOVE, {{12, 22, 30}});
693 args5.pointerProperties[0].id = args4.pointerProperties[1].id;
694 args5.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
695 mBlocker->notifyMotion(&args5);
696 mTestListener.assertNotifyMotionWasCalled(WithAction(MOVE));
697
698 // Lift up the stylus pointer
699 NotifyMotionArgs args6 =
700 generateMotionArgs(0 /*downTime*/, 5 * RESAMPLE_PERIOD, UP, {{4, 5, 200}});
701 args6.pointerProperties[0].id = args4.pointerProperties[1].id;
702 args6.pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_STYLUS;
703 mBlocker->notifyMotion(&args6);
704 mTestListener.assertNotifyMotionWasCalled(WithAction(UP));
705}
706
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700707using UnwantedInteractionBlockerTestDeathTest = UnwantedInteractionBlockerTest;
708
709/**
710 * The state should be reset when device reset happens. If we receive an inconsistent event after
711 * the reset happens, crash should occur.
712 */
713TEST_F(UnwantedInteractionBlockerTestDeathTest, InconsistentEventAfterResetCausesACrash) {
714 ScopedSilentDeath _silentDeath;
715 NotifyMotionArgs args;
716 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
717 mBlocker->notifyMotion(
718 &(args = generateMotionArgs(0 /*downTime*/, 1 /*eventTime*/, DOWN, {{1, 2, 3}})));
719 mBlocker->notifyMotion(
720 &(args = generateMotionArgs(0 /*downTime*/, 2 /*eventTime*/, MOVE, {{4, 5, 6}})));
721 NotifyDeviceResetArgs resetArgs(1 /*sequenceNum*/, 3 /*eventTime*/, DEVICE_ID);
722 mBlocker->notifyDeviceReset(&resetArgs);
723 // Sending MOVE without a DOWN -> should crash!
724 ASSERT_DEATH(
725 {
726 mBlocker->notifyMotion(&(args = generateMotionArgs(0 /*downTime*/, 4 /*eventTime*/,
727 MOVE, {{7, 8, 9}})));
728 },
729 "Could not find slot");
730}
731
732/**
733 * There should be a crash when an inconsistent event is received.
734 */
735TEST_F(UnwantedInteractionBlockerTestDeathTest, WhenMoveWithoutDownCausesACrash) {
736 ScopedSilentDeath _silentDeath;
737 NotifyMotionArgs args = generateMotionArgs(0 /*downTime*/, 1 /*eventTime*/, MOVE, {{1, 2, 3}});
738 mBlocker->notifyInputDevicesChanged({generateTestDeviceInfo()});
739 ASSERT_DEATH({ mBlocker->notifyMotion(&args); }, "Could not find slot");
740}
741
742class PalmRejectorTest : public testing::Test {
743protected:
744 std::unique_ptr<PalmRejector> mPalmRejector;
745
746 void SetUp() override {
747 AndroidPalmFilterDeviceInfo info = generatePalmFilterDeviceInfo();
748 mPalmRejector = std::make_unique<PalmRejector>(info);
749 }
750};
751
752using PalmRejectorTestDeathTest = PalmRejectorTest;
753
754TEST_F(PalmRejectorTestDeathTest, InconsistentEventCausesACrash) {
755 ScopedSilentDeath _silentDeath;
756 constexpr nsecs_t downTime = 0;
757 NotifyMotionArgs args =
758 generateMotionArgs(downTime, 2 /*eventTime*/, MOVE, {{1406.0, 650.0, 52.0}});
759 ASSERT_DEATH({ mPalmRejector->processMotion(args); }, "Could not find slot");
760}
761
762/**
763 * Use PalmRejector with actual touchscreen data and real model.
764 * Two pointers that should both be classified as palms.
765 */
766TEST_F(PalmRejectorTest, TwoPointersAreCanceled) {
767 std::vector<NotifyMotionArgs> argsList;
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700768 const nsecs_t downTime = toNs(0ms);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700769
770 mPalmRejector->processMotion(
771 generateMotionArgs(downTime, downTime, DOWN, {{1342.0, 613.0, 79.0}}));
772 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700773 generateMotionArgs(downTime, toNs(8ms), MOVE, {{1406.0, 650.0, 52.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700774 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700775 generateMotionArgs(downTime, toNs(16ms), MOVE, {{1429.0, 672.0, 46.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700776 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700777 generateMotionArgs(downTime, toNs(24ms), MOVE, {{1417.0, 685.0, 41.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700778 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700779 generateMotionArgs(downTime, toNs(32ms), POINTER_1_DOWN,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700780 {{1417.0, 685.0, 41.0}, {1062.0, 697.0, 10.0}}));
781 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700782 generateMotionArgs(downTime, toNs(40ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700783 {{1414.0, 702.0, 41.0}, {1059.0, 731.0, 12.0}}));
784 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700785 generateMotionArgs(downTime, toNs(48ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700786 {{1415.0, 719.0, 44.0}, {1060.0, 760.0, 11.0}}));
787 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700788 generateMotionArgs(downTime, toNs(56ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700789 {{1421.0, 733.0, 42.0}, {1065.0, 769.0, 13.0}}));
790 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700791 generateMotionArgs(downTime, toNs(64ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700792 {{1426.0, 742.0, 43.0}, {1068.0, 771.0, 13.0}}));
793 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700794 generateMotionArgs(downTime, toNs(72ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700795 {{1430.0, 748.0, 45.0}, {1069.0, 772.0, 13.0}}));
796 argsList = mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700797 generateMotionArgs(downTime, toNs(80ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700798 {{1432.0, 750.0, 44.0}, {1069.0, 772.0, 13.0}}));
799 ASSERT_EQ(1u, argsList.size());
800 ASSERT_EQ(0 /* No FLAG_CANCELED */, argsList[0].flags);
801 argsList = mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700802 generateMotionArgs(downTime, toNs(88ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700803 {{1433.0, 751.0, 44.0}, {1070.0, 771.0, 13.0}}));
804 ASSERT_EQ(2u, argsList.size());
805 ASSERT_EQ(POINTER_0_UP, argsList[0].action);
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000806 ASSERT_EQ(FLAG_CANCELED, argsList[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700807 ASSERT_EQ(MOVE, argsList[1].action);
808 ASSERT_EQ(1u, argsList[1].pointerCount);
809 ASSERT_EQ(0, argsList[1].flags);
810
811 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700812 generateMotionArgs(downTime, toNs(96ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700813 {{1433.0, 751.0, 42.0}, {1071.0, 770.0, 13.0}}));
814 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700815 generateMotionArgs(downTime, toNs(104ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700816 {{1433.0, 751.0, 45.0}, {1072.0, 769.0, 13.0}}));
817 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700818 generateMotionArgs(downTime, toNs(112ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700819 {{1433.0, 751.0, 43.0}, {1072.0, 768.0, 13.0}}));
820 argsList = mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700821 generateMotionArgs(downTime, toNs(120ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700822 {{1433.0, 751.0, 45.0}, {1072.0, 767.0, 13.0}}));
823 ASSERT_EQ(1u, argsList.size());
824 ASSERT_EQ(AMOTION_EVENT_ACTION_CANCEL, argsList[0].action);
825 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700826 generateMotionArgs(downTime, toNs(128ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700827 {{1433.0, 751.0, 43.0}, {1072.0, 766.0, 13.0}}));
828 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700829 generateMotionArgs(downTime, toNs(136ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700830 {{1433.0, 750.0, 44.0}, {1072.0, 765.0, 13.0}}));
831 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700832 generateMotionArgs(downTime, toNs(144ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700833 {{1433.0, 750.0, 42.0}, {1072.0, 763.0, 14.0}}));
834 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700835 generateMotionArgs(downTime, toNs(152ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700836 {{1434.0, 750.0, 44.0}, {1073.0, 761.0, 14.0}}));
837 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700838 generateMotionArgs(downTime, toNs(160ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700839 {{1435.0, 750.0, 43.0}, {1073.0, 759.0, 15.0}}));
840 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700841 generateMotionArgs(downTime, toNs(168ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700842 {{1436.0, 750.0, 45.0}, {1074.0, 757.0, 15.0}}));
843 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700844 generateMotionArgs(downTime, toNs(176ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700845 {{1436.0, 750.0, 44.0}, {1074.0, 755.0, 15.0}}));
846 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700847 generateMotionArgs(downTime, toNs(184ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700848 {{1436.0, 750.0, 45.0}, {1074.0, 753.0, 15.0}}));
849 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700850 generateMotionArgs(downTime, toNs(192ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700851 {{1436.0, 749.0, 44.0}, {1074.0, 751.0, 15.0}}));
852 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700853 generateMotionArgs(downTime, toNs(200ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700854 {{1435.0, 748.0, 45.0}, {1074.0, 749.0, 15.0}}));
855 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700856 generateMotionArgs(downTime, toNs(208ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700857 {{1434.0, 746.0, 44.0}, {1074.0, 747.0, 14.0}}));
858 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700859 generateMotionArgs(downTime, toNs(216ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700860 {{1433.0, 744.0, 44.0}, {1075.0, 745.0, 14.0}}));
861 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700862 generateMotionArgs(downTime, toNs(224ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700863 {{1431.0, 741.0, 43.0}, {1075.0, 742.0, 13.0}}));
864 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700865 generateMotionArgs(downTime, toNs(232ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700866 {{1428.0, 738.0, 43.0}, {1076.0, 739.0, 12.0}}));
867 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700868 generateMotionArgs(downTime, toNs(240ms), MOVE,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700869 {{1400.0, 726.0, 54.0}, {1076.0, 739.0, 13.0}}));
870 argsList = mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700871 generateMotionArgs(downTime, toNs(248ms), POINTER_1_UP,
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700872 {{1362.0, 716.0, 55.0}, {1076.0, 739.0, 13.0}}));
873 ASSERT_TRUE(argsList.empty());
874 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700875 generateMotionArgs(downTime, toNs(256ms), MOVE, {{1362.0, 716.0, 55.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700876 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700877 generateMotionArgs(downTime, toNs(264ms), MOVE, {{1347.0, 707.0, 54.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700878 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700879 generateMotionArgs(downTime, toNs(272ms), MOVE, {{1340.0, 698.0, 54.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700880 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700881 generateMotionArgs(downTime, toNs(280ms), MOVE, {{1338.0, 694.0, 55.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700882 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700883 generateMotionArgs(downTime, toNs(288ms), MOVE, {{1336.0, 690.0, 53.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700884 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700885 generateMotionArgs(downTime, toNs(296ms), MOVE, {{1334.0, 685.0, 47.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700886 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700887 generateMotionArgs(downTime, toNs(304ms), MOVE, {{1333.0, 679.0, 46.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700888 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700889 generateMotionArgs(downTime, toNs(312ms), MOVE, {{1332.0, 672.0, 45.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700890 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700891 generateMotionArgs(downTime, toNs(320ms), MOVE, {{1333.0, 666.0, 40.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700892 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700893 generateMotionArgs(downTime, toNs(328ms), MOVE, {{1336.0, 661.0, 24.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700894 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700895 generateMotionArgs(downTime, toNs(336ms), MOVE, {{1338.0, 656.0, 16.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700896 mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700897 generateMotionArgs(downTime, toNs(344ms), MOVE, {{1341.0, 649.0, 1.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700898 argsList = mPalmRejector->processMotion(
Siarhei Vishniakoud5a47632022-06-13 13:56:56 -0700899 generateMotionArgs(downTime, toNs(352ms), UP, {{1341.0, 649.0, 1.0}}));
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700900 ASSERT_TRUE(argsList.empty());
901}
902
903/**
904 * A test implementation of PalmDetectionFilter that allows you to specify which pointer you want
905 * the model to consider 'suppressed'. The pointer is specified using its position (x, y).
906 * Current limitation:
907 * Pointers may not cross each other in space during motion. Otherwise, any pointer with the
908 * position matching the suppressed position will be considered "palm".
909 */
910class TestFilter : public ::ui::PalmDetectionFilter {
911public:
912 TestFilter(::ui::SharedPalmDetectionFilterState* state,
913 std::vector<std::pair<float, float>>& suppressedPointers)
914 : ::ui::PalmDetectionFilter(state), mSuppressedPointers(suppressedPointers) {}
915
916 void Filter(const std::vector<::ui::InProgressTouchEvdev>& touches, ::base::TimeTicks time,
917 std::bitset<::ui::kNumTouchEvdevSlots>* slots_to_hold,
918 std::bitset<::ui::kNumTouchEvdevSlots>* slots_to_suppress) override {
919 updateSuppressedSlots(touches);
920 *slots_to_suppress = mSuppressedSlots;
921 }
922
923 std::string FilterNameForTesting() const override { return "test filter"; }
924
925private:
926 void updateSuppressedSlots(const std::vector<::ui::InProgressTouchEvdev>& touches) {
927 for (::ui::InProgressTouchEvdev touch : touches) {
928 for (const auto& [x, y] : mSuppressedPointers) {
929 const float dx = (touch.x - x);
930 const float dy = (touch.y - y);
931 const float distanceSquared = dx * dx + dy * dy;
932 if (distanceSquared < 1) {
933 mSuppressedSlots.set(touch.slot, true);
934 }
935 }
936 }
937 }
938
939 std::bitset<::ui::kNumTouchEvdevSlots> mSuppressedSlots;
940 std::vector<std::pair<float, float>>& mSuppressedPointers;
941};
942
943class PalmRejectorFakeFilterTest : public testing::Test {
944protected:
945 std::unique_ptr<PalmRejector> mPalmRejector;
946
947 void SetUp() override {
948 std::unique_ptr<::ui::PalmDetectionFilter> filter =
949 std::make_unique<TestFilter>(&mSharedPalmState, /*byref*/ mSuppressedPointers);
950 mPalmRejector =
951 std::make_unique<PalmRejector>(generatePalmFilterDeviceInfo(), std::move(filter));
952 }
953
954 void suppressPointerAtPosition(float x, float y) { mSuppressedPointers.push_back({x, y}); }
955
956private:
957 std::vector<std::pair<float, float>> mSuppressedPointers;
958 ::ui::SharedPalmDetectionFilterState mSharedPalmState; // unused, but we must retain ownership
959};
960
961/**
962 * When a MOVE event happens, the model identifies the pointer as palm. At that time, the palm
963 * rejector should send a POINTER_UP event for this pointer with FLAG_CANCELED, and subsequent
964 * events should have this pointer removed.
965 */
966TEST_F(PalmRejectorFakeFilterTest, OneOfTwoPointersIsCanceled) {
967 std::vector<NotifyMotionArgs> argsList;
968 constexpr nsecs_t downTime = 0;
969
970 mPalmRejector->processMotion(
971 generateMotionArgs(downTime, downTime, DOWN, {{1342.0, 613.0, 79.0}}));
972 mPalmRejector->processMotion(
973 generateMotionArgs(downTime, 1, POINTER_1_DOWN,
974 {{1417.0, 685.0, 41.0}, {1062.0, 697.0, 10.0}}));
975 // Cancel the second pointer
976 suppressPointerAtPosition(1059, 731);
977 argsList = mPalmRejector->processMotion(
978 generateMotionArgs(downTime, 255955783039000, MOVE,
979 {{1414.0, 702.0, 41.0}, {1059.0, 731.0, 12.0}}));
980 ASSERT_EQ(2u, argsList.size());
981 // First event - cancel pointer 1
982 ASSERT_EQ(POINTER_1_UP, argsList[0].action);
Siarhei Vishniakou88151b82022-08-11 00:53:38 +0000983 ASSERT_EQ(FLAG_CANCELED, argsList[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -0700984 // Second event - send MOVE for the remaining pointer
985 ASSERT_EQ(MOVE, argsList[1].action);
986 ASSERT_EQ(0, argsList[1].flags);
987
988 // Future move events only contain 1 pointer, because the second pointer will continue
989 // to be suppressed
990 argsList = mPalmRejector->processMotion(
991 generateMotionArgs(downTime, 255955783039000, MOVE,
992 {{1433.0, 751.0, 43.0}, {1072.0, 766.0, 13.0}}));
993 ASSERT_EQ(1u, argsList.size());
994 ASSERT_EQ(MOVE, argsList[0].action);
995 ASSERT_EQ(1u, argsList[0].pointerCount);
996 ASSERT_EQ(1433, argsList[0].pointerCoords[0].getX());
997 ASSERT_EQ(751, argsList[0].pointerCoords[0].getY());
998}
999
1000/**
1001 * Send two pointers, and suppress both of them. Check that ACTION_CANCEL is generated.
1002 * Afterwards:
1003 * 1) Future MOVE events are ignored.
1004 * 2) When a new pointer goes down, ACTION_DOWN is generated
1005 */
1006TEST_F(PalmRejectorFakeFilterTest, NewDownEventAfterCancel) {
1007 std::vector<NotifyMotionArgs> argsList;
1008 constexpr nsecs_t downTime = 0;
1009
1010 mPalmRejector->processMotion(
1011 generateMotionArgs(downTime, downTime, DOWN, {{1342.0, 613.0, 79.0}}));
1012 mPalmRejector->processMotion(
1013 generateMotionArgs(downTime, 1, POINTER_1_DOWN,
1014 {{1417.0, 685.0, 41.0}, {1062.0, 697.0, 10.0}}));
1015 // Cancel both pointers
1016 suppressPointerAtPosition(1059, 731);
1017 suppressPointerAtPosition(1400, 680);
1018 argsList = mPalmRejector->processMotion(
1019 generateMotionArgs(downTime, 1, MOVE, {{1400, 680, 41}, {1059, 731, 10}}));
1020 ASSERT_EQ(1u, argsList.size());
1021 // Cancel all
1022 ASSERT_EQ(CANCEL, argsList[0].action);
1023 ASSERT_EQ(2u, argsList[0].pointerCount);
Siarhei Vishniakou88151b82022-08-11 00:53:38 +00001024 ASSERT_EQ(FLAG_CANCELED, argsList[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -07001025
1026 // Future move events are ignored
1027 argsList = mPalmRejector->processMotion(
1028 generateMotionArgs(downTime, 255955783039000, MOVE,
1029 {{1433.0, 751.0, 43.0}, {1072.0, 766.0, 13.0}}));
1030 ASSERT_EQ(0u, argsList.size());
1031
1032 // When a new pointer goes down, a new DOWN event is generated
1033 argsList = mPalmRejector->processMotion(
1034 generateMotionArgs(downTime, 255955783039000, POINTER_2_DOWN,
1035 {{1433.0, 751.0, 43.0}, {1072.0, 766.0, 13.0}, {1000, 700, 10}}));
1036 ASSERT_EQ(1u, argsList.size());
1037 ASSERT_EQ(DOWN, argsList[0].action);
1038 ASSERT_EQ(1u, argsList[0].pointerCount);
1039 ASSERT_EQ(2, argsList[0].pointerProperties[0].id);
1040}
1041
1042/**
1043 * 2 pointers are classified as palm simultaneously. When they are later
1044 * released by Android, make sure that we drop both of these POINTER_UP events.
1045 * Since they are classified as palm at the same time, we just need to receive a single CANCEL
1046 * event. From MotionEvent docs: """A pointer id remains valid until the pointer eventually goes up
1047 * (indicated by ACTION_UP or ACTION_POINTER_UP) or when the gesture is canceled (indicated by
1048 * ACTION_CANCEL)."""
1049 * This means that generating additional POINTER_UP events is not necessary.
1050 * The risk here is that "oldSuppressedPointerIds" will not be correct, because it will update after
1051 * each motion, but pointers are canceled one at a time by Android.
1052 */
1053TEST_F(PalmRejectorFakeFilterTest, TwoPointersCanceledWhenOnePointerGoesUp) {
1054 std::vector<NotifyMotionArgs> argsList;
1055 constexpr nsecs_t downTime = 0;
1056
1057 mPalmRejector->processMotion(
1058 generateMotionArgs(downTime, downTime, DOWN, {{1342.0, 613.0, 79.0}}));
1059 mPalmRejector->processMotion(
1060 generateMotionArgs(downTime, /*eventTime*/ 1, POINTER_1_DOWN,
1061 {{1417.0, 685.0, 41.0}, {1062.0, 697.0, 10.0}}));
1062 // Suppress both pointers!!
1063 suppressPointerAtPosition(1414, 702);
1064 suppressPointerAtPosition(1059, 731);
1065 argsList = mPalmRejector->processMotion(
1066 generateMotionArgs(downTime, 255955783039000, POINTER_1_UP,
1067 {{1414.0, 702.0, 41.0}, {1059.0, 731.0, 12.0}}));
1068 ASSERT_EQ(1u, argsList.size());
1069 ASSERT_EQ(CANCEL, argsList[0].action) << MotionEvent::actionToString(argsList[0].action);
Siarhei Vishniakou88151b82022-08-11 00:53:38 +00001070 ASSERT_EQ(FLAG_CANCELED, argsList[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -07001071
1072 // Future move events should not go to the listener.
1073 argsList = mPalmRejector->processMotion(
1074 generateMotionArgs(downTime, 255955783049000, MOVE, {{1435.0, 755.0, 43.0}}));
1075 ASSERT_EQ(0u, argsList.size());
1076
1077 argsList = mPalmRejector->processMotion(
1078 generateMotionArgs(downTime, 255955783059000, UP, {{1436.0, 756.0, 43.0}}));
1079 ASSERT_EQ(0u, argsList.size());
1080}
1081
1082/**
1083 * Send 3 pointers, and then cancel one of them during a MOVE event. We should see ACTION_POINTER_UP
1084 * generated for that. Next, another pointer is canceled during ACTION_POINTER_DOWN. For that
1085 * pointer, we simply shouldn't send the event.
1086 */
1087TEST_F(PalmRejectorFakeFilterTest, CancelTwoPointers) {
1088 std::vector<NotifyMotionArgs> argsList;
1089 constexpr nsecs_t downTime = 0;
1090
1091 mPalmRejector->processMotion(
1092 generateMotionArgs(downTime, downTime, DOWN, {{1342.0, 613.0, 79.0}}));
1093 mPalmRejector->processMotion(
1094 generateMotionArgs(downTime, /*eventTime*/ 1, POINTER_1_DOWN,
1095 {{1417.0, 685.0, 41.0}, {1062.0, 697.0, 10.0}}));
1096
1097 // Suppress second pointer (pointer 1)
1098 suppressPointerAtPosition(1060, 700);
1099 argsList = mPalmRejector->processMotion(
1100 generateMotionArgs(downTime, /*eventTime*/ 1, MOVE,
1101 {{1417.0, 685.0, 41.0}, {1060, 700, 10.0}}));
1102 ASSERT_EQ(2u, argsList.size());
1103 ASSERT_EQ(POINTER_1_UP, argsList[0].action);
Siarhei Vishniakou88151b82022-08-11 00:53:38 +00001104 ASSERT_EQ(FLAG_CANCELED, argsList[0].flags);
Siarhei Vishniakouba0a8752021-09-14 14:43:25 -07001105
1106 ASSERT_EQ(MOVE, argsList[1].action) << MotionEvent::actionToString(argsList[1].action);
1107 ASSERT_EQ(0, argsList[1].flags);
1108
1109 // A new pointer goes down and gets suppressed right away. It should just be dropped
1110 suppressPointerAtPosition(1001, 601);
1111 argsList = mPalmRejector->processMotion(
1112 generateMotionArgs(downTime, /*eventTime*/ 1, POINTER_2_DOWN,
1113 {{1417.0, 685.0, 41.0}, {1062.0, 697.0, 10.0}, {1001, 601, 5}}));
1114
1115 ASSERT_EQ(0u, argsList.size());
1116 // Likewise, pointer that's already canceled should be ignored
1117 argsList = mPalmRejector->processMotion(
1118 generateMotionArgs(downTime, /*eventTime*/ 1, POINTER_2_UP,
1119 {{1417.0, 685.0, 41.0}, {1062.0, 697.0, 10.0}, {1001, 601, 5}}));
1120 ASSERT_EQ(0u, argsList.size());
1121
1122 // Cancel all pointers when pointer 1 goes up. Pointer 1 was already canceled earlier.
1123 suppressPointerAtPosition(1417, 685);
1124 argsList = mPalmRejector->processMotion(
1125 generateMotionArgs(downTime, /*eventTime*/ 1, POINTER_1_UP,
1126 {{1417.0, 685.0, 41.0}, {1062.0, 697.0, 10.0}}));
1127 ASSERT_EQ(1u, argsList.size());
1128 ASSERT_EQ(CANCEL, argsList[0].action);
1129}
1130
1131} // namespace android