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