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