diff options
Diffstat (limited to 'services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp')
-rw-r--r-- | services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp | 118 |
1 files changed, 71 insertions, 47 deletions
diff --git a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp index 5a14133eb2..bc77b8aef4 100644 --- a/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +++ b/services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp @@ -16,9 +16,14 @@ #include <benchmark/benchmark.h> +#include <android/os/IInputConstants.h> #include <binder/Binder.h> #include "../dispatcher/InputDispatcher.h" +using android::os::IInputConstants; +using android::os::InputEventInjectionResult; +using android::os::InputEventInjectionSync; + namespace android::inputdispatcher { // An arbitrary device id. @@ -45,49 +50,72 @@ protected: virtual ~FakeInputDispatcherPolicy() {} private: - virtual void notifyConfigurationChanged(nsecs_t) override {} + void notifyConfigurationChanged(nsecs_t) override {} - virtual nsecs_t notifyAnr(const sp<InputApplicationHandle>&, const sp<IBinder>&, - const std::string& name) override { - ALOGE("The window is not responding : %s", name.c_str()); - return 0; + void notifyNoFocusedWindowAnr( + const std::shared_ptr<InputApplicationHandle>& applicationHandle) override { + ALOGE("There is no focused window for %s", applicationHandle->getName().c_str()); } - virtual void notifyInputChannelBroken(const sp<IBinder>&) override {} + void notifyWindowUnresponsive(const sp<IBinder>& connectionToken, + const std::string& reason) override { + ALOGE("Window is not responding: %s", reason.c_str()); + } + + void notifyWindowResponsive(const sp<IBinder>& connectionToken) override {} + + void notifyMonitorUnresponsive(int32_t pid, const std::string& reason) override { + ALOGE("Monitor is not responding: %s", reason.c_str()); + } + + void notifyMonitorResponsive(int32_t pid) override {} + + void notifyInputChannelBroken(const sp<IBinder>&) override {} + + void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) override {} - virtual void notifyFocusChanged(const sp<IBinder>&, const sp<IBinder>&) override {} + void notifySensorEvent(int32_t deviceId, InputDeviceSensorType sensorType, + InputDeviceSensorAccuracy accuracy, nsecs_t timestamp, + const std::vector<float>& values) override {} - virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override { + void notifySensorAccuracy(int32_t deviceId, InputDeviceSensorType sensorType, + InputDeviceSensorAccuracy accuracy) override {} + + void notifyVibratorState(int32_t deviceId, bool isOn) override {} + + void notifyUntrustedTouch(const std::string& obscuringPackage) override {} + + void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override { *outConfig = mConfig; } - virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { + bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { return true; } - virtual void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {} + void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {} - virtual void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {} + void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {} - virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*, - uint32_t) override { + nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*, uint32_t) override { return 0; } - virtual bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t, - KeyEvent*) override { + bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t, KeyEvent*) override { return false; } - virtual void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) override {} + void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) override {} - virtual void pokeUserActivity(nsecs_t, int32_t) override {} + void pokeUserActivity(nsecs_t, int32_t, int32_t) override {} - virtual bool checkInjectEventsPermissionNonReentrant(int32_t, int32_t) override { - return false; - } + bool checkInjectEventsPermissionNonReentrant(int32_t, int32_t) override { return false; } + + void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {} - virtual void onPointerDownOutsideFocus(const sp<IBinder>& newToken) override {} + void setPointerCapture(bool enabled) override {} + + void notifyDropWindow(const sp<IBinder>&, float x, float y) override {} InputDispatcherConfiguration mConfig; }; @@ -98,7 +126,8 @@ public: virtual ~FakeApplicationHandle() {} virtual bool updateInfo() { - mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT.count(); + mInfo.dispatchingTimeoutMillis = + std::chrono::duration_cast<std::chrono::milliseconds>(DISPATCHING_TIMEOUT).count(); return true; } }; @@ -106,7 +135,7 @@ public: class FakeInputReceiver { public: void consumeEvent() { - uint32_t consumeSeq; + uint32_t consumeSeq = 0; InputEvent* event; std::chrono::time_point start = std::chrono::steady_clock::now(); @@ -132,14 +161,14 @@ public: protected: explicit FakeInputReceiver(const sp<InputDispatcher>& dispatcher, const std::string name) : mDispatcher(dispatcher) { - InputChannel::openInputChannelPair(name, mServerChannel, mClientChannel); + mClientChannel = *mDispatcher->createInputChannel(name); mConsumer = std::make_unique<InputConsumer>(mClientChannel); } virtual ~FakeInputReceiver() {} sp<InputDispatcher> mDispatcher; - sp<InputChannel> mServerChannel, mClientChannel; + std::shared_ptr<InputChannel> mClientChannel; std::unique_ptr<InputConsumer> mConsumer; PreallocatedInputEventFactory mEventFactory; }; @@ -149,21 +178,18 @@ public: static const int32_t WIDTH = 200; static const int32_t HEIGHT = 200; - FakeWindowHandle(const sp<InputApplicationHandle>& inputApplicationHandle, + FakeWindowHandle(const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle, const sp<InputDispatcher>& dispatcher, const std::string name) : FakeInputReceiver(dispatcher, name), mFrame(Rect(0, 0, WIDTH, HEIGHT)) { - mDispatcher->registerInputChannel(mServerChannel); - inputApplicationHandle->updateInfo(); mInfo.applicationInfo = *inputApplicationHandle->getInfo(); } virtual bool updateInfo() override { - mInfo.token = mServerChannel->getConnectionToken(); + mInfo.token = mClientChannel->getConnectionToken(); mInfo.name = "FakeWindowHandle"; - mInfo.layoutParamsFlags = 0; - mInfo.layoutParamsType = InputWindowInfo::TYPE_APPLICATION; - mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT.count(); + mInfo.type = InputWindowInfo::Type::APPLICATION; + mInfo.dispatchingTimeout = DISPATCHING_TIMEOUT; mInfo.frameLeft = mFrame.left; mInfo.frameTop = mFrame.top; mInfo.frameRight = mFrame.right; @@ -172,13 +198,11 @@ public: mInfo.touchableRegion.clear(); mInfo.addTouchableRegion(mFrame); mInfo.visible = true; - mInfo.canReceiveKeys = true; - mInfo.hasFocus = true; + mInfo.focusable = true; mInfo.hasWallpaper = false; mInfo.paused = false; mInfo.ownerPid = INJECTOR_PID; mInfo.ownerUid = INJECTOR_UID; - mInfo.inputFeatures = 0; mInfo.displayId = ADISPLAY_ID_DEFAULT; return true; @@ -202,15 +226,16 @@ static MotionEvent generateMotionEvent() { const nsecs_t currentTime = now(); + ui::Transform identityTransform; MotionEvent event; - event.initialize(InputEvent::nextId(), DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, + event.initialize(IInputConstants::INVALID_INPUT_EVENT_ID, DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, INVALID_HMAC, AMOTION_EVENT_ACTION_DOWN, /* actionButton */ 0, /* flags */ 0, /* edgeFlags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, - 1 /* xScale */, 1 /* yScale */, - /* xOffset */ 0, /* yOffset */ 0, /* xPrecision */ 0, + identityTransform, /* xPrecision */ 0, /* yPrecision */ 0, AMOTION_EVENT_INVALID_CURSOR_POSITION, - AMOTION_EVENT_INVALID_CURSOR_POSITION, currentTime, currentTime, + AMOTION_EVENT_INVALID_CURSOR_POSITION, AMOTION_EVENT_INVALID_DISPLAY_SIZE, + AMOTION_EVENT_INVALID_DISPLAY_SIZE, currentTime, currentTime, /*pointerCount*/ 1, pointerProperties, pointerCoords); return event; } @@ -229,8 +254,9 @@ static NotifyMotionArgs generateMotionArgs() { const nsecs_t currentTime = now(); // Define a valid motion event. - NotifyMotionArgs args(/* id */ 0, currentTime, DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, - ADISPLAY_ID_DEFAULT, POLICY_FLAG_PASS_TO_USER, AMOTION_EVENT_ACTION_DOWN, + NotifyMotionArgs args(IInputConstants::INVALID_INPUT_EVENT_ID, currentTime, currentTime, + DEVICE_ID, AINPUT_SOURCE_TOUCHSCREEN, ADISPLAY_ID_DEFAULT, + POLICY_FLAG_PASS_TO_USER, AMOTION_EVENT_ACTION_DOWN, /* actionButton */ 0, /* flags */ 0, AMETA_NONE, /* buttonState */ 0, MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1, pointerProperties, pointerCoords, @@ -249,7 +275,7 @@ static void benchmarkNotifyMotion(benchmark::State& state) { dispatcher->start(); // Create a window that will receive motion events - sp<FakeApplicationHandle> application = new FakeApplicationHandle(); + std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -259,14 +285,12 @@ static void benchmarkNotifyMotion(benchmark::State& state) { for (auto _ : state) { // Send ACTION_DOWN motionArgs.action = AMOTION_EVENT_ACTION_DOWN; - motionArgs.id = 0; motionArgs.downTime = now(); motionArgs.eventTime = motionArgs.downTime; dispatcher->notifyMotion(&motionArgs); // Send ACTION_UP motionArgs.action = AMOTION_EVENT_ACTION_UP; - motionArgs.id = 1; motionArgs.eventTime = now(); dispatcher->notifyMotion(&motionArgs); @@ -285,7 +309,7 @@ static void benchmarkInjectMotion(benchmark::State& state) { dispatcher->start(); // Create a window that will receive motion events - sp<FakeApplicationHandle> application = new FakeApplicationHandle(); + std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>(); sp<FakeWindowHandle> window = new FakeWindowHandle(application, dispatcher, "Fake Window"); dispatcher->setInputWindows({{ADISPLAY_ID_DEFAULT, {window}}}); @@ -294,13 +318,13 @@ static void benchmarkInjectMotion(benchmark::State& state) { MotionEvent event = generateMotionEvent(); // Send ACTION_DOWN dispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID, - INPUT_EVENT_INJECTION_SYNC_NONE, INJECT_EVENT_TIMEOUT, + InputEventInjectionSync::NONE, INJECT_EVENT_TIMEOUT, POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER); // Send ACTION_UP event.setAction(AMOTION_EVENT_ACTION_UP); dispatcher->injectInputEvent(&event, INJECTOR_PID, INJECTOR_UID, - INPUT_EVENT_INJECTION_SYNC_NONE, INJECT_EVENT_TIMEOUT, + InputEventInjectionSync::NONE, INJECT_EVENT_TIMEOUT, POLICY_FLAG_FILTERED | POLICY_FLAG_PASS_TO_USER); window->consumeEvent(); |