Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 <benchmark/benchmark.h> |
| 18 | |
| 19 | #include <binder/Binder.h> |
| 20 | #include "../dispatcher/InputDispatcher.h" |
| 21 | |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 22 | using android::os::InputEventInjectionResult; |
| 23 | using android::os::InputEventInjectionSync; |
| 24 | |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 25 | namespace android::inputdispatcher { |
| 26 | |
| 27 | // An arbitrary device id. |
| 28 | static const int32_t DEVICE_ID = 1; |
| 29 | |
| 30 | // An arbitrary injector pid / uid pair that has permission to inject events. |
| 31 | static const int32_t INJECTOR_PID = 999; |
| 32 | static const int32_t INJECTOR_UID = 1001; |
| 33 | |
Siarhei Vishniakou | 097c3db | 2020-05-06 14:18:38 -0700 | [diff] [blame] | 34 | static constexpr std::chrono::duration INJECT_EVENT_TIMEOUT = 5s; |
| 35 | static constexpr std::chrono::nanoseconds DISPATCHING_TIMEOUT = 100ms; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 36 | |
| 37 | static nsecs_t now() { |
| 38 | return systemTime(SYSTEM_TIME_MONOTONIC); |
| 39 | } |
| 40 | |
| 41 | // --- FakeInputDispatcherPolicy --- |
| 42 | |
| 43 | class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface { |
| 44 | public: |
| 45 | FakeInputDispatcherPolicy() {} |
| 46 | |
| 47 | protected: |
| 48 | virtual ~FakeInputDispatcherPolicy() {} |
| 49 | |
| 50 | private: |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 51 | void notifyConfigurationChanged(nsecs_t) override {} |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 52 | |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 53 | void notifyNoFocusedWindowAnr( |
| 54 | const std::shared_ptr<InputApplicationHandle>& applicationHandle) override { |
| 55 | ALOGE("There is no focused window for %s", applicationHandle->getName().c_str()); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Siarhei Vishniakou | 234129c | 2020-10-22 22:28:12 -0500 | [diff] [blame] | 58 | void notifyConnectionUnresponsive(const sp<IBinder>& connectionToken, |
| 59 | const std::string& reason) override { |
| 60 | ALOGE("Connection is not responding: %s", reason.c_str()); |
| 61 | } |
| 62 | |
| 63 | void notifyConnectionResponsive(const sp<IBinder>& connectionToken) override {} |
| 64 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 65 | void notifyInputChannelBroken(const sp<IBinder>&) override {} |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 66 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 67 | void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) override {} |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 68 | |
Bernardo Rufino | 2e1f651 | 2020-10-08 13:42:07 +0000 | [diff] [blame] | 69 | void notifyUntrustedTouch(const std::string& obscuringPackage) override {} |
| 70 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 71 | void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override { |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 72 | *outConfig = mConfig; |
| 73 | } |
| 74 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 75 | bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 79 | void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {} |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 80 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 81 | void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {} |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 82 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 83 | nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*, uint32_t) override { |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 87 | bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t, KeyEvent*) override { |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 88 | return false; |
| 89 | } |
| 90 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 91 | void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) override {} |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 92 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 93 | void pokeUserActivity(nsecs_t, int32_t) override {} |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 94 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 95 | bool checkInjectEventsPermissionNonReentrant(int32_t, int32_t) override { return false; } |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 96 | |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 97 | void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {} |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 98 | |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame^] | 99 | void setPointerCapture(bool enabled) override {} |
| 100 | |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 101 | InputDispatcherConfiguration mConfig; |
| 102 | }; |
| 103 | |
| 104 | class FakeApplicationHandle : public InputApplicationHandle { |
| 105 | public: |
| 106 | FakeApplicationHandle() {} |
| 107 | virtual ~FakeApplicationHandle() {} |
| 108 | |
| 109 | virtual bool updateInfo() { |
Siarhei Vishniakou | 7062295 | 2020-07-30 11:17:23 -0500 | [diff] [blame] | 110 | mInfo.dispatchingTimeoutMillis = |
| 111 | std::chrono::duration_cast<std::chrono::milliseconds>(DISPATCHING_TIMEOUT).count(); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 112 | return true; |
| 113 | } |
| 114 | }; |
| 115 | |
| 116 | class FakeInputReceiver { |
| 117 | public: |
| 118 | void consumeEvent() { |
Siarhei Vishniakou | d549b25 | 2020-08-11 11:25:26 -0500 | [diff] [blame] | 119 | uint32_t consumeSeq = 0; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 120 | InputEvent* event; |
| 121 | |
Siarhei Vishniakou | adfd4fa | 2019-12-20 11:02:58 -0800 | [diff] [blame] | 122 | std::chrono::time_point start = std::chrono::steady_clock::now(); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 123 | status_t result = WOULD_BLOCK; |
| 124 | while (result == WOULD_BLOCK) { |
Siarhei Vishniakou | adfd4fa | 2019-12-20 11:02:58 -0800 | [diff] [blame] | 125 | std::chrono::duration elapsed = std::chrono::steady_clock::now() - start; |
| 126 | if (elapsed > 10ms) { |
| 127 | ALOGE("Waited too long for consumer to produce an event, giving up"); |
| 128 | break; |
| 129 | } |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 130 | result = mConsumer->consume(&mEventFactory, true /*consumeBatches*/, -1, &consumeSeq, |
| 131 | &event); |
| 132 | } |
| 133 | if (result != OK) { |
| 134 | ALOGE("Received result = %d from consume()", result); |
| 135 | } |
| 136 | result = mConsumer->sendFinishedSignal(consumeSeq, true); |
| 137 | if (result != OK) { |
| 138 | ALOGE("Received result = %d from sendFinishedSignal", result); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | protected: |
| 143 | explicit FakeInputReceiver(const sp<InputDispatcher>& dispatcher, const std::string name) |
| 144 | : mDispatcher(dispatcher) { |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 145 | mClientChannel = *mDispatcher->createInputChannel(name); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 146 | mConsumer = std::make_unique<InputConsumer>(mClientChannel); |
| 147 | } |
| 148 | |
| 149 | virtual ~FakeInputReceiver() {} |
| 150 | |
| 151 | sp<InputDispatcher> mDispatcher; |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 152 | std::shared_ptr<InputChannel> mClientChannel; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 153 | std::unique_ptr<InputConsumer> mConsumer; |
| 154 | PreallocatedInputEventFactory mEventFactory; |
| 155 | }; |
| 156 | |
| 157 | class FakeWindowHandle : public InputWindowHandle, public FakeInputReceiver { |
| 158 | public: |
| 159 | static const int32_t WIDTH = 200; |
| 160 | static const int32_t HEIGHT = 200; |
| 161 | |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 162 | FakeWindowHandle(const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle, |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 163 | const sp<InputDispatcher>& dispatcher, const std::string name) |
| 164 | : FakeInputReceiver(dispatcher, name), mFrame(Rect(0, 0, WIDTH, HEIGHT)) { |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 165 | inputApplicationHandle->updateInfo(); |
| 166 | mInfo.applicationInfo = *inputApplicationHandle->getInfo(); |
| 167 | } |
| 168 | |
| 169 | virtual bool updateInfo() override { |
Garfield Tan | 1560166 | 2020-09-22 15:32:38 -0700 | [diff] [blame] | 170 | mInfo.token = mClientChannel->getConnectionToken(); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 171 | mInfo.name = "FakeWindowHandle"; |
Michael Wright | 44753b1 | 2020-07-08 13:48:11 +0100 | [diff] [blame] | 172 | mInfo.type = InputWindowInfo::Type::APPLICATION; |
Siarhei Vishniakou | c1ae556 | 2020-06-30 14:22:57 -0500 | [diff] [blame] | 173 | mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 174 | mInfo.frameLeft = mFrame.left; |
| 175 | mInfo.frameTop = mFrame.top; |
| 176 | mInfo.frameRight = mFrame.right; |
| 177 | mInfo.frameBottom = mFrame.bottom; |
| 178 | mInfo.globalScaleFactor = 1.0; |
| 179 | mInfo.touchableRegion.clear(); |
| 180 | mInfo.addTouchableRegion(mFrame); |
| 181 | mInfo.visible = true; |
Vishnu Nair | 47074b8 | 2020-08-14 11:54:47 -0700 | [diff] [blame] | 182 | mInfo.focusable = true; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 183 | mInfo.hasWallpaper = false; |
| 184 | mInfo.paused = false; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 185 | mInfo.ownerPid = INJECTOR_PID; |
| 186 | mInfo.ownerUid = INJECTOR_UID; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 187 | mInfo.displayId = ADISPLAY_ID_DEFAULT; |
| 188 | |
| 189 | return true; |
| 190 | } |
| 191 | |
| 192 | protected: |
| 193 | Rect mFrame; |
| 194 | }; |
| 195 | |
| 196 | static MotionEvent generateMotionEvent() { |
| 197 | PointerProperties pointerProperties[1]; |
| 198 | PointerCoords pointerCoords[1]; |
| 199 | |
| 200 | pointerProperties[0].clear(); |
| 201 | pointerProperties[0].id = 0; |
| 202 | pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 203 | |
| 204 | pointerCoords[0].clear(); |
| 205 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100); |
| 206 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 100); |
| 207 | |
| 208 | const nsecs_t currentTime = now(); |
| 209 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 210 | ui::Transform identityTransform; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 211 | MotionEvent event; |
Garfield Tan | fbe732e | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 212 | event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, |
| 213 | ADISPLAY_ID_DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, |
| 214 | /* actionButton */ 0, /* flags */ 0, |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 215 | /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 216 | identityTransform, /* xPrecision */ 0, |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 217 | /* yPrecision */ 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 218 | AMOTION_EVENT_INVALID_CURSOR_POSITION, currentTime, currentTime, |
| 219 | /*pointerCount*/ 1, pointerProperties, pointerCoords); |
| 220 | return event; |
| 221 | } |
| 222 | |
| 223 | static NotifyMotionArgs generateMotionArgs() { |
| 224 | PointerProperties pointerProperties[1]; |
| 225 | PointerCoords pointerCoords[1]; |
| 226 | |
| 227 | pointerProperties[0].clear(); |
| 228 | pointerProperties[0].id = 0; |
| 229 | pointerProperties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER; |
| 230 | |
| 231 | pointerCoords[0].clear(); |
| 232 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_X, 100); |
| 233 | pointerCoords[0].setAxisValue(AMOTION_EVENT_AXIS_Y, 100); |
| 234 | |
| 235 | const nsecs_t currentTime = now(); |
| 236 | // Define a valid motion event. |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 237 | NotifyMotionArgs args(/* id */ 0, currentTime, DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 238 | ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER, AMOTION_EVENT_ACTION_DOWN, |
| 239 | /* actionButton */ 0, /* flags */ 0, AMETA_NONE, /* buttonState */ 0, |
| 240 | MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1, |
| 241 | pointerProperties, pointerCoords, |
| 242 | /* xPrecision */ 0, /* yPrecision */ 0, |
| 243 | AMOTION_EVENT_INVALID_CURSOR_POSITION, |
| 244 | AMOTION_EVENT_INVALID_CURSOR_POSITION, currentTime, /* videoFrames */ {}); |
| 245 | |
| 246 | return args; |
| 247 | } |
| 248 | |
| 249 | static void benchmarkNotifyMotion(benchmark::State& state) { |
| 250 | // Create dispatcher |
| 251 | sp<FakeInputDispatcherPolicy> fakePolicy = new FakeInputDispatcherPolicy(); |
| 252 | sp<InputDispatcher> dispatcher = new InputDispatcher(fakePolicy); |
| 253 | dispatcher->setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); |
| 254 | dispatcher->start(); |
| 255 | |
| 256 | // Create a window that will receive motion events |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 257 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 258 | sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); |
| 259 | |
Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 260 | dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 261 | |
| 262 | NotifyMotionArgs motionArgs = generateMotionArgs(); |
| 263 | |
| 264 | for (auto _ : state) { |
| 265 | // Send ACTION_DOWN |
| 266 | motionArgs.action = AMOTION_EVENT_ACTION_DOWN; |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 267 | motionArgs.id = 0; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 268 | motionArgs.downTime = now(); |
| 269 | motionArgs.eventTime = motionArgs.downTime; |
| 270 | dispatcher->notifyMotion(&motionArgs); |
| 271 | |
| 272 | // Send ACTION_UP |
| 273 | motionArgs.action = AMOTION_EVENT_ACTION_UP; |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 274 | motionArgs.id = 1; |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 275 | motionArgs.eventTime = now(); |
| 276 | dispatcher->notifyMotion(&motionArgs); |
| 277 | |
| 278 | window->consumeEvent(); |
| 279 | window->consumeEvent(); |
| 280 | } |
| 281 | |
| 282 | dispatcher->stop(); |
| 283 | } |
| 284 | |
| 285 | static void benchmarkInjectMotion(benchmark::State& state) { |
| 286 | // Create dispatcher |
| 287 | sp<FakeInputDispatcherPolicy> fakePolicy = new FakeInputDispatcherPolicy(); |
| 288 | sp<InputDispatcher> dispatcher = new InputDispatcher(fakePolicy); |
| 289 | dispatcher->setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); |
| 290 | dispatcher->start(); |
| 291 | |
| 292 | // Create a window that will receive motion events |
Chris Ye | a209fde | 2020-07-22 13:54:51 -0700 | [diff] [blame] | 293 | std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 294 | sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); |
| 295 | |
Arthur Hung | 72d8dc3 | 2020-03-28 00:48:39 +0000 | [diff] [blame] | 296 | dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 297 | |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 298 | for (auto _ : state) { |
Siarhei Vishniakou | adfd4fa | 2019-12-20 11:02:58 -0800 | [diff] [blame] | 299 | MotionEvent event = generateMotionEvent(); |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 300 | // Send ACTION_DOWN |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 301 | dispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 302 | InputEventInjectionSync::NONE, INJECT_EVENT_TIMEOUT, |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 303 | POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER); |
| 304 | |
| 305 | // Send ACTION_UP |
| 306 | event.setAction(AMOTION_EVENT_ACTION_UP); |
| 307 | dispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID, |
Siarhei Vishniakou | ae6229e | 2019-12-30 16:23:19 -0800 | [diff] [blame] | 308 | InputEventInjectionSync::NONE, INJECT_EVENT_TIMEOUT, |
Siarhei Vishniakou | d078476 | 2019-11-01 15:33:48 -0700 | [diff] [blame] | 309 | POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER); |
| 310 | |
| 311 | window->consumeEvent(); |
| 312 | window->consumeEvent(); |
| 313 | } |
| 314 | |
| 315 | dispatcher->stop(); |
| 316 | } |
| 317 | |
| 318 | BENCHMARK(benchmarkNotifyMotion); |
| 319 | BENCHMARK(benchmarkInjectMotion); |
| 320 | |
| 321 | } // namespace android::inputdispatcher |
| 322 | |
| 323 | BENCHMARK_MAIN(); |