blob: 06b841be0d164c6a2f2914f3091895c94772eece [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
43} // namespace
Prabir Pradhan00e029d2023-03-09 20:11:09 +000044
Jeff Brown5912f952013-07-01 19:10:31 -070045class InputPublisherAndConsumerTest : public testing::Test {
46protected:
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050047 std::shared_ptr<InputChannel> mServerChannel, mClientChannel;
48 std::unique_ptr<InputPublisher> mPublisher;
49 std::unique_ptr<InputConsumer> mConsumer;
Jeff Brown5912f952013-07-01 19:10:31 -070050 PreallocatedInputEventFactory mEventFactory;
51
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050052 void SetUp() override {
53 std::unique_ptr<InputChannel> serverChannel, clientChannel;
Siarhei Vishniakouf93fcf42017-11-22 16:00:14 -080054 status_t result = InputChannel::openInputChannelPair("channel name",
Jeff Brown5912f952013-07-01 19:10:31 -070055 serverChannel, clientChannel);
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080056 ASSERT_EQ(OK, result);
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050057 mServerChannel = std::move(serverChannel);
58 mClientChannel = std::move(clientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -070059
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050060 mPublisher = std::make_unique<InputPublisher>(mServerChannel);
61 mConsumer = std::make_unique<InputConsumer>(mClientChannel);
Jeff Brown5912f952013-07-01 19:10:31 -070062 }
63
Siarhei Vishniakou6252af72023-09-20 09:00:38 -070064 void publishAndConsumeKeyEvent();
65 void publishAndConsumeMotionStream();
66 void publishAndConsumeFocusEvent();
67 void publishAndConsumeCaptureEvent();
68 void publishAndConsumeDragEvent();
69 void publishAndConsumeTouchModeEvent();
70 void publishAndConsumeMotionEvent(int32_t action, nsecs_t downTime,
71 const std::vector<Pointer>& pointers);
72
73private:
74 // The sequence number to use when publishing the next event
75 uint32_t mSeq = 1;
76
77 void publishAndConsumeMotionEvent(
78 int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac,
79 int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags,
80 int32_t metaState, int32_t buttonState, MotionClassification classification,
81 float xScale, float yScale, float xOffset, float yOffset, float xPrecision,
82 float yPrecision, float xCursorPosition, float yCursorPosition, float rawXScale,
83 float rawYScale, float rawXOffset, float rawYOffset, nsecs_t downTime,
84 nsecs_t eventTime, const std::vector<PointerProperties>& pointerProperties,
85 const std::vector<PointerCoords>& pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -070086};
87
88TEST_F(InputPublisherAndConsumerTest, GetChannel_ReturnsTheChannel) {
Siarhei Vishniakoua1188f52020-10-20 20:14:52 -050089 ASSERT_NE(nullptr, mPublisher->getChannel());
90 ASSERT_NE(nullptr, mConsumer->getChannel());
Siarhei Vishniakoud2588272020-07-10 11:15:40 -050091 EXPECT_EQ(mServerChannel.get(), mPublisher->getChannel().get());
92 EXPECT_EQ(mClientChannel.get(), mConsumer->getChannel().get());
Siarhei Vishniakoua1188f52020-10-20 20:14:52 -050093 ASSERT_EQ(mPublisher->getChannel()->getConnectionToken(),
94 mConsumer->getChannel()->getConnectionToken());
Jeff Brown5912f952013-07-01 19:10:31 -070095}
96
Siarhei Vishniakou6252af72023-09-20 09:00:38 -070097void InputPublisherAndConsumerTest::publishAndConsumeKeyEvent() {
Jeff Brown5912f952013-07-01 19:10:31 -070098 status_t status;
99
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700100 const uint32_t seq = mSeq++;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800101 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100102 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600103 constexpr uint32_t source = AINPUT_SOURCE_KEYBOARD;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100104 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600105 constexpr std::array<uint8_t, 32> hmac = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21,
106 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
107 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100108 constexpr int32_t action = AKEY_EVENT_ACTION_DOWN;
109 constexpr int32_t flags = AKEY_EVENT_FLAG_FROM_SYSTEM;
110 constexpr int32_t keyCode = AKEYCODE_ENTER;
111 constexpr int32_t scanCode = 13;
112 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
113 constexpr int32_t repeatCount = 1;
114 constexpr nsecs_t downTime = 3;
115 constexpr nsecs_t eventTime = 4;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000116 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Jeff Brown5912f952013-07-01 19:10:31 -0700117
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800118 status = mPublisher->publishKeyEvent(seq, eventId, deviceId, source, displayId, hmac, action,
119 flags, keyCode, scanCode, metaState, repeatCount, downTime,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600120 eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700121 ASSERT_EQ(OK, status)
122 << "publisher publishKeyEvent should return OK";
123
124 uint32_t consumeSeq;
125 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000126 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700127 ASSERT_EQ(OK, status)
128 << "consumer consume should return OK";
129
Yi Kong5bed83b2018-07-17 12:53:47 -0700130 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700131 << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700132 ASSERT_EQ(InputEventType::KEY, event->getType()) << "consumer should have returned a key event";
Jeff Brown5912f952013-07-01 19:10:31 -0700133
134 KeyEvent* keyEvent = static_cast<KeyEvent*>(event);
135 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800136 EXPECT_EQ(eventId, keyEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700137 EXPECT_EQ(deviceId, keyEvent->getDeviceId());
138 EXPECT_EQ(source, keyEvent->getSource());
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100139 EXPECT_EQ(displayId, keyEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600140 EXPECT_EQ(hmac, keyEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700141 EXPECT_EQ(action, keyEvent->getAction());
142 EXPECT_EQ(flags, keyEvent->getFlags());
143 EXPECT_EQ(keyCode, keyEvent->getKeyCode());
144 EXPECT_EQ(scanCode, keyEvent->getScanCode());
145 EXPECT_EQ(metaState, keyEvent->getMetaState());
146 EXPECT_EQ(repeatCount, keyEvent->getRepeatCount());
147 EXPECT_EQ(downTime, keyEvent->getDownTime());
148 EXPECT_EQ(eventTime, keyEvent->getEventTime());
149
150 status = mConsumer->sendFinishedSignal(seq, true);
151 ASSERT_EQ(OK, status)
152 << "consumer sendFinishedSignal should return OK";
153
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000154 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
155 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
156 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
157 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
158 ASSERT_EQ(seq, finish.seq)
159 << "receiveConsumerResponse should have returned the original sequence number";
160 ASSERT_TRUE(finish.handled)
161 << "receiveConsumerResponse should have set handled to consumer's reply";
162 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000163 << "finished signal's consume time should be greater than publish time";
Jeff Brown5912f952013-07-01 19:10:31 -0700164}
165
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700166void InputPublisherAndConsumerTest::publishAndConsumeMotionStream() {
167 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
Jeff Brown5912f952013-07-01 19:10:31 -0700168
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700169 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
170 {Pointer{.id = 0, .x = 20, .y = 30}});
171
172 publishAndConsumeMotionEvent(POINTER_1_DOWN, downTime,
173 {Pointer{.id = 0, .x = 20, .y = 30},
174 Pointer{.id = 1, .x = 200, .y = 300}});
175
176 publishAndConsumeMotionEvent(POINTER_2_DOWN, downTime,
177 {Pointer{.id = 0, .x = 20, .y = 30},
178 Pointer{.id = 1, .x = 200, .y = 300},
179 Pointer{.id = 2, .x = 300, .y = 400}});
180
181 // Provide a consistent input stream - cancel the gesture that was started above
182 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_CANCEL, downTime,
183 {Pointer{.id = 0, .x = 20, .y = 30},
184 Pointer{.id = 1, .x = 200, .y = 300},
185 Pointer{.id = 2, .x = 300, .y = 400}});
186}
187
188void InputPublisherAndConsumerTest::publishAndConsumeMotionEvent(
189 int32_t action, nsecs_t downTime, const std::vector<Pointer>& pointers) {
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800190 constexpr int32_t deviceId = 1;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600191 constexpr uint32_t source = AINPUT_SOURCE_TOUCHSCREEN;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100192 constexpr int32_t displayId = ADISPLAY_ID_DEFAULT;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600193 constexpr std::array<uint8_t, 32> hmac = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
194 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
195 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800196 constexpr int32_t actionButton = 0;
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700197 int32_t flags = AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED;
198
199 if (action == AMOTION_EVENT_ACTION_CANCEL) {
200 flags |= AMOTION_EVENT_FLAG_CANCELED;
201 }
202 const size_t pointerCount = pointers.size();
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800203 constexpr int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_TOP;
204 constexpr int32_t metaState = AMETA_ALT_LEFT_ON | AMETA_ALT_ON;
205 constexpr int32_t buttonState = AMOTION_EVENT_BUTTON_PRIMARY;
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800206 constexpr MotionClassification classification = MotionClassification::AMBIGUOUS_GESTURE;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600207 constexpr float xScale = 2;
208 constexpr float yScale = 3;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800209 constexpr float xOffset = -10;
210 constexpr float yOffset = -20;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700211 constexpr float rawXScale = 4;
212 constexpr float rawYScale = -5;
213 constexpr float rawXOffset = -11;
214 constexpr float rawYOffset = 42;
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800215 constexpr float xPrecision = 0.25;
216 constexpr float yPrecision = 0.5;
Garfield Tan00f511d2019-06-12 16:55:40 -0700217 constexpr float xCursorPosition = 1.3;
218 constexpr float yCursorPosition = 50.6;
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700219
220 const nsecs_t eventTime = systemTime(SYSTEM_TIME_MONOTONIC);
221 std::vector<PointerProperties> pointerProperties;
222 std::vector<PointerCoords> pointerCoords;
Jeff Brown5912f952013-07-01 19:10:31 -0700223 for (size_t i = 0; i < pointerCount; i++) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700224 pointerProperties.push_back({});
Jeff Brown5912f952013-07-01 19:10:31 -0700225 pointerProperties[i].clear();
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700226 pointerProperties[i].id = pointers[i].id;
Siarhei Vishniakou6d73f832022-07-21 17:27:03 -0700227 pointerProperties[i].toolType = ToolType::FINGER;
Jeff Brown5912f952013-07-01 19:10:31 -0700228
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700229 pointerCoords.push_back({});
Jeff Brown5912f952013-07-01 19:10:31 -0700230 pointerCoords[i].clear();
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700231 pointerCoords[i].isResampled = pointers[i].isResampled;
232 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_X, pointers[i].x);
233 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_Y, pointers[i].y);
Jeff Brown5912f952013-07-01 19:10:31 -0700234 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_PRESSURE, 0.5 * i);
235 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_SIZE, 0.7 * i);
236 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, 1.5 * i);
237 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, 1.7 * i);
238 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.5 * i);
239 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, 2.7 * i);
240 pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, 3.5 * i);
241 }
242
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700243 publishAndConsumeMotionEvent(deviceId, source, displayId, hmac, action, actionButton, flags,
244 edgeFlags, metaState, buttonState, classification, xScale, yScale,
245 xOffset, yOffset, xPrecision, yPrecision, xCursorPosition,
246 yCursorPosition, rawXScale, rawYScale, rawXOffset, rawYOffset,
247 downTime, eventTime, pointerProperties, pointerCoords);
248}
249
250void InputPublisherAndConsumerTest::publishAndConsumeMotionEvent(
251 int32_t deviceId, uint32_t source, int32_t displayId, std::array<uint8_t, 32> hmac,
252 int32_t action, int32_t actionButton, int32_t flags, int32_t edgeFlags, int32_t metaState,
253 int32_t buttonState, MotionClassification classification, float xScale, float yScale,
254 float xOffset, float yOffset, float xPrecision, float yPrecision, float xCursorPosition,
255 float yCursorPosition, float rawXScale, float rawYScale, float rawXOffset, float rawYOffset,
256 nsecs_t downTime, nsecs_t eventTime,
257 const std::vector<PointerProperties>& pointerProperties,
258 const std::vector<PointerCoords>& pointerCoords) {
259 const uint32_t seq = mSeq++;
260 const int32_t eventId = InputEvent::nextId();
chaviw9eaa22c2020-07-01 16:21:27 -0700261 ui::Transform transform;
262 transform.set({xScale, 0, xOffset, 0, yScale, yOffset, 0, 0, 1});
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700263 ui::Transform rawTransform;
264 rawTransform.set({rawXScale, 0, rawXOffset, 0, rawYScale, rawYOffset, 0, 0, 1});
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700265
266 status_t status;
267 ASSERT_EQ(pointerProperties.size(), pointerCoords.size());
268 const size_t pointerCount = pointerProperties.size();
269 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800270 status = mPublisher->publishMotionEvent(seq, eventId, deviceId, source, displayId, hmac, action,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600271 actionButton, flags, edgeFlags, metaState, buttonState,
chaviw9eaa22c2020-07-01 16:21:27 -0700272 classification, transform, xPrecision, yPrecision,
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700273 xCursorPosition, yCursorPosition, rawTransform,
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700274 downTime, eventTime, pointerCount,
275 pointerProperties.data(), pointerCoords.data());
276 ASSERT_EQ(OK, status) << "publisher publishMotionEvent should return OK";
Jeff Brown5912f952013-07-01 19:10:31 -0700277
278 uint32_t consumeSeq;
279 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000280 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Jeff Brown5912f952013-07-01 19:10:31 -0700281 ASSERT_EQ(OK, status)
282 << "consumer consume should return OK";
283
Yi Kong5bed83b2018-07-17 12:53:47 -0700284 ASSERT_TRUE(event != nullptr)
Jeff Brown5912f952013-07-01 19:10:31 -0700285 << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700286 ASSERT_EQ(InputEventType::MOTION, event->getType())
Jeff Brown5912f952013-07-01 19:10:31 -0700287 << "consumer should have returned a motion event";
288
289 MotionEvent* motionEvent = static_cast<MotionEvent*>(event);
290 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800291 EXPECT_EQ(eventId, motionEvent->getId());
Jeff Brown5912f952013-07-01 19:10:31 -0700292 EXPECT_EQ(deviceId, motionEvent->getDeviceId());
293 EXPECT_EQ(source, motionEvent->getSource());
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800294 EXPECT_EQ(displayId, motionEvent->getDisplayId());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600295 EXPECT_EQ(hmac, motionEvent->getHmac());
Jeff Brown5912f952013-07-01 19:10:31 -0700296 EXPECT_EQ(action, motionEvent->getAction());
297 EXPECT_EQ(flags, motionEvent->getFlags());
298 EXPECT_EQ(edgeFlags, motionEvent->getEdgeFlags());
299 EXPECT_EQ(metaState, motionEvent->getMetaState());
300 EXPECT_EQ(buttonState, motionEvent->getButtonState());
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800301 EXPECT_EQ(classification, motionEvent->getClassification());
chaviw9eaa22c2020-07-01 16:21:27 -0700302 EXPECT_EQ(transform, motionEvent->getTransform());
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600303 EXPECT_EQ(xOffset, motionEvent->getXOffset());
304 EXPECT_EQ(yOffset, motionEvent->getYOffset());
Jeff Brown5912f952013-07-01 19:10:31 -0700305 EXPECT_EQ(xPrecision, motionEvent->getXPrecision());
306 EXPECT_EQ(yPrecision, motionEvent->getYPrecision());
Prabir Pradhan00e029d2023-03-09 20:11:09 +0000307 EXPECT_NEAR(xCursorPosition, motionEvent->getRawXCursorPosition(), EPSILON);
308 EXPECT_NEAR(yCursorPosition, motionEvent->getRawYCursorPosition(), EPSILON);
309 EXPECT_NEAR(xCursorPosition * xScale + xOffset, motionEvent->getXCursorPosition(), EPSILON);
310 EXPECT_NEAR(yCursorPosition * yScale + yOffset, motionEvent->getYCursorPosition(), EPSILON);
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700311 EXPECT_EQ(rawTransform, motionEvent->getRawTransform());
Jeff Brown5912f952013-07-01 19:10:31 -0700312 EXPECT_EQ(downTime, motionEvent->getDownTime());
313 EXPECT_EQ(eventTime, motionEvent->getEventTime());
314 EXPECT_EQ(pointerCount, motionEvent->getPointerCount());
315 EXPECT_EQ(0U, motionEvent->getHistorySize());
316
317 for (size_t i = 0; i < pointerCount; i++) {
318 SCOPED_TRACE(i);
319 EXPECT_EQ(pointerProperties[i].id, motionEvent->getPointerId(i));
320 EXPECT_EQ(pointerProperties[i].toolType, motionEvent->getToolType(i));
321
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700322 const auto& pc = pointerCoords[i];
Prabir Pradhan00e029d2023-03-09 20:11:09 +0000323 EXPECT_EQ(pc, motionEvent->getSamplePointerCoords()[i]);
324
325 EXPECT_NEAR(pc.getX() * rawXScale + rawXOffset, motionEvent->getRawX(i), EPSILON);
326 EXPECT_NEAR(pc.getY() * rawYScale + rawYOffset, motionEvent->getRawY(i), EPSILON);
327 EXPECT_NEAR(pc.getX() * xScale + xOffset, motionEvent->getX(i), EPSILON);
328 EXPECT_NEAR(pc.getY() * yScale + yOffset, motionEvent->getY(i), EPSILON);
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700329 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_PRESSURE), motionEvent->getPressure(i));
330 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_SIZE), motionEvent->getSize(i));
331 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR), motionEvent->getTouchMajor(i));
332 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR), motionEvent->getTouchMinor(i));
333 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR), motionEvent->getToolMajor(i));
334 EXPECT_EQ(pc.getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR), motionEvent->getToolMinor(i));
Prabir Pradhan9eb02c02021-10-19 14:02:20 -0700335
336 // Calculate the orientation after scaling, keeping in mind that an orientation of 0 is
337 // "up", and the positive y direction is "down".
338 const float unscaledOrientation = pc.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION);
339 const float x = sinf(unscaledOrientation) * xScale;
340 const float y = -cosf(unscaledOrientation) * yScale;
341 EXPECT_EQ(atan2f(x, -y), motionEvent->getOrientation(i));
Jeff Brown5912f952013-07-01 19:10:31 -0700342 }
343
344 status = mConsumer->sendFinishedSignal(seq, false);
345 ASSERT_EQ(OK, status)
346 << "consumer sendFinishedSignal should return OK";
347
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000348 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
349 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
350 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
351 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
352 ASSERT_EQ(seq, finish.seq)
353 << "receiveConsumerResponse should have returned the original sequence number";
354 ASSERT_FALSE(finish.handled)
355 << "receiveConsumerResponse should have set handled to consumer's reply";
356 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000357 << "finished signal's consume time should be greater than publish time";
Jeff Brown5912f952013-07-01 19:10:31 -0700358}
359
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700360void InputPublisherAndConsumerTest::publishAndConsumeFocusEvent() {
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800361 status_t status;
362
363 constexpr uint32_t seq = 15;
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800364 int32_t eventId = InputEvent::nextId();
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800365 constexpr bool hasFocus = true;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000366 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800367
Antonio Kantek3cfec7b2021-11-05 18:26:17 -0700368 status = mPublisher->publishFocusEvent(seq, eventId, hasFocus);
arthurhung7632c332020-12-30 16:58:01 +0800369 ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK";
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800370
371 uint32_t consumeSeq;
372 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000373 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800374 ASSERT_EQ(OK, status) << "consumer consume should return OK";
375
376 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700377 ASSERT_EQ(InputEventType::FOCUS, event->getType())
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800378 << "consumer should have returned a focus event";
379
380 FocusEvent* focusEvent = static_cast<FocusEvent*>(event);
381 EXPECT_EQ(seq, consumeSeq);
Garfield Tanff1f1bb2020-01-28 13:24:04 -0800382 EXPECT_EQ(eventId, focusEvent->getId());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800383 EXPECT_EQ(hasFocus, focusEvent->getHasFocus());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800384
385 status = mConsumer->sendFinishedSignal(seq, true);
386 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
387
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000388 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
389 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
390 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
391 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000392
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000393 ASSERT_EQ(seq, finish.seq)
394 << "receiveConsumerResponse should have returned the original sequence number";
395 ASSERT_TRUE(finish.handled)
396 << "receiveConsumerResponse should have set handled to consumer's reply";
397 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000398 << "finished signal's consume time should be greater than publish time";
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800399}
400
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700401void InputPublisherAndConsumerTest::publishAndConsumeCaptureEvent() {
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800402 status_t status;
403
404 constexpr uint32_t seq = 42;
405 int32_t eventId = InputEvent::nextId();
406 constexpr bool captureEnabled = true;
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000407 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800408
409 status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled);
arthurhung7632c332020-12-30 16:58:01 +0800410 ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK";
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800411
412 uint32_t consumeSeq;
413 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000414 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800415 ASSERT_EQ(OK, status) << "consumer consume should return OK";
416
417 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700418 ASSERT_EQ(InputEventType::CAPTURE, event->getType())
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800419 << "consumer should have returned a capture event";
420
421 const CaptureEvent* captureEvent = static_cast<CaptureEvent*>(event);
422 EXPECT_EQ(seq, consumeSeq);
423 EXPECT_EQ(eventId, captureEvent->getId());
424 EXPECT_EQ(captureEnabled, captureEvent->getPointerCaptureEnabled());
425
426 status = mConsumer->sendFinishedSignal(seq, true);
427 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
428
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000429 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
430 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
431 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
432 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
433 ASSERT_EQ(seq, finish.seq)
434 << "receiveConsumerResponse should have returned the original sequence number";
435 ASSERT_TRUE(finish.handled)
436 << "receiveConsumerResponse should have set handled to consumer's reply";
437 ASSERT_GE(finish.consumeTime, publishTime)
Siarhei Vishniakou3531ae72021-02-02 12:12:27 -1000438 << "finished signal's consume time should be greater than publish time";
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800439}
440
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700441void InputPublisherAndConsumerTest::publishAndConsumeDragEvent() {
arthurhung7632c332020-12-30 16:58:01 +0800442 status_t status;
443
444 constexpr uint32_t seq = 15;
445 int32_t eventId = InputEvent::nextId();
446 constexpr bool isExiting = false;
447 constexpr float x = 10;
448 constexpr float y = 15;
449 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
450
451 status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting);
452 ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK";
453
454 uint32_t consumeSeq;
455 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000456 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
arthurhung7632c332020-12-30 16:58:01 +0800457 ASSERT_EQ(OK, status) << "consumer consume should return OK";
458
459 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700460 ASSERT_EQ(InputEventType::DRAG, event->getType())
arthurhung7632c332020-12-30 16:58:01 +0800461 << "consumer should have returned a drag event";
462
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000463 const DragEvent& dragEvent = static_cast<const DragEvent&>(*event);
arthurhung7632c332020-12-30 16:58:01 +0800464 EXPECT_EQ(seq, consumeSeq);
Siarhei Vishniakoueedd0fc2021-03-12 09:50:36 +0000465 EXPECT_EQ(eventId, dragEvent.getId());
466 EXPECT_EQ(isExiting, dragEvent.isExiting());
467 EXPECT_EQ(x, dragEvent.getX());
468 EXPECT_EQ(y, dragEvent.getY());
arthurhung7632c332020-12-30 16:58:01 +0800469
470 status = mConsumer->sendFinishedSignal(seq, true);
471 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
472
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000473 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
474 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
475 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
476 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
477 ASSERT_EQ(seq, finish.seq)
478 << "receiveConsumerResponse should have returned the original sequence number";
479 ASSERT_TRUE(finish.handled)
480 << "receiveConsumerResponse should have set handled to consumer's reply";
481 ASSERT_GE(finish.consumeTime, publishTime)
arthurhung7632c332020-12-30 16:58:01 +0800482 << "finished signal's consume time should be greater than publish time";
483}
484
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700485void InputPublisherAndConsumerTest::publishAndConsumeTouchModeEvent() {
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700486 status_t status;
487
488 constexpr uint32_t seq = 15;
489 int32_t eventId = InputEvent::nextId();
490 constexpr bool touchModeEnabled = true;
491 const nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC);
492
493 status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled);
494 ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK";
495
496 uint32_t consumeSeq;
497 InputEvent* event;
Harry Cutts82c791c2023-03-10 17:15:07 +0000498 status = mConsumer->consume(&mEventFactory, /*consumeBatches=*/true, -1, &consumeSeq, &event);
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700499 ASSERT_EQ(OK, status) << "consumer consume should return OK";
500
501 ASSERT_TRUE(event != nullptr) << "consumer should have returned non-NULL event";
Siarhei Vishniakou63b63612023-04-12 11:00:23 -0700502 ASSERT_EQ(InputEventType::TOUCH_MODE, event->getType())
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700503 << "consumer should have returned a touch mode event";
504
505 const TouchModeEvent& touchModeEvent = static_cast<const TouchModeEvent&>(*event);
506 EXPECT_EQ(seq, consumeSeq);
507 EXPECT_EQ(eventId, touchModeEvent.getId());
508 EXPECT_EQ(touchModeEnabled, touchModeEvent.isInTouchMode());
509
510 status = mConsumer->sendFinishedSignal(seq, true);
511 ASSERT_EQ(OK, status) << "consumer sendFinishedSignal should return OK";
512
513 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
514 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
515 ASSERT_TRUE(std::holds_alternative<InputPublisher::Finished>(*result));
516 const InputPublisher::Finished& finish = std::get<InputPublisher::Finished>(*result);
517 ASSERT_EQ(seq, finish.seq)
518 << "receiveConsumerResponse should have returned the original sequence number";
519 ASSERT_TRUE(finish.handled)
520 << "receiveConsumerResponse should have set handled to consumer's reply";
521 ASSERT_GE(finish.consumeTime, publishTime)
522 << "finished signal's consume time should be greater than publish time";
523}
524
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000525TEST_F(InputPublisherAndConsumerTest, SendTimeline) {
526 const int32_t inputEventId = 20;
527 std::array<nsecs_t, GraphicsTimeline::SIZE> graphicsTimeline;
528 graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME] = 30;
529 graphicsTimeline[GraphicsTimeline::PRESENT_TIME] = 40;
530 status_t status = mConsumer->sendTimeline(inputEventId, graphicsTimeline);
531 ASSERT_EQ(OK, status);
532
533 Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse();
534 ASSERT_TRUE(result.ok()) << "receiveConsumerResponse should return OK";
535 ASSERT_TRUE(std::holds_alternative<InputPublisher::Timeline>(*result));
536 const InputPublisher::Timeline& timeline = std::get<InputPublisher::Timeline>(*result);
537 ASSERT_EQ(inputEventId, timeline.inputEventId);
538 ASSERT_EQ(graphicsTimeline, timeline.graphicsTimeline);
539}
540
Jeff Brown5912f952013-07-01 19:10:31 -0700541TEST_F(InputPublisherAndConsumerTest, PublishKeyEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700542 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700543}
544
545TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700546 ASSERT_NO_FATAL_FAILURE(publishAndConsumeMotionStream());
Jeff Brown5912f952013-07-01 19:10:31 -0700547}
548
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800549TEST_F(InputPublisherAndConsumerTest, PublishFocusEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700550 ASSERT_NO_FATAL_FAILURE(publishAndConsumeFocusEvent());
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800551}
552
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800553TEST_F(InputPublisherAndConsumerTest, PublishCaptureEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700554 ASSERT_NO_FATAL_FAILURE(publishAndConsumeCaptureEvent());
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800555}
556
arthurhung7632c332020-12-30 16:58:01 +0800557TEST_F(InputPublisherAndConsumerTest, PublishDragEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700558 ASSERT_NO_FATAL_FAILURE(publishAndConsumeDragEvent());
arthurhung7632c332020-12-30 16:58:01 +0800559}
560
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700561TEST_F(InputPublisherAndConsumerTest, PublishTouchModeEvent_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700562 ASSERT_NO_FATAL_FAILURE(publishAndConsumeTouchModeEvent());
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700563}
564
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800565TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenSequenceNumberIsZero_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700566 status_t status;
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800567 const size_t pointerCount = 1;
Jeff Brown5912f952013-07-01 19:10:31 -0700568 PointerProperties pointerProperties[pointerCount];
569 PointerCoords pointerCoords[pointerCount];
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800570 for (size_t i = 0; i < pointerCount; i++) {
571 pointerProperties[i].clear();
572 pointerCoords[i].clear();
573 }
Jeff Brown5912f952013-07-01 19:10:31 -0700574
chaviw9eaa22c2020-07-01 16:21:27 -0700575 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700576 status =
577 mPublisher->publishMotionEvent(0, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
578 0, 0, 0, MotionClassification::NONE, identityTransform,
579 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
580 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
581 0, 0, pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700582 ASSERT_EQ(BAD_VALUE, status)
583 << "publisher publishMotionEvent should return BAD_VALUE";
584}
585
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800586TEST_F(InputPublisherAndConsumerTest, PublishMotionEvent_WhenPointerCountLessThan1_ReturnsError) {
587 status_t status;
588 const size_t pointerCount = 0;
589 PointerProperties pointerProperties[pointerCount];
590 PointerCoords pointerCoords[pointerCount];
591
chaviw9eaa22c2020-07-01 16:21:27 -0700592 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700593 status =
594 mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
595 0, 0, 0, MotionClassification::NONE, identityTransform,
596 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
597 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
598 0, 0, pointerCount, pointerProperties, pointerCoords);
Siarhei Vishniakoub0fffdd2017-11-10 20:16:56 -0800599 ASSERT_EQ(BAD_VALUE, status)
600 << "publisher publishMotionEvent should return BAD_VALUE";
601}
602
603TEST_F(InputPublisherAndConsumerTest,
604 PublishMotionEvent_WhenPointerCountGreaterThanMax_ReturnsError) {
Jeff Brown5912f952013-07-01 19:10:31 -0700605 status_t status;
606 const size_t pointerCount = MAX_POINTERS + 1;
607 PointerProperties pointerProperties[pointerCount];
608 PointerCoords pointerCoords[pointerCount];
609 for (size_t i = 0; i < pointerCount; i++) {
610 pointerProperties[i].clear();
611 pointerCoords[i].clear();
612 }
613
chaviw9eaa22c2020-07-01 16:21:27 -0700614 ui::Transform identityTransform;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700615 status =
616 mPublisher->publishMotionEvent(1, InputEvent::nextId(), 0, 0, 0, INVALID_HMAC, 0, 0, 0,
617 0, 0, 0, MotionClassification::NONE, identityTransform,
618 0, 0, AMOTION_EVENT_INVALID_CURSOR_POSITION,
619 AMOTION_EVENT_INVALID_CURSOR_POSITION, identityTransform,
620 0, 0, pointerCount, pointerProperties, pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700621 ASSERT_EQ(BAD_VALUE, status)
622 << "publisher publishMotionEvent should return BAD_VALUE";
623}
624
625TEST_F(InputPublisherAndConsumerTest, PublishMultipleEvents_EndToEnd) {
Siarhei Vishniakou6252af72023-09-20 09:00:38 -0700626 const nsecs_t downTime = systemTime(SYSTEM_TIME_MONOTONIC);
627
628 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_DOWN, downTime,
629 {Pointer{.id = 0, .x = 20, .y = 30}});
630 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
631 publishAndConsumeMotionEvent(POINTER_1_DOWN, downTime,
632 {Pointer{.id = 0, .x = 20, .y = 30},
633 Pointer{.id = 1, .x = 200, .y = 300}});
634 ASSERT_NO_FATAL_FAILURE(publishAndConsumeFocusEvent());
635 publishAndConsumeMotionEvent(POINTER_2_DOWN, downTime,
636 {Pointer{.id = 0, .x = 20, .y = 30},
637 Pointer{.id = 1, .x = 200, .y = 300},
638 Pointer{.id = 2, .x = 200, .y = 300}});
639 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
640 ASSERT_NO_FATAL_FAILURE(publishAndConsumeCaptureEvent());
641 ASSERT_NO_FATAL_FAILURE(publishAndConsumeDragEvent());
642 // Provide a consistent input stream - cancel the gesture that was started above
643 publishAndConsumeMotionEvent(AMOTION_EVENT_ACTION_CANCEL, downTime,
644 {Pointer{.id = 0, .x = 20, .y = 30},
645 Pointer{.id = 1, .x = 200, .y = 300},
646 Pointer{.id = 2, .x = 200, .y = 300}});
647 ASSERT_NO_FATAL_FAILURE(publishAndConsumeKeyEvent());
648 ASSERT_NO_FATAL_FAILURE(publishAndConsumeTouchModeEvent());
Jeff Brown5912f952013-07-01 19:10:31 -0700649}
650
651} // namespace android