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