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