blob: 35430207f9bed5663ec3e9b34b77344516acfa9c [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
2 * Copyright (C) 2010 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 "TestHelpers.h"
18
chaviw09c8d2d2020-08-24 15:48:26 -070019#include <attestation/HmacKeyManager.h>
Jeff Brown5912f952013-07-01 19:10:31 -070020#include <gtest/gtest.h>
chaviw3277faf2021-05-19 16:45:23 -050021#include <gui/constants.h>
Jeff Brown5912f952013-07-01 19:10:31 -070022#include <input/InputTransport.h>
Jeff Brown5912f952013-07-01 19:10:31 -070023
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +000024using android::base::Result;
25
Jeff Brown5912f952013-07-01 19:10:31 -070026namespace android {
27
Siarhei Vishniakou6252af72023-09-20 09:00:38 -070028namespace {
29
30static constexpr float EPSILON = MotionEvent::ROUNDING_PRECISION;
31static constexpr int32_t POINTER_1_DOWN =
32 AMOTION_EVENT_ACTION_POINTER_DOWN | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
33static constexpr int32_t POINTER_2_DOWN =
34 AMOTION_EVENT_ACTION_POINTER_DOWN | (2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
35
36struct Pointer {
37 int32_t id;
38 float x;
39 float y;
40 bool isResampled = false;
41};
42
Egor Paskoa0d32af2023-12-14 17:45:41 +010043// A collection of arguments to be sent as publishMotionEvent(). The saved members of this struct
44// allow to check the expectations against the event acquired from the InputReceiver. To help
45// simplify expectation checking it carries members not present in MotionEvent, like |rawXScale|.
46struct PublishMotionArgs {
47 const int32_t action;
48 const nsecs_t downTime;
49 const uint32_t seq;
50 const int32_t eventId;
51 const int32_t deviceId = 1;
52 const uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
53 const int32_t displayId = ADISPLAY_ID_DEFAULT;
54 const int32_t actionButton = 0;
55 const int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
56 const int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
57 const int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
58 const MotionClassification classification = MotionClassification::AMBIGUOUS_GESTURE;
59 const float xScale = 2;
60 const float yScale = 3;
61 const float xOffset = -10;
62 const float yOffset = -20;
63 const float rawXScale = 4;
64 const float rawYScale = -5;
65 const float rawXOffset = -11;
66 const float rawYOffset = 42;
67 const float xPrecision = 0.25;
68 const float yPrecision = 0.5;
69 const float xCursorPosition = 1.3;
70 const float yCursorPosition = 50.6;
71 std::array<uint8_t, 32> hmac;
72 int32_t flags;
73 ui::Transform transform;
74 ui::Transform rawTransform;
75 const nsecs_t eventTime;
76 size_t pointerCount;
77 std::vector<PointerProperties> pointerProperties;
78 std::vector<PointerCoords> pointerCoords;
79
80 PublishMotionArgs(int32_t action, nsecs_t downTime, const std::vector<Pointer>& pointers,
81 const uint32_t seq);
82};
83
84PublishMotionArgs::PublishMotionArgs(int32_t inAction, nsecs_t inDownTime,
85 const std::vector<Pointer>& pointers, const uint32_t inSeq)
86 : action(inAction),
87 downTime(inDownTime),
88 seq(inSeq),
89 eventId(InputEvent::nextId()),
90 eventTime(systemTime(SYSTEM_TIME_MONOTONIC)) {
91 hmac = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
92 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
93
94 flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
95 if (action == AMOTION_EVENT_ACTION_CANCEL) {
96 flags |= AMOTION_EVENT_FLAG_CANCELED;
97 }
98 pointerCount = pointers.size();
99 for (size_t i = 0; i < pointerCount; i++) {
100 pointerProperties.push_back({});
101 pointerProperties[i].clear();
102 pointerProperties[i].id = pointers[i].id;
103 pointerProperties[i].toolType = ToolType::FINGER;
104
105 pointerCoords.push_back({});
106 pointerCoords[i].clear();
107 pointerCoords[i].isResampled = pointers[i].isResampled;
108 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, pointers[i].x);
109 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, pointers[i].y);
110 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
111 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
112 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
113 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
114 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
115 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
116 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
117 }
118 transform.set({xScale, 0, xOffset, 0, yScale, yOffset, 0, 0, 1});
119 rawTransform.set({rawXScale, 0, rawXOffset, 0, rawYScale, rawYOffset, 0, 0, 1});
120}
121
122// Checks expectations against |motionEvent| acquired from an InputConsumer. Floating point
123// comparisons limit precision to EPSILON.
124void verifyArgsEqualToEvent(const PublishMotionArgs& args, const MotionEvent& motionEvent) {
125 EXPECT_EQ(args.eventId, motionEvent.getId());
126 EXPECT_EQ(args.deviceId, motionEvent.getDeviceId());
127 EXPECT_EQ(args.source, motionEvent.getSource());
128 EXPECT_EQ(args.displayId, motionEvent.getDisplayId());
129 EXPECT_EQ(args.hmac, motionEvent.getHmac());
130 EXPECT_EQ(args.action, motionEvent.getAction());
131 EXPECT_EQ(args.downTime, motionEvent.getDownTime());
132 EXPECT_EQ(args.flags, motionEvent.getFlags());
133 EXPECT_EQ(args.edgeFlags, motionEvent.getEdgeFlags());
134 EXPECT_EQ(args.metaState, motionEvent.getMetaState());
135 EXPECT_EQ(args.buttonState, motionEvent.getButtonState());
136 EXPECT_EQ(args.classification, motionEvent.getClassification());
137 EXPECT_EQ(args.transform, motionEvent.getTransform());
138 EXPECT_EQ(args.xOffset, motionEvent.getXOffset());
139 EXPECT_EQ(args.yOffset, motionEvent.getYOffset());
140 EXPECT_EQ(args.xPrecision, motionEvent.getXPrecision());
141 EXPECT_EQ(args.yPrecision, motionEvent.getYPrecision());
142 EXPECT_NEAR(args.xCursorPosition, motionEvent.getRawXCursorPosition(), EPSILON);
143 EXPECT_NEAR(args.yCursorPosition, motionEvent.getRawYCursorPosition(), EPSILON);
144 EXPECT_NEAR(args.xCursorPosition * args.xScale + args.xOffset, motionEvent.getXCursorPosition(),
145 EPSILON);
146 EXPECT_NEAR(args.yCursorPosition * args.yScale + args.yOffset, motionEvent.getYCursorPosition(),
147 EPSILON);
148 EXPECT_EQ(args.rawTransform, motionEvent.getRawTransform());
149 EXPECT_EQ(args.eventTime, motionEvent.getEventTime());
150 EXPECT_EQ(args.pointerCount, motionEvent.getPointerCount());
151 EXPECT_EQ(0U, motionEvent.getHistorySize());
152
153 for (size_t i = 0; i < args.pointerCount; i++) {
154 SCOPED_TRACE(i);
155 EXPECT_EQ(args.pointerProperties[i].id, motionEvent.getPointerId(i));
156 EXPECT_EQ(args.pointerProperties[i].toolType, motionEvent.getToolType(i));
157
158 const auto& pc = args.pointerCoords[i];
159 EXPECT_EQ(pc, motionEvent.getSamplePointerCoords()[i]);
160
161 EXPECT_NEAR(pc.getX() * args.rawXScale + args.rawXOffset, motionEvent.getRawX(i), EPSILON);
162 EXPECT_NEAR(pc.getY() * args.rawYScale + args.rawYOffset, motionEvent.getRawY(i), EPSILON);
163 EXPECT_NEAR(pc.getX() * args.xScale + args.xOffset, motionEvent.getX(i), EPSILON);
164 EXPECT_NEAR(pc.getY() * args.yScale + args.yOffset, motionEvent.getY(i), EPSILON);
165 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), motionEvent.getPressure(i));
166 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_SIZE), motionEvent.getSize(i));
167 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), motionEvent.getTouchMajor(i));
168 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), motionEvent.getTouchMinor(i));
169 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), motionEvent.getToolMajor(i));
170 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), motionEvent.getToolMinor(i));
171
172 // Calculate the orientation after scaling, keeping in mind that an orientation of 0 is
173 // "up", and the positive y direction is "down".
174 const float unscaledOrientation = pc.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION);
175 const float x = sinf(unscaledOrientation) * args.xScale;
176 const float y = -cosf(unscaledOrientation) * args.yScale;
177 EXPECT_EQ(atan2f(x, -y), motionEvent.getOrientation(i));
178 }
179}
180
181void publishMotionEvent(InputPublisher& publisher, const PublishMotionArgs& a) {
182 status_t status =
183 publisher.publishMotionEvent(a.seq, a.eventId, a.deviceId, a.source, a.displayId,
184 a.hmac, a.action, a.actionButton, a.flags, a.edgeFlags,
185 a.metaState, a.buttonState, a.classification, a.transform,
186 a.xPrecision, a.yPrecision, a.xCursorPosition,
187 a.yCursorPosition, a.rawTransform, a.downTime, a.eventTime,
188 a.pointerCount, a.pointerProperties.data(),
189 a.pointerCoords.data());
190 ASSERT_EQ(OK, status) << "publisher publishMotionEvent should return OK";
191}
192
193void sendAndVerifyFinishedSignal(InputConsumer& consumer, InputPublisher& publisher, uint32_t seq,
194 nsecs_t publishTime) {
195 status_t status = consumer.sendFinishedSignal(seq, false);
196 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
197 Result<InputPublisher::ConsumerResponse> result = publisher.receiveConsumerResponse();
198 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
199 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
200 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
201 ASSERT_EQ(seq, finish.seq)
202 << "receiveConsumerResponse should have returned the original sequence number";
203 ASSERT_FALSE(finish.handled)
204 << "receiveConsumerResponse should have set handled to consumer's reply";
205 ASSERT_GE(finish.consumeTime, publishTime)
206 << "finished signal's consume time should be greater than publish time";
207}
208
209void waitUntilInputAvailable(const InputConsumer& inputConsumer) {
210 bool hasInput;
211 do {
212 // The probablyHasInput() can return false positive under rare circumstances uncontrollable
213 // by the tests. Re-request the availability in this case. Returning |false| for a long
214 // time is not intended, and would cause a test timeout.
215 hasInput = inputConsumer.probablyHasInput();
216 } while (!hasInput);
217}
218
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700219} // namespace
Prabir Pradhan00e029d2023-03-09 20:11:09 +0000220
Jeff Brown5912f952013-07-01 19:10:31 -0700221class InputPublisherAndConsumerTest : public testing::Test {
222protected:
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500223 std::unique_ptr<InputPublisher> mPublisher;
224 std::unique_ptr<InputConsumer> mConsumer;
Jeff Brown5912f952013-07-01 19:10:31 -0700225 PreallocatedInputEventFactory mEventFactory;
226
Siarhei Vishniakoud2588272020-07-10 11:15:40 -0500227 void SetUp() override {
228 std::unique_ptr<InputChannel> serverChannel, clientChannel;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -0800229 status_t result = InputChannel::openInputChannelPair("channel name",
Jeff Brown5912f952013-07-01 19:10:31 -0700230 serverChannel, clientChannel);
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800231 ASSERT_EQ(OK, result);
Jeff Brown5912f952013-07-01 19:10:31 -0700232
Siarhei Vishniakou7b9f4f52024-02-02 13:07:16 -0800233 mPublisher = std::make_unique<InputPublisher>(std::move(serverChannel));
234 mConsumer = std::make_unique<InputConsumer>(std::move(clientChannel));
Jeff Brown5912f952013-07-01 19:10:31 -0700235 }
236
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700237 void publishAndConsumeKeyEvent();
238 void publishAndConsumeMotionStream();
Egor Paskoa0d32af2023-12-14 17:45:41 +0100239 void publishAndConsumeMotionDown(nsecs_t downTime);
240 void publishAndConsumeBatchedMotionMove(nsecs_t downTime);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700241 void publishAndConsumeFocusEvent();
242 void publishAndConsumeCaptureEvent();
243 void publishAndConsumeDragEvent();
244 void publishAndConsumeTouchModeEvent();
245 void publishAndConsumeMotionEvent(int32_t action, nsecs_t downTime,
246 const std::vector<Pointer>& pointers);
247
248private:
249 // The sequence number to use when publishing the next event
250 uint32_t mSeq = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700251};
252
253TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
Siarhei Vishniakou7b9f4f52024-02-02 13:07:16 -0800254 ASSERT_EQ(mPublisher->getChannel().getConnectionToken(),
Siarhei Vishniakoua1188f52020-10-20 20:14:52 -0500255 mConsumer->getChannel()->getConnectionToken());
Jeff Brown5912f952013-07-01 19:10:31 -0700256}
257
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700258void InputPublisherAndConsumerTest::publishAndConsumeKeyEvent() {
Jeff Brown5912f952013-07-01 19:10:31 -0700259 status_t status;
260
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700261 const uint32_t seq = mSeq++;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800262 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100263 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600264 constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100265 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600266 constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
267 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
268 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100269 constexpr int32_t action = AKEY_EVENT_ACTION_DOWN;
270 constexpr int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
271 constexpr int32_t keyCode = AKEYCODE_ENTER;
272 constexpr int32_t scanCode = 13;
273 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
274 constexpr int32_t repeatCount = 1;
275 constexpr nsecs_t downTime = 3;
276 constexpr nsecs_t eventTime = 4;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000277 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Jeff Brown5912f952013-07-01 19:10:31 -0700278
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800279 status = mPublisher->publishKeyEvent(seq, eventId, deviceId, source, displayId, hmac, action,
280 flags, keyCode, scanCode, metaState, repeatCount, downTime,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600281 eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700282 ASSERT_EQ(OK, status)
283 << "publisher publishKeyEvent should return OK";
284
Egor Paskoa0d32af2023-12-14 17:45:41 +0100285 waitUntilInputAvailable(*mConsumer);
Jeff Brown5912f952013-07-01 19:10:31 -0700286 uint32_t consumeSeq;
287 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000288 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700289 ASSERT_EQ(OK, status)
290 << "consumer consume should return OK";
Egor Paskoa0d32af2023-12-14 17:45:41 +0100291 EXPECT_FALSE(mConsumer->probablyHasInput())
292 << "no events should be waiting after being consumed";
Jeff Brown5912f952013-07-01 19:10:31 -0700293
Yi Kong5bed83b2018-07-17 12:53:47 -0700294 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700295 << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700296 ASSERT_EQ(InputEventType::KEY, event->getType()) << "consumer should have returned a key event";
Jeff Brown5912f952013-07-01 19:10:31 -0700297
298 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
299 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800300 EXPECT_EQ(eventId, keyEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700301 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
302 EXPECT_EQ(source, keyEvent->getSource());
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100303 EXPECT_EQ(displayId, keyEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600304 EXPECT_EQ(hmac, keyEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700305 EXPECT_EQ(action, keyEvent->getAction());
306 EXPECT_EQ(flags, keyEvent->getFlags());
307 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
308 EXPECT_EQ(scanCode, keyEvent->getScanCode());
309 EXPECT_EQ(metaState, keyEvent->getMetaState());
310 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
311 EXPECT_EQ(downTime, keyEvent->getDownTime());
312 EXPECT_EQ(eventTime, keyEvent->getEventTime());
313
314 status = mConsumer->sendFinishedSignal(seq, true);
315 ASSERT_EQ(OK, status)
316 << "consumer sendFinishedSignal should return OK";
317
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000318 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
319 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
320 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
321 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
322 ASSERT_EQ(seq, finish.seq)
323 << "receiveConsumerResponse should have returned the original sequence number";
324 ASSERT_TRUE(finish.handled)
325 << "receiveConsumerResponse should have set handled to consumer's reply";
326 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000327 << "finished signal's consume time should be greater than publish time";
Jeff Brown5912f952013-07-01 19:10:31 -0700328}
329
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700330void InputPublisherAndConsumerTest::publishAndConsumeMotionStream() {
331 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
Jeff Brown5912f952013-07-01 19:10:31 -0700332
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700333 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
334 {Pointer{.id = 0, .x = 20, .y = 30}});
335
336 publishAndConsumeMotionEvent(POINTER_1_DOWN, downTime,
337 {Pointer{.id = 0, .x = 20, .y = 30},
338 Pointer{.id = 1, .x = 200, .y = 300}});
339
340 publishAndConsumeMotionEvent(POINTER_2_DOWN, downTime,
341 {Pointer{.id = 0, .x = 20, .y = 30},
342 Pointer{.id = 1, .x = 200, .y = 300},
343 Pointer{.id = 2, .x = 300, .y = 400}});
344
345 // Provide a consistent input stream - cancel the gesture that was started above
346 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_CANCEL, downTime,
347 {Pointer{.id = 0, .x = 20, .y = 30},
348 Pointer{.id = 1, .x = 200, .y = 300},
349 Pointer{.id = 2, .x = 300, .y = 400}});
350}
351
Egor Paskoa0d32af2023-12-14 17:45:41 +0100352void InputPublisherAndConsumerTest::publishAndConsumeMotionDown(nsecs_t downTime) {
353 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
354 {Pointer{.id = 0, .x = 20, .y = 30}});
355}
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700356
Egor Paskoa0d32af2023-12-14 17:45:41 +0100357void InputPublisherAndConsumerTest::publishAndConsumeBatchedMotionMove(nsecs_t downTime) {
358 uint32_t seq = mSeq++;
359 const std::vector<Pointer> pointers = {Pointer{.id = 0, .x = 20, .y = 30}};
360 PublishMotionArgs args(AMOTION_EVENT_ACTION_MOVE, downTime, pointers, seq);
361 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
362 publishMotionEvent(*mPublisher, args);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700363
Egor Paskoa0d32af2023-12-14 17:45:41 +0100364 // Consume leaving a batch behind.
365 uint32_t consumeSeq;
366 InputEvent* event;
367 status_t status = mConsumer->consume(&mEventFactory,
368 /*consumeBatches=*/false, -1, &consumeSeq, &event);
369 ASSERT_EQ(WOULD_BLOCK, status)
370 << "consumer consume should return WOULD_BLOCK when a new batch is started";
371 ASSERT_TRUE(mConsumer->hasPendingBatch()) << "consume should have created a batch";
372 EXPECT_TRUE(mConsumer->probablyHasInput())
373 << "should deterministically have input because there is a batch";
374 sendAndVerifyFinishedSignal(*mConsumer, *mPublisher, seq, publishTime);
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700375}
376
377void InputPublisherAndConsumerTest::publishAndConsumeMotionEvent(
Egor Paskoa0d32af2023-12-14 17:45:41 +0100378 int32_t action, nsecs_t downTime, const std::vector<Pointer>& pointers) {
379 uint32_t seq = mSeq++;
380 PublishMotionArgs args(action, downTime, pointers, seq);
381 nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
382 publishMotionEvent(*mPublisher, args);
Jeff Brown5912f952013-07-01 19:10:31 -0700383
384 uint32_t consumeSeq;
385 InputEvent* event;
Egor Paskoa0d32af2023-12-14 17:45:41 +0100386 status_t status =
387 mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
388 ASSERT_EQ(OK, status) << "consumer consume should return OK";
Yi Kong5bed83b2018-07-17 12:53:47 -0700389 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700390 << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700391 ASSERT_EQ(InputEventType::MOTION, event->getType())
Jeff Brown5912f952013-07-01 19:10:31 -0700392 << "consumer should have returned a motion event";
Jeff Brown5912f952013-07-01 19:10:31 -0700393 EXPECT_EQ(seq, consumeSeq);
Jeff Brown5912f952013-07-01 19:10:31 -0700394
Egor Paskoa0d32af2023-12-14 17:45:41 +0100395 verifyArgsEqualToEvent(args, static_cast<const MotionEvent&>(*event));
396 sendAndVerifyFinishedSignal(*mConsumer, *mPublisher, seq, publishTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700397}
398
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700399void InputPublisherAndConsumerTest::publishAndConsumeFocusEvent() {
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800400 status_t status;
401
402 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800403 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800404 constexpr bool hasFocus = true;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000405 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800406
Antonio Kantek3cfec7b2021-11-05 18:26:17 -0700407 status = mPublisher->publishFocusEvent(seq, eventId, hasFocus);
arthurhung7632c332020-12-30 16:58:01 +0800408 ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK";
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800409
410 uint32_t consumeSeq;
411 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000412 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800413 ASSERT_EQ(OK, status) << "consumer consume should return OK";
414
415 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700416 ASSERT_EQ(InputEventType::FOCUS, event->getType())
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800417 << "consumer should have returned a focus event";
418
419 FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
420 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800421 EXPECT_EQ(eventId, focusEvent->getId());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800422 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800423
424 status = mConsumer->sendFinishedSignal(seq, true);
425 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
426
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000427 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
428 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
429 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
430 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000431
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000432 ASSERT_EQ(seq, finish.seq)
433 << "receiveConsumerResponse should have returned the original sequence number";
434 ASSERT_TRUE(finish.handled)
435 << "receiveConsumerResponse should have set handled to consumer's reply";
436 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000437 << "finished signal's consume time should be greater than publish time";
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800438}
439
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700440void InputPublisherAndConsumerTest::publishAndConsumeCaptureEvent() {
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800441 status_t status;
442
443 constexpr uint32_t seq = 42;
444 int32_t eventId = InputEvent::nextId();
445 constexpr bool captureEnabled = true;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000446 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800447
448 status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled);
arthurhung7632c332020-12-30 16:58:01 +0800449 ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK";
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800450
451 uint32_t consumeSeq;
452 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000453 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800454 ASSERT_EQ(OK, status) << "consumer consume should return OK";
455
456 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700457 ASSERT_EQ(InputEventType::CAPTURE, event->getType())
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800458 << "consumer should have returned a capture event";
459
460 const CaptureEvent* captureEvent = static_cast<CaptureEvent*>(event);
461 EXPECT_EQ(seq, consumeSeq);
462 EXPECT_EQ(eventId, captureEvent->getId());
463 EXPECT_EQ(captureEnabled, captureEvent->getPointerCaptureEnabled());
464
465 status = mConsumer->sendFinishedSignal(seq, true);
466 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
467
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000468 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
469 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
470 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
471 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
472 ASSERT_EQ(seq, finish.seq)
473 << "receiveConsumerResponse should have returned the original sequence number";
474 ASSERT_TRUE(finish.handled)
475 << "receiveConsumerResponse should have set handled to consumer's reply";
476 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000477 << "finished signal's consume time should be greater than publish time";
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800478}
479
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700480void InputPublisherAndConsumerTest::publishAndConsumeDragEvent() {
arthurhung7632c332020-12-30 16:58:01 +0800481 status_t status;
482
483 constexpr uint32_t seq = 15;
484 int32_t eventId = InputEvent::nextId();
485 constexpr bool isExiting = false;
486 constexpr float x = 10;
487 constexpr float y = 15;
488 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
489
490 status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting);
491 ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK";
492
493 uint32_t consumeSeq;
494 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000495 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
arthurhung7632c332020-12-30 16:58:01 +0800496 ASSERT_EQ(OK, status) << "consumer consume should return OK";
497
498 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700499 ASSERT_EQ(InputEventType::DRAG, event->getType())
arthurhung7632c332020-12-30 16:58:01 +0800500 << "consumer should have returned a drag event";
501
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000502 const DragEvent& dragEvent = static_cast<const DragEvent&>(*event);
arthurhung7632c332020-12-30 16:58:01 +0800503 EXPECT_EQ(seq, consumeSeq);
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000504 EXPECT_EQ(eventId, dragEvent.getId());
505 EXPECT_EQ(isExiting, dragEvent.isExiting());
506 EXPECT_EQ(x, dragEvent.getX());
507 EXPECT_EQ(y, dragEvent.getY());
arthurhung7632c332020-12-30 16:58:01 +0800508
509 status = mConsumer->sendFinishedSignal(seq, true);
510 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
511
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000512 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
513 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
514 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
515 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
516 ASSERT_EQ(seq, finish.seq)
517 << "receiveConsumerResponse should have returned the original sequence number";
518 ASSERT_TRUE(finish.handled)
519 << "receiveConsumerResponse should have set handled to consumer's reply";
520 ASSERT_GE(finish.consumeTime, publishTime)
arthurhung7632c332020-12-30 16:58:01 +0800521 << "finished signal's consume time should be greater than publish time";
522}
523
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700524void InputPublisherAndConsumerTest::publishAndConsumeTouchModeEvent() {
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700525 status_t status;
526
527 constexpr uint32_t seq = 15;
528 int32_t eventId = InputEvent::nextId();
529 constexpr bool touchModeEnabled = true;
530 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
531
532 status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled);
533 ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK";
534
535 uint32_t consumeSeq;
536 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000537 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700538 ASSERT_EQ(OK, status) << "consumer consume should return OK";
539
540 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700541 ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType())
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700542 << "consumer should have returned a touch mode event";
543
544 const TouchModeEvent& touchModeEvent = static_cast<const TouchModeEvent&>(*event);
545 EXPECT_EQ(seq, consumeSeq);
546 EXPECT_EQ(eventId, touchModeEvent.getId());
547 EXPECT_EQ(touchModeEnabled, touchModeEvent.isInTouchMode());
548
549 status = mConsumer->sendFinishedSignal(seq, true);
550 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
551
552 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
553 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
554 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
555 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
556 ASSERT_EQ(seq, finish.seq)
557 << "receiveConsumerResponse should have returned the original sequence number";
558 ASSERT_TRUE(finish.handled)
559 << "receiveConsumerResponse should have set handled to consumer's reply";
560 ASSERT_GE(finish.consumeTime, publishTime)
561 << "finished signal's consume time should be greater than publish time";
562}
563
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000564TEST_F(InputPublisherAndConsumerTest, SendTimeline) {
565 const int32_t inputEventId = 20;
566 std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
567 graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 30;
568 graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 40;
569 status_t status = mConsumer->sendTimeline(inputEventId, graphicsTimeline);
570 ASSERT_EQ(OK, status);
571
572 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
573 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
574 ASSERT_TRUE(std::holds_alternative<InputPublisher::Timeline>(*result));
575 const InputPublisher::Timeline& timeline = std::get<InputPublisher::Timeline>(*result);
576 ASSERT_EQ(inputEventId, timeline.inputEventId);
577 ASSERT_EQ(graphicsTimeline, timeline.graphicsTimeline);
578}
579
Jeff Brown5912f952013-07-01 19:10:31 -0700580TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700581 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700582}
583
584TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700585 ASSERT_NO_FATAL_FAILURE(publishAndConsumeMotionStream());
Jeff Brown5912f952013-07-01 19:10:31 -0700586}
587
Egor Paskoa0d32af2023-12-14 17:45:41 +0100588TEST_F(InputPublisherAndConsumerTest, PublishMotionMoveEvent_EndToEnd) {
589 // Publish a DOWN event before MOVE to pass the InputVerifier checks.
590 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
591 ASSERT_NO_FATAL_FAILURE(publishAndConsumeMotionDown(downTime));
592
593 // Publish the MOVE event and check expectations.
594 ASSERT_NO_FATAL_FAILURE(publishAndConsumeBatchedMotionMove(downTime));
595}
596
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800597TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700598 ASSERT_NO_FATAL_FAILURE(publishAndConsumeFocusEvent());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800599}
600
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800601TEST_F(InputPublisherAndConsumerTest, PublishCaptureEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700602 ASSERT_NO_FATAL_FAILURE(publishAndConsumeCaptureEvent());
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800603}
604
arthurhung7632c332020-12-30 16:58:01 +0800605TEST_F(InputPublisherAndConsumerTest, PublishDragEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700606 ASSERT_NO_FATAL_FAILURE(publishAndConsumeDragEvent());
arthurhung7632c332020-12-30 16:58:01 +0800607}
608
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700609TEST_F(InputPublisherAndConsumerTest, PublishTouchModeEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700610 ASSERT_NO_FATAL_FAILURE(publishAndConsumeTouchModeEvent());
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700611}
612
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800613TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700614 status_t status;
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800615 const size_t pointerCount = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700616 PointerProperties pointerProperties[pointerCount];
617 PointerCoords pointerCoords[pointerCount];
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800618 for (size_t i = 0; i < pointerCount; i++) {
619 pointerProperties[i].clear();
620 pointerCoords[i].clear();
621 }
Jeff Brown5912f952013-07-01 19:10:31 -0700622
chaviw9eaa22c2020-07-01 16:21:27 -0700623 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700624 status =
625 mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
626 0, 0, 0, MotionClassification::NONE, identityTransform,
627 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
628 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
629 0, 0, pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700630 ASSERT_EQ(BAD_VALUE, status)
631 << "publisher publishMotionEvent should return BAD_VALUE";
632}
633
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800634TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
635 status_t status;
636 const size_t pointerCount = 0;
637 PointerProperties pointerProperties[pointerCount];
638 PointerCoords pointerCoords[pointerCount];
639
chaviw9eaa22c2020-07-01 16:21:27 -0700640 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700641 status =
642 mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
643 0, 0, 0, MotionClassification::NONE, identityTransform,
644 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
645 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
646 0, 0, pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800647 ASSERT_EQ(BAD_VALUE, status)
648 << "publisher publishMotionEvent should return BAD_VALUE";
649}
650
651TEST_F(InputPublisherAndConsumerTest,
652 PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700653 status_t status;
654 const size_t pointerCount = MAX_POINTERS + 1;
655 PointerProperties pointerProperties[pointerCount];
656 PointerCoords pointerCoords[pointerCount];
657 for (size_t i = 0; i < pointerCount; i++) {
658 pointerProperties[i].clear();
659 pointerCoords[i].clear();
660 }
661
chaviw9eaa22c2020-07-01 16:21:27 -0700662 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700663 status =
664 mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
665 0, 0, 0, MotionClassification::NONE, identityTransform,
666 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
667 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
668 0, 0, pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700669 ASSERT_EQ(BAD_VALUE, status)
670 << "publisher publishMotionEvent should return BAD_VALUE";
671}
672
673TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700674 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
675
676 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
677 {Pointer{.id = 0, .x = 20, .y = 30}});
678 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
679 publishAndConsumeMotionEvent(POINTER_1_DOWN, downTime,
680 {Pointer{.id = 0, .x = 20, .y = 30},
681 Pointer{.id = 1, .x = 200, .y = 300}});
682 ASSERT_NO_FATAL_FAILURE(publishAndConsumeFocusEvent());
683 publishAndConsumeMotionEvent(POINTER_2_DOWN, downTime,
684 {Pointer{.id = 0, .x = 20, .y = 30},
685 Pointer{.id = 1, .x = 200, .y = 300},
686 Pointer{.id = 2, .x = 200, .y = 300}});
687 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
688 ASSERT_NO_FATAL_FAILURE(publishAndConsumeCaptureEvent());
689 ASSERT_NO_FATAL_FAILURE(publishAndConsumeDragEvent());
690 // Provide a consistent input stream - cancel the gesture that was started above
691 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_CANCEL, downTime,
692 {Pointer{.id = 0, .x = 20, .y = 30},
693 Pointer{.id = 1, .x = 200, .y = 300},
694 Pointer{.id = 2, .x = 200, .y = 300}});
695 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
696 ASSERT_NO_FATAL_FAILURE(publishAndConsumeTouchModeEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700697}
698
699} // namespace android