Loading services/inputflinger/dispatcher/InputDispatcher.cpp +11 −7 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ #include <ctime> #include <queue> #include <sstream> #include <variant> #include "../InputDeviceMetricsSource.h" Loading Loading @@ -6651,24 +6652,27 @@ void InputDispatcher::updateLastAnrStateLocked(const std::string& windowLabel, void InputDispatcher::doInterceptKeyBeforeDispatchingCommand(const sp<IBinder>& focusedWindowToken, const KeyEntry& entry) { const KeyEvent event = createKeyEvent(entry); std::variant<nsecs_t, KeyEntry::InterceptKeyResult> interceptResult; nsecs_t delay = 0; { // release lock scoped_unlock unlock(mLock); android::base::Timer t; delay = mPolicy.interceptKeyBeforeDispatching(focusedWindowToken, event, entry.policyFlags); interceptResult = mPolicy.interceptKeyBeforeDispatching(focusedWindowToken, event, entry.policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptKeyBeforeDispatching; took %s ms", std::to_string(t.duration().count()).c_str()); } } // acquire lock if (delay < 0) { entry.interceptKeyResult = KeyEntry::InterceptKeyResult::SKIP; } else if (delay == 0) { entry.interceptKeyResult = KeyEntry::InterceptKeyResult::CONTINUE; } else { if (std::holds_alternative<KeyEntry::InterceptKeyResult>(interceptResult)) { entry.interceptKeyResult = std::get<KeyEntry::InterceptKeyResult>(interceptResult); return; } if (std::holds_alternative<nsecs_t>(interceptResult)) { entry.interceptKeyResult = KeyEntry::InterceptKeyResult::TRY_AGAIN_LATER; entry.interceptKeyWakeupTime = now() + delay; entry.interceptKeyWakeupTime = now() + std::get<nsecs_t>(interceptResult); } } Loading services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h +5 −3 Original line number Diff line number Diff line Loading @@ -20,12 +20,14 @@ #include <android-base/properties.h> #include <binder/IBinder.h> #include <dispatcher/Entry.h> #include <gui/InputApplication.h> #include <gui/PidUid.h> #include <input/Input.h> #include <input/InputDevice.h> #include <utils/RefBase.h> #include <set> #include <variant> namespace android { Loading Loading @@ -106,8 +108,8 @@ public: uint32_t& policyFlags) = 0; /* Allows the policy a chance to intercept a key before dispatching. */ virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token, const KeyEvent& keyEvent, virtual std::variant<nsecs_t, inputdispatcher::KeyEntry::InterceptKeyResult> interceptKeyBeforeDispatching(const sp<IBinder>& token, const KeyEvent& keyEvent, uint32_t policyFlags) = 0; /* Allows the policy a chance to perform default processing for an unhandled key. Loading services/inputflinger/tests/FakeInputDispatcherPolicy.cpp +11 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include "FakeInputDispatcherPolicy.h" #include <variant> #include <gtest/gtest.h> namespace android { Loading Loading @@ -409,12 +411,18 @@ void FakeInputDispatcherPolicy::interceptKeyBeforeQueueing(const KeyEvent& input void FakeInputDispatcherPolicy::interceptMotionBeforeQueueing(ui::LogicalDisplayId, uint32_t, int32_t, nsecs_t, uint32_t&) {} nsecs_t FakeInputDispatcherPolicy::interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) { std::variant<nsecs_t, inputdispatcher::KeyEntry::InterceptKeyResult> FakeInputDispatcherPolicy::interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) { if (mConsumeKeyBeforeDispatching) { return -1; return inputdispatcher::KeyEntry::InterceptKeyResult::SKIP; } nsecs_t delay = std::chrono::nanoseconds(mInterceptKeyTimeout).count(); if (delay == 0) { return inputdispatcher::KeyEntry::InterceptKeyResult::CONTINUE; } // Clear intercept state so we could dispatch the event in next wake. mInterceptKeyTimeout = 0ms; return delay; Loading services/inputflinger/tests/FakeInputDispatcherPolicy.h +4 −1 Original line number Diff line number Diff line Loading @@ -28,11 +28,13 @@ #include <optional> #include <queue> #include <string> #include <variant> #include <vector> #include <android-base/logging.h> #include <android-base/thread_annotations.h> #include <binder/IBinder.h> #include <dispatcher/Entry.h> #include <gui/PidUid.h> #include <gui/WindowInfo.h> #include <input/BlockingQueue.h> Loading Loading @@ -189,7 +191,8 @@ private: void interceptKeyBeforeQueueing(const KeyEvent& inputEvent, uint32_t&) override; void interceptMotionBeforeQueueing(ui::LogicalDisplayId, uint32_t, int32_t, nsecs_t, uint32_t&) override; nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) override; std::variant<nsecs_t, inputdispatcher::KeyEntry::InterceptKeyResult> interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) override; std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent& event, uint32_t) override; void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, Loading Loading
services/inputflinger/dispatcher/InputDispatcher.cpp +11 −7 Original line number Diff line number Diff line Loading @@ -46,6 +46,7 @@ #include <ctime> #include <queue> #include <sstream> #include <variant> #include "../InputDeviceMetricsSource.h" Loading Loading @@ -6651,24 +6652,27 @@ void InputDispatcher::updateLastAnrStateLocked(const std::string& windowLabel, void InputDispatcher::doInterceptKeyBeforeDispatchingCommand(const sp<IBinder>& focusedWindowToken, const KeyEntry& entry) { const KeyEvent event = createKeyEvent(entry); std::variant<nsecs_t, KeyEntry::InterceptKeyResult> interceptResult; nsecs_t delay = 0; { // release lock scoped_unlock unlock(mLock); android::base::Timer t; delay = mPolicy.interceptKeyBeforeDispatching(focusedWindowToken, event, entry.policyFlags); interceptResult = mPolicy.interceptKeyBeforeDispatching(focusedWindowToken, event, entry.policyFlags); if (t.duration() > SLOW_INTERCEPTION_THRESHOLD) { ALOGW("Excessive delay in interceptKeyBeforeDispatching; took %s ms", std::to_string(t.duration().count()).c_str()); } } // acquire lock if (delay < 0) { entry.interceptKeyResult = KeyEntry::InterceptKeyResult::SKIP; } else if (delay == 0) { entry.interceptKeyResult = KeyEntry::InterceptKeyResult::CONTINUE; } else { if (std::holds_alternative<KeyEntry::InterceptKeyResult>(interceptResult)) { entry.interceptKeyResult = std::get<KeyEntry::InterceptKeyResult>(interceptResult); return; } if (std::holds_alternative<nsecs_t>(interceptResult)) { entry.interceptKeyResult = KeyEntry::InterceptKeyResult::TRY_AGAIN_LATER; entry.interceptKeyWakeupTime = now() + delay; entry.interceptKeyWakeupTime = now() + std::get<nsecs_t>(interceptResult); } } Loading
services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h +5 −3 Original line number Diff line number Diff line Loading @@ -20,12 +20,14 @@ #include <android-base/properties.h> #include <binder/IBinder.h> #include <dispatcher/Entry.h> #include <gui/InputApplication.h> #include <gui/PidUid.h> #include <input/Input.h> #include <input/InputDevice.h> #include <utils/RefBase.h> #include <set> #include <variant> namespace android { Loading Loading @@ -106,8 +108,8 @@ public: uint32_t& policyFlags) = 0; /* Allows the policy a chance to intercept a key before dispatching. */ virtual nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>& token, const KeyEvent& keyEvent, virtual std::variant<nsecs_t, inputdispatcher::KeyEntry::InterceptKeyResult> interceptKeyBeforeDispatching(const sp<IBinder>& token, const KeyEvent& keyEvent, uint32_t policyFlags) = 0; /* Allows the policy a chance to perform default processing for an unhandled key. Loading
services/inputflinger/tests/FakeInputDispatcherPolicy.cpp +11 −3 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ #include "FakeInputDispatcherPolicy.h" #include <variant> #include <gtest/gtest.h> namespace android { Loading Loading @@ -409,12 +411,18 @@ void FakeInputDispatcherPolicy::interceptKeyBeforeQueueing(const KeyEvent& input void FakeInputDispatcherPolicy::interceptMotionBeforeQueueing(ui::LogicalDisplayId, uint32_t, int32_t, nsecs_t, uint32_t&) {} nsecs_t FakeInputDispatcherPolicy::interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) { std::variant<nsecs_t, inputdispatcher::KeyEntry::InterceptKeyResult> FakeInputDispatcherPolicy::interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) { if (mConsumeKeyBeforeDispatching) { return -1; return inputdispatcher::KeyEntry::InterceptKeyResult::SKIP; } nsecs_t delay = std::chrono::nanoseconds(mInterceptKeyTimeout).count(); if (delay == 0) { return inputdispatcher::KeyEntry::InterceptKeyResult::CONTINUE; } // Clear intercept state so we could dispatch the event in next wake. mInterceptKeyTimeout = 0ms; return delay; Loading
services/inputflinger/tests/FakeInputDispatcherPolicy.h +4 −1 Original line number Diff line number Diff line Loading @@ -28,11 +28,13 @@ #include <optional> #include <queue> #include <string> #include <variant> #include <vector> #include <android-base/logging.h> #include <android-base/thread_annotations.h> #include <binder/IBinder.h> #include <dispatcher/Entry.h> #include <gui/PidUid.h> #include <gui/WindowInfo.h> #include <input/BlockingQueue.h> Loading Loading @@ -189,7 +191,8 @@ private: void interceptKeyBeforeQueueing(const KeyEvent& inputEvent, uint32_t&) override; void interceptMotionBeforeQueueing(ui::LogicalDisplayId, uint32_t, int32_t, nsecs_t, uint32_t&) override; nsecs_t interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) override; std::variant<nsecs_t, inputdispatcher::KeyEntry::InterceptKeyResult> interceptKeyBeforeDispatching(const sp<IBinder>&, const KeyEvent&, uint32_t) override; std::optional<KeyEvent> dispatchUnhandledKey(const sp<IBinder>&, const KeyEvent& event, uint32_t) override; void notifySwitch(nsecs_t when, uint32_t switchValues, uint32_t switchMask, Loading