Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Garfield Tan | 0fc2fa7 | 2019-08-29 17:22:15 -0700 | [diff] [blame] | 17 | #include "../dispatcher/InputDispatcher.h" |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 18 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 19 | #include <InputDispatcherThread.h> |
| 20 | |
Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 21 | #include <binder/Binder.h> |
| 22 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 23 | #include <gtest/gtest.h> |
| 24 | #include <linux/input.h> |
| 25 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 26 | namespace android::inputdispatcher { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 27 | |
| 28 | // An arbitrary time value. |
| 29 | static const nsecs_t ARBITRARY_TIME = 1234; |
| 30 | |
| 31 | // An arbitrary device id. |
| 32 | static const int32_t DEVICE_ID = 1; |
| 33 | |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 34 | // An arbitrary display id. |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 35 | static const int32_t DISPLAY_ID = ADISPLAY_ID_DEFAULT; |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 36 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 37 | // An arbitrary injector pid / uid pair that has permission to inject events. |
| 38 | static const int32_t INJECTOR_PID = 999; |
| 39 | static const int32_t INJECTOR_UID = 1001; |
| 40 | |
| 41 | |
| 42 | // --- FakeInputDispatcherPolicy --- |
| 43 | |
| 44 | class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface { |
| 45 | InputDispatcherConfiguration mConfig; |
| 46 | |
| 47 | protected: |
| 48 | virtual ~FakeInputDispatcherPolicy() { |
| 49 | } |
| 50 | |
| 51 | public: |
| 52 | FakeInputDispatcherPolicy() { |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 53 | mOnPointerDownToken.clear(); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 54 | } |
| 55 | |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 56 | void assertFilterInputEventWasCalled(const NotifyKeyArgs& args) { |
Siarhei Vishniakou | d99e1b6 | 2019-11-26 11:01:06 -0800 | [diff] [blame] | 57 | assertFilterInputEventWasCalled(AINPUT_EVENT_TYPE_KEY, args.eventTime, args.action, |
| 58 | args.displayId); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 59 | } |
| 60 | |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 61 | void assertFilterInputEventWasCalled(const NotifyMotionArgs& args) { |
Siarhei Vishniakou | d99e1b6 | 2019-11-26 11:01:06 -0800 | [diff] [blame] | 62 | assertFilterInputEventWasCalled(AINPUT_EVENT_TYPE_MOTION, args.eventTime, args.action, |
| 63 | args.displayId); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 64 | } |
| 65 | |
Siarhei Vishniakou | d99e1b6 | 2019-11-26 11:01:06 -0800 | [diff] [blame] | 66 | void assertFilterInputEventWasNotCalled() { ASSERT_EQ(nullptr, mFilteredEvent); } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 67 | |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 68 | void assertOnPointerDownEquals(const sp<IBinder>& touchedToken) { |
| 69 | ASSERT_EQ(mOnPointerDownToken, touchedToken) |
| 70 | << "Expected token from onPointerDownOutsideFocus was not matched"; |
| 71 | reset(); |
| 72 | } |
| 73 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 74 | private: |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 75 | std::unique_ptr<InputEvent> mFilteredEvent; |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 76 | sp<IBinder> mOnPointerDownToken; |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 77 | |
Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 78 | virtual void notifyConfigurationChanged(nsecs_t) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 79 | } |
| 80 | |
Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 81 | virtual nsecs_t notifyANR(const sp<InputApplicationHandle>&, |
Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 82 | const sp<IBinder>&, |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 83 | const std::string&) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 87 | virtual void notifyInputChannelBroken(const sp<IBinder>&) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 88 | } |
| 89 | |
chaviw | 0c06c6e | 2019-01-09 13:27:07 -0800 | [diff] [blame] | 90 | virtual void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) { |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 93 | virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) { |
| 94 | *outConfig = mConfig; |
| 95 | } |
| 96 | |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 97 | virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 98 | switch (inputEvent->getType()) { |
| 99 | case AINPUT_EVENT_TYPE_KEY: { |
| 100 | const KeyEvent* keyEvent = static_cast<const KeyEvent*>(inputEvent); |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 101 | mFilteredEvent = std::make_unique<KeyEvent>(*keyEvent); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 102 | break; |
| 103 | } |
| 104 | |
| 105 | case AINPUT_EVENT_TYPE_MOTION: { |
| 106 | const MotionEvent* motionEvent = static_cast<const MotionEvent*>(inputEvent); |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 107 | mFilteredEvent = std::make_unique<MotionEvent>(*motionEvent); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 111 | return true; |
| 112 | } |
| 113 | |
Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 114 | virtual void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Charles Chen | 3611f1f | 2019-01-29 17:26:18 +0800 | [diff] [blame] | 117 | virtual void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 118 | } |
| 119 | |
Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 120 | virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, |
Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 121 | const KeyEvent*, uint32_t) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
Robert Carr | 803535b | 2018-08-02 16:38:15 -0700 | [diff] [blame] | 125 | virtual bool dispatchUnhandledKey(const sp<IBinder>&, |
Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 126 | const KeyEvent*, uint32_t, KeyEvent*) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 127 | return false; |
| 128 | } |
| 129 | |
Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 130 | virtual void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 131 | } |
| 132 | |
Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 133 | virtual void pokeUserActivity(nsecs_t, int32_t) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 134 | } |
| 135 | |
Narayan Kamath | 39efe3e | 2014-10-17 10:37:08 +0100 | [diff] [blame] | 136 | virtual bool checkInjectEventsPermissionNonReentrant(int32_t, int32_t) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 137 | return false; |
| 138 | } |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 139 | |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 140 | virtual void onPointerDownOutsideFocus(const sp<IBinder>& newToken) { |
| 141 | mOnPointerDownToken = newToken; |
| 142 | } |
| 143 | |
Siarhei Vishniakou | d99e1b6 | 2019-11-26 11:01:06 -0800 | [diff] [blame] | 144 | void assertFilterInputEventWasCalled(int type, nsecs_t eventTime, int32_t action, |
| 145 | int32_t displayId) { |
| 146 | ASSERT_NE(nullptr, mFilteredEvent) << "Expected filterInputEvent() to have been called."; |
| 147 | ASSERT_EQ(mFilteredEvent->getType(), type); |
| 148 | |
| 149 | if (type == AINPUT_EVENT_TYPE_KEY) { |
| 150 | const KeyEvent& keyEvent = static_cast<const KeyEvent&>(*mFilteredEvent); |
| 151 | EXPECT_EQ(keyEvent.getEventTime(), eventTime); |
| 152 | EXPECT_EQ(keyEvent.getAction(), action); |
| 153 | EXPECT_EQ(keyEvent.getDisplayId(), displayId); |
| 154 | } else if (type == AINPUT_EVENT_TYPE_MOTION) { |
| 155 | const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*mFilteredEvent); |
| 156 | EXPECT_EQ(motionEvent.getEventTime(), eventTime); |
| 157 | EXPECT_EQ(motionEvent.getAction(), action); |
| 158 | EXPECT_EQ(motionEvent.getDisplayId(), displayId); |
| 159 | } else { |
| 160 | FAIL() << "Unknown type: " << type; |
| 161 | } |
| 162 | |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 163 | mFilteredEvent = nullptr; |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 164 | } |
Siarhei Vishniakou | d99e1b6 | 2019-11-26 11:01:06 -0800 | [diff] [blame] | 165 | |
| 166 | void reset() { mOnPointerDownToken.clear(); } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | |
| 170 | // --- InputDispatcherTest --- |
| 171 | |
| 172 | class InputDispatcherTest : public testing::Test { |
| 173 | protected: |
| 174 | sp<FakeInputDispatcherPolicy> mFakePolicy; |
| 175 | sp<InputDispatcher> mDispatcher; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 176 | sp<InputDispatcherThread> mDispatcherThread; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 177 | |
| 178 | virtual void SetUp() { |
| 179 | mFakePolicy = new FakeInputDispatcherPolicy(); |
| 180 | mDispatcher = new InputDispatcher(mFakePolicy); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 181 | mDispatcher->setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); |
| 182 | //Start InputDispatcher thread |
| 183 | mDispatcherThread = new InputDispatcherThread(mDispatcher); |
| 184 | mDispatcherThread->run("InputDispatcherTest", PRIORITY_URGENT_DISPLAY); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | virtual void TearDown() { |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 188 | mDispatcherThread->requestExit(); |
| 189 | mDispatcherThread.clear(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 190 | mFakePolicy.clear(); |
| 191 | mDispatcher.clear(); |
| 192 | } |
| 193 | }; |
| 194 | |
| 195 | |
| 196 | TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesKeyEvents) { |
| 197 | KeyEvent event; |
| 198 | |
| 199 | // Rejects undefined key actions. |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 200 | event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 201 | /*action*/ -1, 0, |
| 202 | AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 203 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 204 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 205 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 206 | << "Should reject key events with undefined action."; |
| 207 | |
| 208 | // Rejects ACTION_MULTIPLE since it is not supported despite being defined in the API. |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 209 | event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD, ADISPLAY_ID_NONE, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 210 | AKEY_EVENT_ACTION_MULTIPLE, 0, |
| 211 | AKEYCODE_A, KEY_A, AMETA_NONE, 0, ARBITRARY_TIME, ARBITRARY_TIME); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 212 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 213 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 214 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 215 | << "Should reject key events with ACTION_MULTIPLE."; |
| 216 | } |
| 217 | |
| 218 | TEST_F(InputDispatcherTest, InjectInputEvent_ValidatesMotionEvents) { |
| 219 | MotionEvent event; |
| 220 | PointerProperties pointerProperties[MAX_POINTERS + 1]; |
| 221 | PointerCoords pointerCoords[MAX_POINTERS + 1]; |
| 222 | for (int i = 0; i <= MAX_POINTERS; i++) { |
| 223 | pointerProperties[i].clear(); |
| 224 | pointerProperties[i].id = i; |
| 225 | pointerCoords[i].clear(); |
| 226 | } |
| 227 | |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 228 | // Some constants commonly used below |
| 229 | constexpr int32_t source = AINPUT_SOURCE_TOUCHSCREEN; |
| 230 | constexpr int32_t edgeFlags = AMOTION_EVENT_EDGE_FLAG_NONE; |
| 231 | constexpr int32_t metaState = AMETA_NONE; |
| 232 | constexpr MotionClassification classification = MotionClassification::NONE; |
| 233 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 234 | // Rejects undefined motion actions. |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 235 | event.initialize(DEVICE_ID, source, DISPLAY_ID, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 236 | /*action*/ -1, 0, 0, edgeFlags, metaState, 0, classification, 0, 0, 0, 0, |
| 237 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 238 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 239 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 240 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 241 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 242 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 243 | << "Should reject motion events with undefined action."; |
| 244 | |
| 245 | // Rejects pointer down with invalid index. |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 246 | event.initialize(DEVICE_ID, source, DISPLAY_ID, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 247 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 248 | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 249 | 0, 0, edgeFlags, metaState, 0, classification, 0, 0, 0, 0, |
| 250 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 251 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 252 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 253 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 254 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 255 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 256 | << "Should reject motion events with pointer down index too large."; |
| 257 | |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 258 | event.initialize(DEVICE_ID, source, DISPLAY_ID, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 259 | AMOTION_EVENT_ACTION_POINTER_DOWN | |
| 260 | (~0U << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 261 | 0, 0, edgeFlags, metaState, 0, classification, 0, 0, 0, 0, |
| 262 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 263 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 264 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 265 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 266 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 267 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 268 | << "Should reject motion events with pointer down index too small."; |
| 269 | |
| 270 | // Rejects pointer up with invalid index. |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 271 | event.initialize(DEVICE_ID, source, DISPLAY_ID, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 272 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 273 | (1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 274 | 0, 0, edgeFlags, metaState, 0, classification, 0, 0, 0, 0, |
| 275 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 276 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 277 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 278 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 279 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 280 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 281 | << "Should reject motion events with pointer up index too large."; |
| 282 | |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 283 | event.initialize(DEVICE_ID, source, DISPLAY_ID, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 284 | AMOTION_EVENT_ACTION_POINTER_UP | |
| 285 | (~0U << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), |
| 286 | 0, 0, edgeFlags, metaState, 0, classification, 0, 0, 0, 0, |
| 287 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 288 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 289 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 290 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 291 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 292 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 293 | << "Should reject motion events with pointer up index too small."; |
| 294 | |
| 295 | // Rejects motion events with invalid number of pointers. |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 296 | event.initialize(DEVICE_ID, source, DISPLAY_ID, AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, |
| 297 | metaState, 0, classification, 0, 0, 0, 0, |
| 298 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 299 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 300 | /*pointerCount*/ 0, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 301 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 302 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 303 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 304 | << "Should reject motion events with 0 pointers."; |
| 305 | |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 306 | event.initialize(DEVICE_ID, source, DISPLAY_ID, AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, |
| 307 | metaState, 0, classification, 0, 0, 0, 0, |
| 308 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 309 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 310 | /*pointerCount*/ MAX_POINTERS + 1, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 311 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 312 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 313 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 314 | << "Should reject motion events with more than MAX_POINTERS pointers."; |
| 315 | |
| 316 | // Rejects motion events with invalid pointer ids. |
| 317 | pointerProperties[0].id = -1; |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 318 | event.initialize(DEVICE_ID, source, DISPLAY_ID, AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, |
| 319 | metaState, 0, classification, 0, 0, 0, 0, |
| 320 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 321 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 322 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 323 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 324 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 325 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 326 | << "Should reject motion events with pointer ids less than 0."; |
| 327 | |
| 328 | pointerProperties[0].id = MAX_POINTER_ID + 1; |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 329 | event.initialize(DEVICE_ID, source, DISPLAY_ID, AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, |
| 330 | metaState, 0, classification, 0, 0, 0, 0, |
| 331 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 332 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 333 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 334 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 335 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 336 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 337 | << "Should reject motion events with pointer ids greater than MAX_POINTER_ID."; |
| 338 | |
| 339 | // Rejects motion events with duplicate pointer ids. |
| 340 | pointerProperties[0].id = 1; |
| 341 | pointerProperties[1].id = 1; |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 342 | event.initialize(DEVICE_ID, source, DISPLAY_ID, AMOTION_EVENT_ACTION_DOWN, 0, 0, edgeFlags, |
| 343 | metaState, 0, classification, 0, 0, 0, 0, |
| 344 | AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 345 | ARBITRARY_TIME, ARBITRARY_TIME, |
| 346 | /*pointerCount*/ 2, pointerProperties, pointerCoords); |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 347 | ASSERT_EQ(INPUT_EVENT_INJECTION_FAILED, mDispatcher->injectInputEvent( |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 348 | &event, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 349 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_NONE, 0, 0)) |
| 350 | << "Should reject motion events with duplicate pointer ids."; |
| 351 | } |
| 352 | |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 353 | // --- InputDispatcherTest SetInputWindowTest --- |
| 354 | static const int32_t INJECT_EVENT_TIMEOUT = 500; |
| 355 | static const int32_t DISPATCHING_TIMEOUT = 100; |
| 356 | |
| 357 | class FakeApplicationHandle : public InputApplicationHandle { |
| 358 | public: |
| 359 | FakeApplicationHandle() {} |
| 360 | virtual ~FakeApplicationHandle() {} |
| 361 | |
| 362 | virtual bool updateInfo() { |
Arthur Hung | 7a0c39a | 2019-03-20 16:52:24 +0800 | [diff] [blame] | 363 | mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 364 | return true; |
| 365 | } |
| 366 | }; |
| 367 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 368 | class FakeInputReceiver { |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 369 | public: |
Siarhei Vishniakou | 08b574f | 2019-11-15 18:05:52 -0800 | [diff] [blame] | 370 | InputEvent* consume() { |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 371 | uint32_t consumeSeq; |
| 372 | InputEvent* event; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 373 | |
Siarhei Vishniakou | 08b574f | 2019-11-15 18:05:52 -0800 | [diff] [blame] | 374 | std::chrono::time_point start = std::chrono::steady_clock::now(); |
| 375 | status_t status = WOULD_BLOCK; |
| 376 | while (status == WOULD_BLOCK) { |
| 377 | status = mConsumer->consume(&mEventFactory, false /*consumeBatches*/, -1, &consumeSeq, |
| 378 | &event); |
| 379 | std::chrono::duration elapsed = std::chrono::steady_clock::now() - start; |
| 380 | if (elapsed > 100ms) { |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | if (status == WOULD_BLOCK) { |
| 386 | // Just means there's no event available. |
| 387 | return nullptr; |
| 388 | } |
| 389 | |
| 390 | if (status != OK) { |
| 391 | ADD_FAILURE() << mName.c_str() << ": consumer consume should return OK."; |
| 392 | return nullptr; |
| 393 | } |
| 394 | if (event == nullptr) { |
| 395 | ADD_FAILURE() << "Consumed correctly, but received NULL event from consumer"; |
| 396 | return nullptr; |
| 397 | } |
| 398 | |
| 399 | status = mConsumer->sendFinishedSignal(consumeSeq, handled()); |
| 400 | if (status != OK) { |
| 401 | ADD_FAILURE() << mName.c_str() << ": consumer sendFinishedSignal should return OK."; |
| 402 | } |
| 403 | return event; |
| 404 | } |
| 405 | |
| 406 | void consumeEvent(int32_t expectedEventType, int32_t expectedAction, int32_t expectedDisplayId, |
| 407 | int32_t expectedFlags) { |
| 408 | InputEvent* event = consume(); |
| 409 | |
| 410 | ASSERT_NE(nullptr, event) << mName.c_str() |
| 411 | << ": consumer should have returned non-NULL event."; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 412 | ASSERT_EQ(expectedEventType, event->getType()) |
Tiger Huang | 8664f8c | 2018-10-11 19:14:35 +0800 | [diff] [blame] | 413 | << mName.c_str() << ": event type should match."; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 414 | |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 415 | EXPECT_EQ(expectedDisplayId, event->getDisplayId()); |
Tiger Huang | 8664f8c | 2018-10-11 19:14:35 +0800 | [diff] [blame] | 416 | |
Tiger Huang | 8664f8c | 2018-10-11 19:14:35 +0800 | [diff] [blame] | 417 | switch (expectedEventType) { |
| 418 | case AINPUT_EVENT_TYPE_KEY: { |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 419 | const KeyEvent& keyEvent = static_cast<const KeyEvent&>(*event); |
| 420 | EXPECT_EQ(expectedAction, keyEvent.getAction()); |
| 421 | EXPECT_EQ(expectedFlags, keyEvent.getFlags()); |
Tiger Huang | 8664f8c | 2018-10-11 19:14:35 +0800 | [diff] [blame] | 422 | break; |
| 423 | } |
| 424 | case AINPUT_EVENT_TYPE_MOTION: { |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 425 | const MotionEvent& motionEvent = static_cast<const MotionEvent&>(*event); |
| 426 | EXPECT_EQ(expectedAction, motionEvent.getAction()); |
| 427 | EXPECT_EQ(expectedFlags, motionEvent.getFlags()); |
Tiger Huang | 8664f8c | 2018-10-11 19:14:35 +0800 | [diff] [blame] | 428 | break; |
| 429 | } |
| 430 | default: { |
| 431 | FAIL() << mName.c_str() << ": invalid event type: " << expectedEventType; |
| 432 | } |
| 433 | } |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 434 | } |
| 435 | |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 436 | void consumeKeyDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) { |
| 437 | consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_DOWN, expectedDisplayId, |
| 438 | expectedFlags); |
| 439 | } |
| 440 | |
| 441 | void consumeMotionDown(int32_t expectedDisplayId, int32_t expectedFlags = 0) { |
| 442 | consumeEvent(AINPUT_EVENT_TYPE_MOTION, AMOTION_EVENT_ACTION_DOWN, expectedDisplayId, |
| 443 | expectedFlags); |
| 444 | } |
| 445 | |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 446 | void assertNoEvents() { |
Siarhei Vishniakou | 08b574f | 2019-11-15 18:05:52 -0800 | [diff] [blame] | 447 | InputEvent* event = consume(); |
| 448 | ASSERT_EQ(nullptr, event) |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 449 | << mName.c_str() |
Siarhei Vishniakou | 08b574f | 2019-11-15 18:05:52 -0800 | [diff] [blame] | 450 | << ": should not have received any events, so consume() should return NULL"; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 451 | } |
| 452 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 453 | protected: |
| 454 | explicit FakeInputReceiver(const sp<InputDispatcher>& dispatcher, |
| 455 | const std::string name, int32_t displayId) : |
| 456 | mDispatcher(dispatcher), mName(name), mDisplayId(displayId) { |
| 457 | InputChannel::openInputChannelPair(name, mServerChannel, mClientChannel); |
| 458 | mConsumer = new InputConsumer(mClientChannel); |
| 459 | } |
| 460 | |
| 461 | virtual ~FakeInputReceiver() { |
| 462 | } |
| 463 | |
| 464 | // return true if the event has been handled. |
| 465 | virtual bool handled() { |
| 466 | return false; |
| 467 | } |
| 468 | |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 469 | sp<InputDispatcher> mDispatcher; |
| 470 | sp<InputChannel> mServerChannel, mClientChannel; |
| 471 | InputConsumer *mConsumer; |
| 472 | PreallocatedInputEventFactory mEventFactory; |
| 473 | |
| 474 | std::string mName; |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 475 | int32_t mDisplayId; |
| 476 | }; |
| 477 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 478 | class FakeWindowHandle : public InputWindowHandle, public FakeInputReceiver { |
| 479 | public: |
| 480 | static const int32_t WIDTH = 600; |
| 481 | static const int32_t HEIGHT = 800; |
| 482 | |
| 483 | FakeWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle, |
| 484 | const sp<InputDispatcher>& dispatcher, const std::string name, int32_t displayId) : |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 485 | FakeInputReceiver(dispatcher, name, displayId), |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 486 | mFocused(false), mFrame(Rect(0, 0, WIDTH, HEIGHT)), mLayoutParamFlags(0) { |
Siarhei Vishniakou | 7c34b23 | 2019-10-11 19:08:48 -0700 | [diff] [blame] | 487 | mDispatcher->registerInputChannel(mServerChannel); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 488 | |
Robert Carr | 740167f | 2018-10-11 19:03:41 -0700 | [diff] [blame] | 489 | inputApplicationHandle->updateInfo(); |
| 490 | mInfo.applicationInfo = *inputApplicationHandle->getInfo(); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | virtual bool updateInfo() { |
Siarhei Vishniakou | 26d3cfb | 2019-10-15 17:02:32 -0700 | [diff] [blame] | 494 | mInfo.token = mServerChannel ? mServerChannel->getConnectionToken() : nullptr; |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 495 | mInfo.name = mName; |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 496 | mInfo.layoutParamsFlags = mLayoutParamFlags; |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 497 | mInfo.layoutParamsType = InputWindowInfo::TYPE_APPLICATION; |
| 498 | mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 499 | mInfo.frameLeft = mFrame.left; |
| 500 | mInfo.frameTop = mFrame.top; |
| 501 | mInfo.frameRight = mFrame.right; |
| 502 | mInfo.frameBottom = mFrame.bottom; |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 503 | mInfo.globalScaleFactor = 1.0; |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 504 | mInfo.touchableRegion.clear(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 505 | mInfo.addTouchableRegion(mFrame); |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 506 | mInfo.visible = true; |
| 507 | mInfo.canReceiveKeys = true; |
| 508 | mInfo.hasFocus = mFocused; |
| 509 | mInfo.hasWallpaper = false; |
| 510 | mInfo.paused = false; |
| 511 | mInfo.layer = 0; |
| 512 | mInfo.ownerPid = INJECTOR_PID; |
| 513 | mInfo.ownerUid = INJECTOR_UID; |
| 514 | mInfo.inputFeatures = 0; |
| 515 | mInfo.displayId = mDisplayId; |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 516 | |
| 517 | return true; |
| 518 | } |
| 519 | |
| 520 | void setFocus() { |
| 521 | mFocused = true; |
| 522 | } |
Arthur Hung | 832bc4a | 2019-01-28 11:43:17 +0800 | [diff] [blame] | 523 | |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 524 | void setFrame(const Rect& frame) { |
| 525 | mFrame.set(frame); |
| 526 | } |
| 527 | |
| 528 | void setLayoutParamFlags(int32_t flags) { |
| 529 | mLayoutParamFlags = flags; |
| 530 | } |
| 531 | |
Arthur Hung | 832bc4a | 2019-01-28 11:43:17 +0800 | [diff] [blame] | 532 | void releaseChannel() { |
Arthur Hung | 6b5a2b9 | 2019-01-31 16:39:28 +0800 | [diff] [blame] | 533 | mServerChannel.clear(); |
Arthur Hung | 832bc4a | 2019-01-28 11:43:17 +0800 | [diff] [blame] | 534 | InputWindowHandle::releaseChannel(); |
Arthur Hung | 832bc4a | 2019-01-28 11:43:17 +0800 | [diff] [blame] | 535 | } |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 536 | protected: |
| 537 | virtual bool handled() { |
| 538 | return true; |
| 539 | } |
| 540 | |
| 541 | bool mFocused; |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 542 | Rect mFrame; |
| 543 | int32_t mLayoutParamFlags; |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 544 | }; |
| 545 | |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 546 | static int32_t injectKeyDown(const sp<InputDispatcher>& dispatcher, |
| 547 | int32_t displayId = ADISPLAY_ID_NONE) { |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 548 | KeyEvent event; |
| 549 | nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 550 | |
| 551 | // Define a valid key down event. |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 552 | event.initialize(DEVICE_ID, AINPUT_SOURCE_KEYBOARD, displayId, |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 553 | AKEY_EVENT_ACTION_DOWN, /* flags */ 0, |
| 554 | AKEYCODE_A, KEY_A, AMETA_NONE, /* repeatCount */ 0, currentTime, currentTime); |
| 555 | |
| 556 | // Inject event until dispatch out. |
| 557 | return dispatcher->injectInputEvent( |
| 558 | &event, |
| 559 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 560 | INJECT_EVENT_TIMEOUT, POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER); |
| 561 | } |
| 562 | |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 563 | static int32_t injectMotionEvent(const sp<InputDispatcher>& dispatcher, int32_t action, |
| 564 | int32_t source, int32_t displayId, int32_t x, int32_t y, |
| 565 | int32_t xCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 566 | int32_t yCursorPosition = AMOTION_EVENT_INVALID_CURSOR_POSITION) { |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 567 | MotionEvent event; |
| 568 | PointerProperties pointerProperties[1]; |
| 569 | PointerCoords pointerCoords[1]; |
| 570 | |
| 571 | pointerProperties[0].clear(); |
| 572 | pointerProperties[0].id = 0; |
| 573 | pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 574 | |
| 575 | pointerCoords[0].clear(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 576 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, x); |
| 577 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, y); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 578 | |
| 579 | nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 580 | // Define a valid motion down event. |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 581 | event.initialize(DEVICE_ID, source, displayId, action, /* actionButton */ 0, /* flags */ 0, |
| 582 | /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, |
| 583 | /* xOffset */ 0, /* yOffset */ 0, /* xPrecision */ 0, |
| 584 | /* yPrecision */ 0, xCursorPosition, yCursorPosition, currentTime, currentTime, |
| 585 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 586 | |
| 587 | // Inject event until dispatch out. |
| 588 | return dispatcher->injectInputEvent( |
| 589 | &event, |
| 590 | INJECTOR_PID, INJECTOR_UID, INPUT_EVENT_INJECTION_SYNC_WAIT_FOR_RESULT, |
| 591 | INJECT_EVENT_TIMEOUT, POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER); |
| 592 | } |
| 593 | |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 594 | static int32_t injectMotionDown(const sp<InputDispatcher>& dispatcher, int32_t source, |
| 595 | int32_t displayId, int32_t x = 100, int32_t y = 200) { |
| 596 | return injectMotionEvent(dispatcher, AMOTION_EVENT_ACTION_DOWN, source, displayId, x, y); |
| 597 | } |
| 598 | |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 599 | static NotifyKeyArgs generateKeyArgs(int32_t action, int32_t displayId = ADISPLAY_ID_NONE) { |
| 600 | nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 601 | // Define a valid key event. |
| 602 | NotifyKeyArgs args(/* sequenceNum */ 0, currentTime, DEVICE_ID, AINPUT_SOURCE_KEYBOARD, |
| 603 | displayId, POLICY_FLAG_PASS_TO_USER, action, /* flags */ 0, |
| 604 | AKEYCODE_A, KEY_A, AMETA_NONE, currentTime); |
| 605 | |
| 606 | return args; |
| 607 | } |
| 608 | |
| 609 | static NotifyMotionArgs generateMotionArgs(int32_t action, int32_t source, int32_t displayId) { |
| 610 | PointerProperties pointerProperties[1]; |
| 611 | PointerCoords pointerCoords[1]; |
| 612 | |
| 613 | pointerProperties[0].clear(); |
| 614 | pointerProperties[0].id = 0; |
| 615 | pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 616 | |
| 617 | pointerCoords[0].clear(); |
| 618 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100); |
| 619 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 200); |
| 620 | |
| 621 | nsecs_t currentTime = systemTime(SYSTEM_TIME_MONOTONIC); |
| 622 | // Define a valid motion event. |
| 623 | NotifyMotionArgs args(/* sequenceNum */ 0, currentTime, DEVICE_ID, source, displayId, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 624 | POLICY_FLAG_PASS_TO_USER, action, /* actionButton */ 0, /* flags */ 0, |
| 625 | AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, |
Atif Niyaz | 21da0ff | 2019-06-28 13:22:51 -0700 | [diff] [blame] | 626 | AMOTION_EVENT_EDGE_FLAG_NONE, 1, pointerProperties, pointerCoords, |
| 627 | /* xPrecision */ 0, /* yPrecision */ 0, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 628 | AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 629 | AMOTION_EVENT_INVALID_CURSOR_POSITION, currentTime, /* videoFrames */ {}); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 630 | |
| 631 | return args; |
| 632 | } |
| 633 | |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 634 | TEST_F(InputDispatcherTest, SetInputWindow_SingleWindowTouch) { |
| 635 | sp<FakeApplicationHandle> application = new FakeApplicationHandle(); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 636 | sp<FakeWindowHandle> window = new FakeWindowHandle(application, mDispatcher, "Fake Window", |
| 637 | ADISPLAY_ID_DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 638 | |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 639 | mDispatcher->setInputWindows({window}, ADISPLAY_ID_DEFAULT); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 640 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 641 | AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 642 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 643 | |
| 644 | // Window should receive motion event. |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 645 | window->consumeMotionDown(ADISPLAY_ID_DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | // The foreground window should receive the first touch down event. |
| 649 | TEST_F(InputDispatcherTest, SetInputWindow_MultiWindowsTouch) { |
| 650 | sp<FakeApplicationHandle> application = new FakeApplicationHandle(); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 651 | sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top", |
| 652 | ADISPLAY_ID_DEFAULT); |
| 653 | sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second", |
| 654 | ADISPLAY_ID_DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 655 | |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 656 | mDispatcher->setInputWindows({windowTop, windowSecond}, ADISPLAY_ID_DEFAULT); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 657 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 658 | AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 659 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 660 | |
| 661 | // Top window should receive the touch down event. Second window should not receive anything. |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 662 | windowTop->consumeMotionDown(ADISPLAY_ID_DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 663 | windowSecond->assertNoEvents(); |
| 664 | } |
| 665 | |
| 666 | TEST_F(InputDispatcherTest, SetInputWindow_FocusedWindow) { |
| 667 | sp<FakeApplicationHandle> application = new FakeApplicationHandle(); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 668 | sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top", |
| 669 | ADISPLAY_ID_DEFAULT); |
| 670 | sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second", |
| 671 | ADISPLAY_ID_DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 672 | |
Arthur Hung | 7ab76b1 | 2019-01-09 19:17:20 +0800 | [diff] [blame] | 673 | // Set focused application. |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 674 | mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 675 | |
| 676 | // Expect one focus window exist in display. |
| 677 | windowSecond->setFocus(); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 678 | |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 679 | mDispatcher->setInputWindows({windowTop, windowSecond}, ADISPLAY_ID_DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 680 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher)) |
| 681 | << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 682 | |
| 683 | // Focused window should receive event. |
| 684 | windowTop->assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 685 | windowSecond->consumeKeyDown(ADISPLAY_ID_NONE); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 686 | } |
| 687 | |
Arthur Hung | 7ab76b1 | 2019-01-09 19:17:20 +0800 | [diff] [blame] | 688 | TEST_F(InputDispatcherTest, SetInputWindow_FocusPriority) { |
| 689 | sp<FakeApplicationHandle> application = new FakeApplicationHandle(); |
| 690 | sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top", |
| 691 | ADISPLAY_ID_DEFAULT); |
| 692 | sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second", |
| 693 | ADISPLAY_ID_DEFAULT); |
| 694 | |
| 695 | // Set focused application. |
| 696 | mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); |
| 697 | |
| 698 | // Display has two focused windows. Add them to inputWindowsHandles in z-order (top most first) |
| 699 | windowTop->setFocus(); |
| 700 | windowSecond->setFocus(); |
Arthur Hung | 7ab76b1 | 2019-01-09 19:17:20 +0800 | [diff] [blame] | 701 | |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 702 | mDispatcher->setInputWindows({windowTop, windowSecond}, ADISPLAY_ID_DEFAULT); |
Arthur Hung | 7ab76b1 | 2019-01-09 19:17:20 +0800 | [diff] [blame] | 703 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher)) |
| 704 | << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 705 | |
| 706 | // Top focused window should receive event. |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 707 | windowTop->consumeKeyDown(ADISPLAY_ID_NONE); |
Arthur Hung | 7ab76b1 | 2019-01-09 19:17:20 +0800 | [diff] [blame] | 708 | windowSecond->assertNoEvents(); |
| 709 | } |
| 710 | |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 711 | TEST_F(InputDispatcherTest, SetInputWindow_InputWindowInfo) { |
| 712 | sp<FakeApplicationHandle> application = new FakeApplicationHandle(); |
| 713 | |
| 714 | sp<FakeWindowHandle> windowTop = new FakeWindowHandle(application, mDispatcher, "Top", |
| 715 | ADISPLAY_ID_DEFAULT); |
| 716 | sp<FakeWindowHandle> windowSecond = new FakeWindowHandle(application, mDispatcher, "Second", |
| 717 | ADISPLAY_ID_DEFAULT); |
| 718 | |
Arthur Hung | 832bc4a | 2019-01-28 11:43:17 +0800 | [diff] [blame] | 719 | // Set focused application. |
| 720 | mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 721 | |
Arthur Hung | 832bc4a | 2019-01-28 11:43:17 +0800 | [diff] [blame] | 722 | windowTop->setFocus(); |
| 723 | windowSecond->setFocus(); |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 724 | // Release channel for window is no longer valid. |
| 725 | windowTop->releaseChannel(); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 726 | mDispatcher->setInputWindows({windowTop, windowSecond}, ADISPLAY_ID_DEFAULT); |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 727 | |
Arthur Hung | 832bc4a | 2019-01-28 11:43:17 +0800 | [diff] [blame] | 728 | // Test inject a key down, should dispatch to a valid window. |
| 729 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher)) |
| 730 | << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 731 | |
| 732 | // Top window is invalid, so it should not receive any input event. |
| 733 | windowTop->assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 734 | windowSecond->consumeKeyDown(ADISPLAY_ID_NONE); |
Arthur Hung | 3b413f2 | 2018-10-26 18:05:34 +0800 | [diff] [blame] | 735 | } |
| 736 | |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 737 | TEST_F(InputDispatcherTest, DispatchMouseEventsUnderCursor) { |
| 738 | sp<FakeApplicationHandle> application = new FakeApplicationHandle(); |
| 739 | |
| 740 | sp<FakeWindowHandle> windowLeft = |
| 741 | new FakeWindowHandle(application, mDispatcher, "Left", ADISPLAY_ID_DEFAULT); |
| 742 | windowLeft->setFrame(Rect(0, 0, 600, 800)); |
| 743 | windowLeft->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL); |
| 744 | sp<FakeWindowHandle> windowRight = |
| 745 | new FakeWindowHandle(application, mDispatcher, "Right", ADISPLAY_ID_DEFAULT); |
| 746 | windowRight->setFrame(Rect(600, 0, 1200, 800)); |
| 747 | windowRight->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL); |
| 748 | |
| 749 | mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); |
| 750 | |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 751 | mDispatcher->setInputWindows({windowLeft, windowRight}, ADISPLAY_ID_DEFAULT); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 752 | |
| 753 | // Inject an event with coordinate in the area of right window, with mouse cursor in the area of |
| 754 | // left window. This event should be dispatched to the left window. |
| 755 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, |
| 756 | injectMotionEvent(mDispatcher, AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_MOUSE, |
| 757 | ADISPLAY_ID_DEFAULT, 610, 400, 599, 400)); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 758 | windowLeft->consumeMotionDown(ADISPLAY_ID_DEFAULT); |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 759 | windowRight->assertNoEvents(); |
| 760 | } |
| 761 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 762 | /* Test InputDispatcher for MultiDisplay */ |
| 763 | class InputDispatcherFocusOnTwoDisplaysTest : public InputDispatcherTest { |
| 764 | public: |
| 765 | static constexpr int32_t SECOND_DISPLAY_ID = 1; |
| 766 | virtual void SetUp() { |
| 767 | InputDispatcherTest::SetUp(); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 768 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 769 | application1 = new FakeApplicationHandle(); |
| 770 | windowInPrimary = new FakeWindowHandle(application1, mDispatcher, "D_1", |
| 771 | ADISPLAY_ID_DEFAULT); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 772 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 773 | // Set focus window for primary display, but focused display would be second one. |
| 774 | mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application1); |
| 775 | windowInPrimary->setFocus(); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 776 | mDispatcher->setInputWindows({windowInPrimary}, ADISPLAY_ID_DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 777 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 778 | application2 = new FakeApplicationHandle(); |
| 779 | windowInSecondary = new FakeWindowHandle(application2, mDispatcher, "D_2", |
| 780 | SECOND_DISPLAY_ID); |
| 781 | // Set focus to second display window. |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 782 | // Set focus display to second one. |
| 783 | mDispatcher->setFocusedDisplay(SECOND_DISPLAY_ID); |
| 784 | // Set focus window for second display. |
| 785 | mDispatcher->setFocusedApplication(SECOND_DISPLAY_ID, application2); |
| 786 | windowInSecondary->setFocus(); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 787 | mDispatcher->setInputWindows({windowInSecondary}, SECOND_DISPLAY_ID); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | virtual void TearDown() { |
| 791 | InputDispatcherTest::TearDown(); |
| 792 | |
| 793 | application1.clear(); |
| 794 | windowInPrimary.clear(); |
| 795 | application2.clear(); |
| 796 | windowInSecondary.clear(); |
| 797 | } |
| 798 | |
| 799 | protected: |
| 800 | sp<FakeApplicationHandle> application1; |
| 801 | sp<FakeWindowHandle> windowInPrimary; |
| 802 | sp<FakeApplicationHandle> application2; |
| 803 | sp<FakeWindowHandle> windowInSecondary; |
| 804 | }; |
| 805 | |
| 806 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayTouch) { |
| 807 | // Test touch down on primary display. |
| 808 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 809 | AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 810 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 811 | windowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 812 | windowInSecondary->assertNoEvents(); |
| 813 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 814 | // Test touch down on second display. |
| 815 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 816 | AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID)) |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 817 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 818 | windowInPrimary->assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 819 | windowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 820 | } |
| 821 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 822 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, SetInputWindow_MultiDisplayFocus) { |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 823 | // Test inject a key down with display id specified. |
| 824 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT)) |
| 825 | << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 826 | windowInPrimary->consumeKeyDown(ADISPLAY_ID_DEFAULT); |
Tiger Huang | 721e26f | 2018-07-24 22:26:19 +0800 | [diff] [blame] | 827 | windowInSecondary->assertNoEvents(); |
| 828 | |
| 829 | // Test inject a key down without display id specified. |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 830 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher)) |
| 831 | << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 832 | windowInPrimary->assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 833 | windowInSecondary->consumeKeyDown(ADISPLAY_ID_NONE); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 834 | |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 835 | // Remove all windows in secondary display. |
| 836 | mDispatcher->setInputWindows({}, SECOND_DISPLAY_ID); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 837 | |
| 838 | // Expect old focus should receive a cancel event. |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 839 | windowInSecondary->consumeEvent(AINPUT_EVENT_TYPE_KEY, AKEY_EVENT_ACTION_UP, ADISPLAY_ID_NONE, |
| 840 | AKEY_EVENT_FLAG_CANCELED); |
Arthur Hung | b92218b | 2018-08-14 12:00:21 +0800 | [diff] [blame] | 841 | |
| 842 | // Test inject a key down, should timeout because of no target window. |
| 843 | ASSERT_EQ(INPUT_EVENT_INJECTION_TIMED_OUT, injectKeyDown(mDispatcher)) |
| 844 | << "Inject key event should return INPUT_EVENT_INJECTION_TIMED_OUT"; |
| 845 | windowInPrimary->assertNoEvents(); |
| 846 | windowInSecondary->assertNoEvents(); |
| 847 | } |
| 848 | |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 849 | class FakeMonitorReceiver : public FakeInputReceiver, public RefBase { |
| 850 | public: |
| 851 | FakeMonitorReceiver(const sp<InputDispatcher>& dispatcher, const std::string name, |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 852 | int32_t displayId, bool isGestureMonitor = false) |
| 853 | : FakeInputReceiver(dispatcher, name, displayId) { |
Michael Wright | 3dd60e2 | 2019-03-27 22:06:44 +0000 | [diff] [blame] | 854 | mDispatcher->registerInputMonitor(mServerChannel, displayId, isGestureMonitor); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 855 | } |
| 856 | }; |
| 857 | |
| 858 | // Test per-display input monitors for motion event. |
| 859 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorMotionEvent_MultiDisplay) { |
| 860 | sp<FakeMonitorReceiver> monitorInPrimary = |
| 861 | new FakeMonitorReceiver(mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); |
| 862 | sp<FakeMonitorReceiver> monitorInSecondary = |
| 863 | new FakeMonitorReceiver(mDispatcher, "M_2", SECOND_DISPLAY_ID); |
| 864 | |
| 865 | // Test touch down on primary display. |
| 866 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 867 | AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT)) |
| 868 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 869 | windowInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT); |
| 870 | monitorInPrimary->consumeMotionDown(ADISPLAY_ID_DEFAULT); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 871 | windowInSecondary->assertNoEvents(); |
| 872 | monitorInSecondary->assertNoEvents(); |
| 873 | |
| 874 | // Test touch down on second display. |
| 875 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 876 | AINPUT_SOURCE_TOUCHSCREEN, SECOND_DISPLAY_ID)) |
| 877 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 878 | windowInPrimary->assertNoEvents(); |
| 879 | monitorInPrimary->assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 880 | windowInSecondary->consumeMotionDown(SECOND_DISPLAY_ID); |
| 881 | monitorInSecondary->consumeMotionDown(SECOND_DISPLAY_ID); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 882 | |
| 883 | // Test inject a non-pointer motion event. |
| 884 | // If specific a display, it will dispatch to the focused window of particular display, |
| 885 | // or it will dispatch to the focused window of focused display. |
| 886 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 887 | AINPUT_SOURCE_TRACKBALL, ADISPLAY_ID_NONE)) |
| 888 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 889 | windowInPrimary->assertNoEvents(); |
| 890 | monitorInPrimary->assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 891 | windowInSecondary->consumeMotionDown(ADISPLAY_ID_NONE); |
| 892 | monitorInSecondary->consumeMotionDown(ADISPLAY_ID_NONE); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | // Test per-display input monitors for key event. |
| 896 | TEST_F(InputDispatcherFocusOnTwoDisplaysTest, MonitorKeyEvent_MultiDisplay) { |
| 897 | //Input monitor per display. |
| 898 | sp<FakeMonitorReceiver> monitorInPrimary = |
| 899 | new FakeMonitorReceiver(mDispatcher, "M_1", ADISPLAY_ID_DEFAULT); |
| 900 | sp<FakeMonitorReceiver> monitorInSecondary = |
| 901 | new FakeMonitorReceiver(mDispatcher, "M_2", SECOND_DISPLAY_ID); |
| 902 | |
| 903 | // Test inject a key down. |
| 904 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher)) |
| 905 | << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 906 | windowInPrimary->assertNoEvents(); |
| 907 | monitorInPrimary->assertNoEvents(); |
Siarhei Vishniakou | c5ca85c | 2019-11-15 17:20:00 -0800 | [diff] [blame] | 908 | windowInSecondary->consumeKeyDown(ADISPLAY_ID_NONE); |
| 909 | monitorInSecondary->consumeKeyDown(ADISPLAY_ID_NONE); |
Arthur Hung | 2fbf37f | 2018-09-13 18:16:41 +0800 | [diff] [blame] | 910 | } |
| 911 | |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 912 | class InputFilterTest : public InputDispatcherTest { |
| 913 | protected: |
| 914 | static constexpr int32_t SECOND_DISPLAY_ID = 1; |
| 915 | |
| 916 | void testNotifyMotion(int32_t displayId, bool expectToBeFiltered) { |
| 917 | NotifyMotionArgs motionArgs; |
| 918 | |
| 919 | motionArgs = generateMotionArgs( |
| 920 | AMOTION_EVENT_ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN, displayId); |
| 921 | mDispatcher->notifyMotion(&motionArgs); |
| 922 | motionArgs = generateMotionArgs( |
| 923 | AMOTION_EVENT_ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN, displayId); |
| 924 | mDispatcher->notifyMotion(&motionArgs); |
| 925 | |
| 926 | if (expectToBeFiltered) { |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 927 | mFakePolicy->assertFilterInputEventWasCalled(motionArgs); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 928 | } else { |
| 929 | mFakePolicy->assertFilterInputEventWasNotCalled(); |
| 930 | } |
| 931 | } |
| 932 | |
| 933 | void testNotifyKey(bool expectToBeFiltered) { |
| 934 | NotifyKeyArgs keyArgs; |
| 935 | |
| 936 | keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_DOWN); |
| 937 | mDispatcher->notifyKey(&keyArgs); |
| 938 | keyArgs = generateKeyArgs(AKEY_EVENT_ACTION_UP); |
| 939 | mDispatcher->notifyKey(&keyArgs); |
| 940 | |
| 941 | if (expectToBeFiltered) { |
Siarhei Vishniakou | 8935a80 | 2019-11-15 16:41:44 -0800 | [diff] [blame] | 942 | mFakePolicy->assertFilterInputEventWasCalled(keyArgs); |
Jackal Guo | f969668 | 2018-10-05 12:23:23 +0800 | [diff] [blame] | 943 | } else { |
| 944 | mFakePolicy->assertFilterInputEventWasNotCalled(); |
| 945 | } |
| 946 | } |
| 947 | }; |
| 948 | |
| 949 | // Test InputFilter for MotionEvent |
| 950 | TEST_F(InputFilterTest, MotionEvent_InputFilter) { |
| 951 | // Since the InputFilter is disabled by default, check if touch events aren't filtered. |
| 952 | testNotifyMotion(ADISPLAY_ID_DEFAULT, /*expectToBeFiltered*/ false); |
| 953 | testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered*/ false); |
| 954 | |
| 955 | // Enable InputFilter |
| 956 | mDispatcher->setInputFilterEnabled(true); |
| 957 | // Test touch on both primary and second display, and check if both events are filtered. |
| 958 | testNotifyMotion(ADISPLAY_ID_DEFAULT, /*expectToBeFiltered*/ true); |
| 959 | testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered*/ true); |
| 960 | |
| 961 | // Disable InputFilter |
| 962 | mDispatcher->setInputFilterEnabled(false); |
| 963 | // Test touch on both primary and second display, and check if both events aren't filtered. |
| 964 | testNotifyMotion(ADISPLAY_ID_DEFAULT, /*expectToBeFiltered*/ false); |
| 965 | testNotifyMotion(SECOND_DISPLAY_ID, /*expectToBeFiltered*/ false); |
| 966 | } |
| 967 | |
| 968 | // Test InputFilter for KeyEvent |
| 969 | TEST_F(InputFilterTest, KeyEvent_InputFilter) { |
| 970 | // Since the InputFilter is disabled by default, check if key event aren't filtered. |
| 971 | testNotifyKey(/*expectToBeFiltered*/ false); |
| 972 | |
| 973 | // Enable InputFilter |
| 974 | mDispatcher->setInputFilterEnabled(true); |
| 975 | // Send a key event, and check if it is filtered. |
| 976 | testNotifyKey(/*expectToBeFiltered*/ true); |
| 977 | |
| 978 | // Disable InputFilter |
| 979 | mDispatcher->setInputFilterEnabled(false); |
| 980 | // Send a key event, and check if it isn't filtered. |
| 981 | testNotifyKey(/*expectToBeFiltered*/ false); |
| 982 | } |
| 983 | |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 984 | class InputDispatcherOnPointerDownOutsideFocus : public InputDispatcherTest { |
| 985 | virtual void SetUp() { |
| 986 | InputDispatcherTest::SetUp(); |
| 987 | |
| 988 | sp<FakeApplicationHandle> application = new FakeApplicationHandle(); |
| 989 | mUnfocusedWindow = new FakeWindowHandle(application, mDispatcher, "Top", |
| 990 | ADISPLAY_ID_DEFAULT); |
| 991 | mUnfocusedWindow->setFrame(Rect(0, 0, 30, 30)); |
| 992 | // Adding FLAG_NOT_TOUCH_MODAL to ensure taps outside this window are not sent to this |
| 993 | // window. |
| 994 | mUnfocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL); |
| 995 | |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 996 | mFocusedWindow = |
| 997 | new FakeWindowHandle(application, mDispatcher, "Second", ADISPLAY_ID_DEFAULT); |
| 998 | mFocusedWindow->setFrame(Rect(50, 50, 100, 100)); |
| 999 | mFocusedWindow->setLayoutParamFlags(InputWindowInfo::FLAG_NOT_TOUCH_MODAL); |
| 1000 | mFocusedWindowTouchPoint = 60; |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 1001 | |
| 1002 | // Set focused application. |
| 1003 | mDispatcher->setFocusedApplication(ADISPLAY_ID_DEFAULT, application); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 1004 | mFocusedWindow->setFocus(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 1005 | |
| 1006 | // Expect one focus window exist in display. |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 1007 | mDispatcher->setInputWindows({mUnfocusedWindow, mFocusedWindow}, ADISPLAY_ID_DEFAULT); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | virtual void TearDown() { |
| 1011 | InputDispatcherTest::TearDown(); |
| 1012 | |
| 1013 | mUnfocusedWindow.clear(); |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 1014 | mFocusedWindow.clear(); |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | protected: |
| 1018 | sp<FakeWindowHandle> mUnfocusedWindow; |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 1019 | sp<FakeWindowHandle> mFocusedWindow; |
| 1020 | int32_t mFocusedWindowTouchPoint; |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 1021 | }; |
| 1022 | |
| 1023 | // Have two windows, one with focus. Inject MotionEvent with source TOUCHSCREEN and action |
| 1024 | // DOWN on the window that doesn't have focus. Ensure the window that didn't have focus received |
| 1025 | // the onPointerDownOutsideFocus callback. |
| 1026 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_Success) { |
| 1027 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 1028 | AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, 20, 20)) |
| 1029 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 1030 | // Call monitor to wait for the command queue to get flushed. |
| 1031 | mDispatcher->monitor(); |
| 1032 | |
| 1033 | mFakePolicy->assertOnPointerDownEquals(mUnfocusedWindow->getToken()); |
| 1034 | } |
| 1035 | |
| 1036 | // Have two windows, one with focus. Inject MotionEvent with source TRACKBALL and action |
| 1037 | // DOWN on the window that doesn't have focus. Ensure no window received the |
| 1038 | // onPointerDownOutsideFocus callback. |
| 1039 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonPointerSource) { |
| 1040 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectMotionDown(mDispatcher, |
| 1041 | AINPUT_SOURCE_TRACKBALL, ADISPLAY_ID_DEFAULT, 20, 20)) |
| 1042 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 1043 | // Call monitor to wait for the command queue to get flushed. |
| 1044 | mDispatcher->monitor(); |
| 1045 | |
| 1046 | mFakePolicy->assertOnPointerDownEquals(nullptr); |
| 1047 | } |
| 1048 | |
| 1049 | // Have two windows, one with focus. Inject KeyEvent with action DOWN on the window that doesn't |
| 1050 | // have focus. Ensure no window received the onPointerDownOutsideFocus callback. |
| 1051 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, OnPointerDownOutsideFocus_NonMotionFailure) { |
| 1052 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, injectKeyDown(mDispatcher, ADISPLAY_ID_DEFAULT)) |
| 1053 | << "Inject key event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 1054 | // Call monitor to wait for the command queue to get flushed. |
| 1055 | mDispatcher->monitor(); |
| 1056 | |
| 1057 | mFakePolicy->assertOnPointerDownEquals(nullptr); |
| 1058 | } |
| 1059 | |
| 1060 | // Have two windows, one with focus. Inject MotionEvent with source TOUCHSCREEN and action |
| 1061 | // DOWN on the window that already has focus. Ensure no window received the |
| 1062 | // onPointerDownOutsideFocus callback. |
| 1063 | TEST_F(InputDispatcherOnPointerDownOutsideFocus, |
| 1064 | OnPointerDownOutsideFocus_OnAlreadyFocusedWindow) { |
Siarhei Vishniakou | b9b1535 | 2019-11-26 13:19:26 -0800 | [diff] [blame^] | 1065 | ASSERT_EQ(INPUT_EVENT_INJECTION_SUCCEEDED, |
| 1066 | injectMotionDown(mDispatcher, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, |
| 1067 | mFocusedWindowTouchPoint, mFocusedWindowTouchPoint)) |
chaviw | fd6d351 | 2019-03-25 13:23:49 -0700 | [diff] [blame] | 1068 | << "Inject motion event should return INPUT_EVENT_INJECTION_SUCCEEDED"; |
| 1069 | // Call monitor to wait for the command queue to get flushed. |
| 1070 | mDispatcher->monitor(); |
| 1071 | |
| 1072 | mFakePolicy->assertOnPointerDownEquals(nullptr); |
| 1073 | } |
| 1074 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 1075 | } // namespace android::inputdispatcher |