Loading services/inputflinger/InputManager.cpp +2 −3 Original line number Original line Diff line number Diff line Loading @@ -57,9 +57,8 @@ static int32_t exceptionCodeFromStatusT(status_t status) { * The event flow is via the "InputListener" interface, as follows: * The event flow is via the "InputListener" interface, as follows: * InputReader -> UnwantedInteractionBlocker -> InputProcessor -> InputDispatcher * InputReader -> UnwantedInteractionBlocker -> InputProcessor -> InputDispatcher */ */ InputManager::InputManager( InputManager::InputManager(const sp<InputReaderPolicyInterface>& readerPolicy, const sp<InputReaderPolicyInterface>& readerPolicy, InputDispatcherPolicyInterface& dispatcherPolicy) { const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) { mDispatcher = createInputDispatcher(dispatcherPolicy); mDispatcher = createInputDispatcher(dispatcherPolicy); mProcessor = std::make_unique<InputProcessor>(*mDispatcher); mProcessor = std::make_unique<InputProcessor>(*mDispatcher); mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mProcessor); mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mProcessor); Loading services/inputflinger/InputManager.h +2 −3 Original line number Original line Diff line number Diff line Loading @@ -100,9 +100,8 @@ protected: ~InputManager() override; ~InputManager() override; public: public: InputManager( InputManager(const sp<InputReaderPolicyInterface>& readerPolicy, const sp<InputReaderPolicyInterface>& readerPolicy, InputDispatcherPolicyInterface& dispatcherPolicy); const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); status_t start() override; status_t start() override; status_t stop() override; status_t stop() override; Loading services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +13 −16 Original line number Original line Diff line number Diff line Loading @@ -48,10 +48,8 @@ static nsecs_t now() { class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface { class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface { public: public: FakeInputDispatcherPolicy() {} FakeInputDispatcherPolicy() = default; virtual ~FakeInputDispatcherPolicy() = default; protected: virtual ~FakeInputDispatcherPolicy() {} private: private: void notifyConfigurationChanged(nsecs_t) override {} void notifyConfigurationChanged(nsecs_t) override {} Loading Loading @@ -82,24 +80,23 @@ private: void notifyVibratorState(int32_t deviceId, bool isOn) override {} void notifyVibratorState(int32_t deviceId, bool isOn) override {} void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override { InputDispatcherConfiguration getDispatcherConfiguration() override { return mConfig; } *outConfig = mConfig; } bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { bool filterInputEvent(const InputEvent& inputEvent, uint32_t policyFlags) override { return true; return true; // dispatch event normally } } void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {} void interceptKeyBeforeQueueing(const KeyEvent&, uint32_t&) override {} void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {} void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {} nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*, uint32_t) override { nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) override { return 0; return 0; } } bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t, KeyEvent*) override { std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent&, return false; uint32_t) override { return {}; } } void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) override {} void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) override {} Loading Loading @@ -258,7 +255,7 @@ static NotifyMotionArgs generateMotionArgs() { static void benchmarkNotifyMotion(benchmark::State& state) { static void benchmarkNotifyMotion(benchmark::State& state) { // Create dispatcher // Create dispatcher sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); FakeInputDispatcherPolicy fakePolicy; InputDispatcher dispatcher(fakePolicy); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); dispatcher.start(); Loading Loading @@ -293,7 +290,7 @@ static void benchmarkNotifyMotion(benchmark::State& state) { static void benchmarkInjectMotion(benchmark::State& state) { static void benchmarkInjectMotion(benchmark::State& state) { // Create dispatcher // Create dispatcher sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); FakeInputDispatcherPolicy fakePolicy; InputDispatcher dispatcher(fakePolicy); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); dispatcher.start(); Loading Loading @@ -327,7 +324,7 @@ static void benchmarkInjectMotion(benchmark::State& state) { static void benchmarkOnWindowInfosChanged(benchmark::State& state) { static void benchmarkOnWindowInfosChanged(benchmark::State& state) { // Create dispatcher // Create dispatcher sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); FakeInputDispatcherPolicy fakePolicy; InputDispatcher dispatcher(fakePolicy); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); dispatcher.start(); Loading services/inputflinger/dispatcher/InputDispatcher.cpp +38 −32 Original line number Original line Diff line number Diff line Loading @@ -685,10 +685,10 @@ std::vector<T>& operator+=(std::vector<T>& left, const std::vector<T>& right) { // --- InputDispatcher --- // --- InputDispatcher --- InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy) InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy) : InputDispatcher(policy, STALE_EVENT_TIMEOUT) {} : InputDispatcher(policy, STALE_EVENT_TIMEOUT) {} InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy, InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy, std::chrono::nanoseconds staleEventTimeout) std::chrono::nanoseconds staleEventTimeout) : mPolicy(policy), : mPolicy(policy), mPendingEvent(nullptr), mPendingEvent(nullptr), Loading Loading @@ -1440,7 +1440,7 @@ bool InputDispatcher::dispatchConfigurationChangedLocked(nsecs_t currentTime, // Enqueue a command to run outside the lock to tell the policy that the configuration changed. // Enqueue a command to run outside the lock to tell the policy that the configuration changed. auto command = [this, eventTime = entry.eventTime]() REQUIRES(mLock) { auto command = [this, eventTime = entry.eventTime]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyConfigurationChanged(eventTime); mPolicy.notifyConfigurationChanged(eventTime); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); return true; return true; Loading Loading @@ -1759,9 +1759,9 @@ void InputDispatcher::dispatchSensorLocked(nsecs_t currentTime, scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); if (entry->accuracyChanged) { if (entry->accuracyChanged) { mPolicy->notifySensorAccuracy(entry->deviceId, entry->sensorType, entry->accuracy); mPolicy.notifySensorAccuracy(entry->deviceId, entry->sensorType, entry->accuracy); } } mPolicy->notifySensorEvent(entry->deviceId, entry->sensorType, entry->accuracy, mPolicy.notifySensorEvent(entry->deviceId, entry->sensorType, entry->accuracy, entry->hwTimestamp, entry->values); entry->hwTimestamp, entry->values); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); Loading Loading @@ -3075,7 +3075,7 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) { auto command = [this, eventTime = eventEntry.eventTime, eventType, displayId]() auto command = [this, eventTime = eventEntry.eventTime, eventType, displayId]() REQUIRES(mLock) { REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->pokeUserActivity(eventTime, eventType, displayId); mPolicy.pokeUserActivity(eventTime, eventType, displayId); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -3416,7 +3416,7 @@ void InputDispatcher::dispatchPointerDownOutsideFocus(uint32_t source, int32_t a auto command = [this, token]() REQUIRES(mLock) { auto command = [this, token]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->onPointerDownOutsideFocus(token); mPolicy.onPointerDownOutsideFocus(token); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -3695,7 +3695,7 @@ void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime, auto command = [this, connection]() REQUIRES(mLock) { auto command = [this, connection]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyInputChannelBroken(connection->inputChannel->getConnectionToken()); mPolicy.notifyInputChannelBroken(connection->inputChannel->getConnectionToken()); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -4178,7 +4178,7 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs& args) { args.eventTime); args.eventTime); android::base::Timer t; android::base::Timer t; mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags); mPolicy.interceptKeyBeforeQueueing(event, /*byref*/ policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptKeyBeforeQueueing; took %s ms", ALOGW("Excessive delay in interceptKeyBeforeQueueing; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading @@ -4192,7 +4192,7 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs& args) { mLock.unlock(); mLock.unlock(); policyFlags |= POLICY_FLAG_FILTERED; policyFlags |= POLICY_FLAG_FILTERED; if (!mPolicy->filterInputEvent(&event, policyFlags)) { if (!mPolicy.filterInputEvent(event, policyFlags)) { return; // event was consumed by the filter return; // event was consumed by the filter } } Loading Loading @@ -4257,7 +4257,7 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs& args) { policyFlags |= POLICY_FLAG_TRUSTED; policyFlags |= POLICY_FLAG_TRUSTED; android::base::Timer t; android::base::Timer t; mPolicy->interceptMotionBeforeQueueing(args.displayId, args.eventTime, policyFlags); mPolicy.interceptMotionBeforeQueueing(args.displayId, args.eventTime, policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms", ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading Loading @@ -4296,7 +4296,7 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs& args) { args.pointerProperties, args.pointerCoords); args.pointerProperties, args.pointerCoords); policyFlags |= POLICY_FLAG_FILTERED; policyFlags |= POLICY_FLAG_FILTERED; if (!mPolicy->filterInputEvent(&event, policyFlags)) { if (!mPolicy.filterInputEvent(event, policyFlags)) { return; // event was consumed by the filter return; // event was consumed by the filter } } Loading Loading @@ -4362,7 +4362,7 @@ void InputDispatcher::notifyVibratorState(const NotifyVibratorStateArgs& args) { ALOGD("notifyVibratorState - eventTime=%" PRId64 ", device=%d, isOn=%d", args.eventTime, ALOGD("notifyVibratorState - eventTime=%" PRId64 ", device=%d, isOn=%d", args.eventTime, args.deviceId, args.isOn); args.deviceId, args.isOn); } } mPolicy->notifyVibratorState(args.deviceId, args.isOn); mPolicy.notifyVibratorState(args.deviceId, args.isOn); } } bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs& args) { bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs& args) { Loading @@ -4378,7 +4378,7 @@ void InputDispatcher::notifySwitch(const NotifySwitchArgs& args) { uint32_t policyFlags = args.policyFlags; uint32_t policyFlags = args.policyFlags; policyFlags |= POLICY_FLAG_TRUSTED; policyFlags |= POLICY_FLAG_TRUSTED; mPolicy->notifySwitch(args.eventTime, args.switchValues, args.switchMask, policyFlags); mPolicy.notifySwitch(args.eventTime, args.switchValues, args.switchMask, policyFlags); } } void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs& args) { void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs& args) { Loading Loading @@ -4477,7 +4477,7 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev if (!(policyFlags & POLICY_FLAG_FILTERED)) { if (!(policyFlags & POLICY_FLAG_FILTERED)) { android::base::Timer t; android::base::Timer t; mPolicy->interceptKeyBeforeQueueing(&keyEvent, /*byref*/ policyFlags); mPolicy.interceptKeyBeforeQueueing(keyEvent, /*byref*/ policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptKeyBeforeQueueing; took %s ms", ALOGW("Excessive delay in interceptKeyBeforeQueueing; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading Loading @@ -4509,7 +4509,7 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev if (!(policyFlags & POLICY_FLAG_FILTERED)) { if (!(policyFlags & POLICY_FLAG_FILTERED)) { nsecs_t eventTime = motionEvent.getEventTime(); nsecs_t eventTime = motionEvent.getEventTime(); android::base::Timer t; android::base::Timer t; mPolicy->interceptMotionBeforeQueueing(displayId, eventTime, /*byref*/ policyFlags); mPolicy.interceptMotionBeforeQueueing(displayId, eventTime, /*byref*/ policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms", ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading Loading @@ -6066,7 +6066,7 @@ void InputDispatcher::sendFocusChangedCommandLocked(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) { const sp<IBinder>& newToken) { auto command = [this, oldToken, newToken]() REQUIRES(mLock) { auto command = [this, oldToken, newToken]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyFocusChanged(oldToken, newToken); mPolicy.notifyFocusChanged(oldToken, newToken); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading @@ -6074,7 +6074,7 @@ void InputDispatcher::sendFocusChangedCommandLocked(const sp<IBinder>& oldToken, void InputDispatcher::sendDropWindowCommandLocked(const sp<IBinder>& token, float x, float y) { void InputDispatcher::sendDropWindowCommandLocked(const sp<IBinder>& token, float x, float y) { auto command = [this, token, x, y]() REQUIRES(mLock) { auto command = [this, token, x, y]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyDropWindow(token, x, y); mPolicy.notifyDropWindow(token, x, y); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -6121,7 +6121,7 @@ void InputDispatcher::onAnrLocked(std::shared_ptr<InputApplicationHandle> applic auto command = [this, application = std::move(application)]() REQUIRES(mLock) { auto command = [this, application = std::move(application)]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyNoFocusedWindowAnr(application); mPolicy.notifyNoFocusedWindowAnr(application); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -6161,8 +6161,7 @@ void InputDispatcher::doInterceptKeyBeforeDispatchingCommand(const sp<IBinder>& { // release lock { // release lock scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); android::base::Timer t; android::base::Timer t; delay = mPolicy->interceptKeyBeforeDispatching(focusedWindowToken, &event, delay = mPolicy.interceptKeyBeforeDispatching(focusedWindowToken, event, entry.policyFlags); entry.policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptKeyBeforeDispatching; took %s ms", ALOGW("Excessive delay in interceptKeyBeforeDispatching; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading @@ -6184,7 +6183,7 @@ void InputDispatcher::sendWindowUnresponsiveCommandLocked(const sp<IBinder>& tok std::string reason) { std::string reason) { auto command = [this, token, pid, reason = std::move(reason)]() REQUIRES(mLock) { auto command = [this, token, pid, reason = std::move(reason)]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyWindowUnresponsive(token, pid, reason); mPolicy.notifyWindowUnresponsive(token, pid, reason); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading @@ -6193,7 +6192,7 @@ void InputDispatcher::sendWindowResponsiveCommandLocked(const sp<IBinder>& token std::optional<int32_t> pid) { std::optional<int32_t> pid) { auto command = [this, token, pid]() REQUIRES(mLock) { auto command = [this, token, pid]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyWindowResponsive(token, pid); mPolicy.notifyWindowResponsive(token, pid); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -6277,8 +6276,12 @@ bool InputDispatcher::afterKeyEventLockedInterruptable( mLock.unlock(); mLock.unlock(); mPolicy->dispatchUnhandledKey(connection->inputChannel->getConnectionToken(), &event, if (const auto unhandledKeyFallback = keyEntry.policyFlags, &event); mPolicy.dispatchUnhandledKey(connection->inputChannel->getConnectionToken(), event, keyEntry.policyFlags); unhandledKeyFallback) { event = *unhandledKeyFallback; } mLock.lock(); mLock.lock(); Loading Loading @@ -6318,9 +6321,13 @@ bool InputDispatcher::afterKeyEventLockedInterruptable( mLock.unlock(); mLock.unlock(); bool fallback = bool fallback = false; mPolicy->dispatchUnhandledKey(connection->inputChannel->getConnectionToken(), if (auto fb = mPolicy.dispatchUnhandledKey(connection->inputChannel->getConnectionToken(), &event, keyEntry.policyFlags, &event); event, keyEntry.policyFlags); fb) { fallback = true; event = *fb; } mLock.lock(); mLock.lock(); Loading Loading @@ -6572,7 +6579,7 @@ void InputDispatcher::setPointerCaptureLocked(bool enable) { mCurrentPointerCaptureRequest.seq++; mCurrentPointerCaptureRequest.seq++; auto command = [this, request = mCurrentPointerCaptureRequest]() REQUIRES(mLock) { auto command = [this, request = mCurrentPointerCaptureRequest]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->setPointerCapture(request); mPolicy.setPointerCapture(request); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -6665,8 +6672,7 @@ void InputDispatcher::cancelCurrentTouch() { } } void InputDispatcher::requestRefreshConfiguration() { void InputDispatcher::requestRefreshConfiguration() { InputDispatcherConfiguration config; InputDispatcherConfiguration config = mPolicy.getDispatcherConfiguration(); mPolicy->getDispatcherConfiguration(&config); std::scoped_lock _l(mLock); std::scoped_lock _l(mLock); mConfig = config; mConfig = config; Loading services/inputflinger/dispatcher/InputDispatcher.h +3 −3 Original line number Original line Diff line number Diff line Loading @@ -82,8 +82,8 @@ class InputDispatcher : public android::InputDispatcherInterface { public: public: static constexpr bool kDefaultInTouchMode = true; static constexpr bool kDefaultInTouchMode = true; explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy); explicit InputDispatcher(InputDispatcherPolicyInterface& policy); explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy, explicit InputDispatcher(InputDispatcherPolicyInterface& policy, std::chrono::nanoseconds staleEventTimeout); std::chrono::nanoseconds staleEventTimeout); ~InputDispatcher() override; ~InputDispatcher() override; Loading Loading @@ -167,7 +167,7 @@ private: std::unique_ptr<InputThread> mThread; std::unique_ptr<InputThread> mThread; sp<InputDispatcherPolicyInterface> mPolicy; InputDispatcherPolicyInterface& mPolicy; android::InputDispatcherConfiguration mConfig GUARDED_BY(mLock); android::InputDispatcherConfiguration mConfig GUARDED_BY(mLock); std::mutex mLock; std::mutex mLock; Loading Loading
services/inputflinger/InputManager.cpp +2 −3 Original line number Original line Diff line number Diff line Loading @@ -57,9 +57,8 @@ static int32_t exceptionCodeFromStatusT(status_t status) { * The event flow is via the "InputListener" interface, as follows: * The event flow is via the "InputListener" interface, as follows: * InputReader -> UnwantedInteractionBlocker -> InputProcessor -> InputDispatcher * InputReader -> UnwantedInteractionBlocker -> InputProcessor -> InputDispatcher */ */ InputManager::InputManager( InputManager::InputManager(const sp<InputReaderPolicyInterface>& readerPolicy, const sp<InputReaderPolicyInterface>& readerPolicy, InputDispatcherPolicyInterface& dispatcherPolicy) { const sp<InputDispatcherPolicyInterface>& dispatcherPolicy) { mDispatcher = createInputDispatcher(dispatcherPolicy); mDispatcher = createInputDispatcher(dispatcherPolicy); mProcessor = std::make_unique<InputProcessor>(*mDispatcher); mProcessor = std::make_unique<InputProcessor>(*mDispatcher); mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mProcessor); mBlocker = std::make_unique<UnwantedInteractionBlocker>(*mProcessor); Loading
services/inputflinger/InputManager.h +2 −3 Original line number Original line Diff line number Diff line Loading @@ -100,9 +100,8 @@ protected: ~InputManager() override; ~InputManager() override; public: public: InputManager( InputManager(const sp<InputReaderPolicyInterface>& readerPolicy, const sp<InputReaderPolicyInterface>& readerPolicy, InputDispatcherPolicyInterface& dispatcherPolicy); const sp<InputDispatcherPolicyInterface>& dispatcherPolicy); status_t start() override; status_t start() override; status_t stop() override; status_t stop() override; Loading
services/inputflinger/benchmarks/InputDispatcher_benchmarks.cpp +13 −16 Original line number Original line Diff line number Diff line Loading @@ -48,10 +48,8 @@ static nsecs_t now() { class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface { class FakeInputDispatcherPolicy : public InputDispatcherPolicyInterface { public: public: FakeInputDispatcherPolicy() {} FakeInputDispatcherPolicy() = default; virtual ~FakeInputDispatcherPolicy() = default; protected: virtual ~FakeInputDispatcherPolicy() {} private: private: void notifyConfigurationChanged(nsecs_t) override {} void notifyConfigurationChanged(nsecs_t) override {} Loading Loading @@ -82,24 +80,23 @@ private: void notifyVibratorState(int32_t deviceId, bool isOn) override {} void notifyVibratorState(int32_t deviceId, bool isOn) override {} void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig) override { InputDispatcherConfiguration getDispatcherConfiguration() override { return mConfig; } *outConfig = mConfig; } bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags) override { bool filterInputEvent(const InputEvent& inputEvent, uint32_t policyFlags) override { return true; return true; // dispatch event normally } } void interceptKeyBeforeQueueing(const KeyEvent*, uint32_t&) override {} void interceptKeyBeforeQueueing(const KeyEvent&, uint32_t&) override {} void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {} void interceptMotionBeforeQueueing(int32_t, nsecs_t, uint32_t&) override {} nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent*, uint32_t) override { nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) override { return 0; return 0; } } bool dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent*, uint32_t, KeyEvent*) override { std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent&, return false; uint32_t) override { return {}; } } void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) override {} void notifySwitch(nsecs_t, uint32_t, uint32_t, uint32_t) override {} Loading Loading @@ -258,7 +255,7 @@ static NotifyMotionArgs generateMotionArgs() { static void benchmarkNotifyMotion(benchmark::State& state) { static void benchmarkNotifyMotion(benchmark::State& state) { // Create dispatcher // Create dispatcher sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); FakeInputDispatcherPolicy fakePolicy; InputDispatcher dispatcher(fakePolicy); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); dispatcher.start(); Loading Loading @@ -293,7 +290,7 @@ static void benchmarkNotifyMotion(benchmark::State& state) { static void benchmarkInjectMotion(benchmark::State& state) { static void benchmarkInjectMotion(benchmark::State& state) { // Create dispatcher // Create dispatcher sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); FakeInputDispatcherPolicy fakePolicy; InputDispatcher dispatcher(fakePolicy); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); dispatcher.start(); Loading Loading @@ -327,7 +324,7 @@ static void benchmarkInjectMotion(benchmark::State& state) { static void benchmarkOnWindowInfosChanged(benchmark::State& state) { static void benchmarkOnWindowInfosChanged(benchmark::State& state) { // Create dispatcher // Create dispatcher sp<FakeInputDispatcherPolicy> fakePolicy = sp<FakeInputDispatcherPolicy>::make(); FakeInputDispatcherPolicy fakePolicy; InputDispatcher dispatcher(fakePolicy); InputDispatcher dispatcher(fakePolicy); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.setInputDispatchMode(/*enabled*/ true, /*frozen*/ false); dispatcher.start(); dispatcher.start(); Loading
services/inputflinger/dispatcher/InputDispatcher.cpp +38 −32 Original line number Original line Diff line number Diff line Loading @@ -685,10 +685,10 @@ std::vector<T>& operator+=(std::vector<T>& left, const std::vector<T>& right) { // --- InputDispatcher --- // --- InputDispatcher --- InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy) InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy) : InputDispatcher(policy, STALE_EVENT_TIMEOUT) {} : InputDispatcher(policy, STALE_EVENT_TIMEOUT) {} InputDispatcher::InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy, InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy, std::chrono::nanoseconds staleEventTimeout) std::chrono::nanoseconds staleEventTimeout) : mPolicy(policy), : mPolicy(policy), mPendingEvent(nullptr), mPendingEvent(nullptr), Loading Loading @@ -1440,7 +1440,7 @@ bool InputDispatcher::dispatchConfigurationChangedLocked(nsecs_t currentTime, // Enqueue a command to run outside the lock to tell the policy that the configuration changed. // Enqueue a command to run outside the lock to tell the policy that the configuration changed. auto command = [this, eventTime = entry.eventTime]() REQUIRES(mLock) { auto command = [this, eventTime = entry.eventTime]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyConfigurationChanged(eventTime); mPolicy.notifyConfigurationChanged(eventTime); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); return true; return true; Loading Loading @@ -1759,9 +1759,9 @@ void InputDispatcher::dispatchSensorLocked(nsecs_t currentTime, scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); if (entry->accuracyChanged) { if (entry->accuracyChanged) { mPolicy->notifySensorAccuracy(entry->deviceId, entry->sensorType, entry->accuracy); mPolicy.notifySensorAccuracy(entry->deviceId, entry->sensorType, entry->accuracy); } } mPolicy->notifySensorEvent(entry->deviceId, entry->sensorType, entry->accuracy, mPolicy.notifySensorEvent(entry->deviceId, entry->sensorType, entry->accuracy, entry->hwTimestamp, entry->values); entry->hwTimestamp, entry->values); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); Loading Loading @@ -3075,7 +3075,7 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) { auto command = [this, eventTime = eventEntry.eventTime, eventType, displayId]() auto command = [this, eventTime = eventEntry.eventTime, eventType, displayId]() REQUIRES(mLock) { REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->pokeUserActivity(eventTime, eventType, displayId); mPolicy.pokeUserActivity(eventTime, eventType, displayId); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -3416,7 +3416,7 @@ void InputDispatcher::dispatchPointerDownOutsideFocus(uint32_t source, int32_t a auto command = [this, token]() REQUIRES(mLock) { auto command = [this, token]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->onPointerDownOutsideFocus(token); mPolicy.onPointerDownOutsideFocus(token); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -3695,7 +3695,7 @@ void InputDispatcher::abortBrokenDispatchCycleLocked(nsecs_t currentTime, auto command = [this, connection]() REQUIRES(mLock) { auto command = [this, connection]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyInputChannelBroken(connection->inputChannel->getConnectionToken()); mPolicy.notifyInputChannelBroken(connection->inputChannel->getConnectionToken()); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -4178,7 +4178,7 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs& args) { args.eventTime); args.eventTime); android::base::Timer t; android::base::Timer t; mPolicy->interceptKeyBeforeQueueing(&event, /*byref*/ policyFlags); mPolicy.interceptKeyBeforeQueueing(event, /*byref*/ policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptKeyBeforeQueueing; took %s ms", ALOGW("Excessive delay in interceptKeyBeforeQueueing; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading @@ -4192,7 +4192,7 @@ void InputDispatcher::notifyKey(const NotifyKeyArgs& args) { mLock.unlock(); mLock.unlock(); policyFlags |= POLICY_FLAG_FILTERED; policyFlags |= POLICY_FLAG_FILTERED; if (!mPolicy->filterInputEvent(&event, policyFlags)) { if (!mPolicy.filterInputEvent(event, policyFlags)) { return; // event was consumed by the filter return; // event was consumed by the filter } } Loading Loading @@ -4257,7 +4257,7 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs& args) { policyFlags |= POLICY_FLAG_TRUSTED; policyFlags |= POLICY_FLAG_TRUSTED; android::base::Timer t; android::base::Timer t; mPolicy->interceptMotionBeforeQueueing(args.displayId, args.eventTime, policyFlags); mPolicy.interceptMotionBeforeQueueing(args.displayId, args.eventTime, policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms", ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading Loading @@ -4296,7 +4296,7 @@ void InputDispatcher::notifyMotion(const NotifyMotionArgs& args) { args.pointerProperties, args.pointerCoords); args.pointerProperties, args.pointerCoords); policyFlags |= POLICY_FLAG_FILTERED; policyFlags |= POLICY_FLAG_FILTERED; if (!mPolicy->filterInputEvent(&event, policyFlags)) { if (!mPolicy.filterInputEvent(event, policyFlags)) { return; // event was consumed by the filter return; // event was consumed by the filter } } Loading Loading @@ -4362,7 +4362,7 @@ void InputDispatcher::notifyVibratorState(const NotifyVibratorStateArgs& args) { ALOGD("notifyVibratorState - eventTime=%" PRId64 ", device=%d, isOn=%d", args.eventTime, ALOGD("notifyVibratorState - eventTime=%" PRId64 ", device=%d, isOn=%d", args.eventTime, args.deviceId, args.isOn); args.deviceId, args.isOn); } } mPolicy->notifyVibratorState(args.deviceId, args.isOn); mPolicy.notifyVibratorState(args.deviceId, args.isOn); } } bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs& args) { bool InputDispatcher::shouldSendMotionToInputFilterLocked(const NotifyMotionArgs& args) { Loading @@ -4378,7 +4378,7 @@ void InputDispatcher::notifySwitch(const NotifySwitchArgs& args) { uint32_t policyFlags = args.policyFlags; uint32_t policyFlags = args.policyFlags; policyFlags |= POLICY_FLAG_TRUSTED; policyFlags |= POLICY_FLAG_TRUSTED; mPolicy->notifySwitch(args.eventTime, args.switchValues, args.switchMask, policyFlags); mPolicy.notifySwitch(args.eventTime, args.switchValues, args.switchMask, policyFlags); } } void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs& args) { void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs& args) { Loading Loading @@ -4477,7 +4477,7 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev if (!(policyFlags & POLICY_FLAG_FILTERED)) { if (!(policyFlags & POLICY_FLAG_FILTERED)) { android::base::Timer t; android::base::Timer t; mPolicy->interceptKeyBeforeQueueing(&keyEvent, /*byref*/ policyFlags); mPolicy.interceptKeyBeforeQueueing(keyEvent, /*byref*/ policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptKeyBeforeQueueing; took %s ms", ALOGW("Excessive delay in interceptKeyBeforeQueueing; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading Loading @@ -4509,7 +4509,7 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev if (!(policyFlags & POLICY_FLAG_FILTERED)) { if (!(policyFlags & POLICY_FLAG_FILTERED)) { nsecs_t eventTime = motionEvent.getEventTime(); nsecs_t eventTime = motionEvent.getEventTime(); android::base::Timer t; android::base::Timer t; mPolicy->interceptMotionBeforeQueueing(displayId, eventTime, /*byref*/ policyFlags); mPolicy.interceptMotionBeforeQueueing(displayId, eventTime, /*byref*/ policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms", ALOGW("Excessive delay in interceptMotionBeforeQueueing; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading Loading @@ -6066,7 +6066,7 @@ void InputDispatcher::sendFocusChangedCommandLocked(const sp<IBinder>& oldToken, const sp<IBinder>& newToken) { const sp<IBinder>& newToken) { auto command = [this, oldToken, newToken]() REQUIRES(mLock) { auto command = [this, oldToken, newToken]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyFocusChanged(oldToken, newToken); mPolicy.notifyFocusChanged(oldToken, newToken); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading @@ -6074,7 +6074,7 @@ void InputDispatcher::sendFocusChangedCommandLocked(const sp<IBinder>& oldToken, void InputDispatcher::sendDropWindowCommandLocked(const sp<IBinder>& token, float x, float y) { void InputDispatcher::sendDropWindowCommandLocked(const sp<IBinder>& token, float x, float y) { auto command = [this, token, x, y]() REQUIRES(mLock) { auto command = [this, token, x, y]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyDropWindow(token, x, y); mPolicy.notifyDropWindow(token, x, y); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -6121,7 +6121,7 @@ void InputDispatcher::onAnrLocked(std::shared_ptr<InputApplicationHandle> applic auto command = [this, application = std::move(application)]() REQUIRES(mLock) { auto command = [this, application = std::move(application)]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyNoFocusedWindowAnr(application); mPolicy.notifyNoFocusedWindowAnr(application); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -6161,8 +6161,7 @@ void InputDispatcher::doInterceptKeyBeforeDispatchingCommand(const sp<IBinder>& { // release lock { // release lock scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); android::base::Timer t; android::base::Timer t; delay = mPolicy->interceptKeyBeforeDispatching(focusedWindowToken, &event, delay = mPolicy.interceptKeyBeforeDispatching(focusedWindowToken, event, entry.policyFlags); entry.policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptKeyBeforeDispatching; took %s ms", ALOGW("Excessive delay in interceptKeyBeforeDispatching; took %s ms", std::to_string(t.duration().count()).c_str()); std::to_string(t.duration().count()).c_str()); Loading @@ -6184,7 +6183,7 @@ void InputDispatcher::sendWindowUnresponsiveCommandLocked(const sp<IBinder>& tok std::string reason) { std::string reason) { auto command = [this, token, pid, reason = std::move(reason)]() REQUIRES(mLock) { auto command = [this, token, pid, reason = std::move(reason)]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyWindowUnresponsive(token, pid, reason); mPolicy.notifyWindowUnresponsive(token, pid, reason); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading @@ -6193,7 +6192,7 @@ void InputDispatcher::sendWindowResponsiveCommandLocked(const sp<IBinder>& token std::optional<int32_t> pid) { std::optional<int32_t> pid) { auto command = [this, token, pid]() REQUIRES(mLock) { auto command = [this, token, pid]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->notifyWindowResponsive(token, pid); mPolicy.notifyWindowResponsive(token, pid); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -6277,8 +6276,12 @@ bool InputDispatcher::afterKeyEventLockedInterruptable( mLock.unlock(); mLock.unlock(); mPolicy->dispatchUnhandledKey(connection->inputChannel->getConnectionToken(), &event, if (const auto unhandledKeyFallback = keyEntry.policyFlags, &event); mPolicy.dispatchUnhandledKey(connection->inputChannel->getConnectionToken(), event, keyEntry.policyFlags); unhandledKeyFallback) { event = *unhandledKeyFallback; } mLock.lock(); mLock.lock(); Loading Loading @@ -6318,9 +6321,13 @@ bool InputDispatcher::afterKeyEventLockedInterruptable( mLock.unlock(); mLock.unlock(); bool fallback = bool fallback = false; mPolicy->dispatchUnhandledKey(connection->inputChannel->getConnectionToken(), if (auto fb = mPolicy.dispatchUnhandledKey(connection->inputChannel->getConnectionToken(), &event, keyEntry.policyFlags, &event); event, keyEntry.policyFlags); fb) { fallback = true; event = *fb; } mLock.lock(); mLock.lock(); Loading Loading @@ -6572,7 +6579,7 @@ void InputDispatcher::setPointerCaptureLocked(bool enable) { mCurrentPointerCaptureRequest.seq++; mCurrentPointerCaptureRequest.seq++; auto command = [this, request = mCurrentPointerCaptureRequest]() REQUIRES(mLock) { auto command = [this, request = mCurrentPointerCaptureRequest]() REQUIRES(mLock) { scoped_unlock unlock(mLock); scoped_unlock unlock(mLock); mPolicy->setPointerCapture(request); mPolicy.setPointerCapture(request); }; }; postCommandLocked(std::move(command)); postCommandLocked(std::move(command)); } } Loading Loading @@ -6665,8 +6672,7 @@ void InputDispatcher::cancelCurrentTouch() { } } void InputDispatcher::requestRefreshConfiguration() { void InputDispatcher::requestRefreshConfiguration() { InputDispatcherConfiguration config; InputDispatcherConfiguration config = mPolicy.getDispatcherConfiguration(); mPolicy->getDispatcherConfiguration(&config); std::scoped_lock _l(mLock); std::scoped_lock _l(mLock); mConfig = config; mConfig = config; Loading
services/inputflinger/dispatcher/InputDispatcher.h +3 −3 Original line number Original line Diff line number Diff line Loading @@ -82,8 +82,8 @@ class InputDispatcher : public android::InputDispatcherInterface { public: public: static constexpr bool kDefaultInTouchMode = true; static constexpr bool kDefaultInTouchMode = true; explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy); explicit InputDispatcher(InputDispatcherPolicyInterface& policy); explicit InputDispatcher(const sp<InputDispatcherPolicyInterface>& policy, explicit InputDispatcher(InputDispatcherPolicyInterface& policy, std::chrono::nanoseconds staleEventTimeout); std::chrono::nanoseconds staleEventTimeout); ~InputDispatcher() override; ~InputDispatcher() override; Loading Loading @@ -167,7 +167,7 @@ private: std::unique_ptr<InputThread> mThread; std::unique_ptr<InputThread> mThread; sp<InputDispatcherPolicyInterface> mPolicy; InputDispatcherPolicyInterface& mPolicy; android::InputDispatcherConfiguration mConfig GUARDED_BY(mLock); android::InputDispatcherConfiguration mConfig GUARDED_BY(mLock); std::mutex mLock; std::mutex mLock; Loading