diff options
author | Corinna Vinschen <xda@vinschen.de> | 2017-08-12 21:22:57 +0200 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2020-12-12 02:28:19 +0200 |
commit | c7ad867eac45199f14c9a7c929c1c571ea335ca1 (patch) | |
tree | 0ca64d9bd869551a929ad4f864b5cd9ccef852a8 | |
parent | b4b82059383bbb7980b4a50cdf036e2d53b7d398 (diff) |
InputDispatcher: On keypress, deliver keycode to pokeUserActivity
Change-Id: I8f64a6fa9b4b2e4520e25731f55e89f5087c70da
Signed-off-by: Corinna Vinschen <xda@vinschen.de>
3 files changed, 34 insertions, 16 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index fe016af01f..dd0082c09e 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -591,7 +591,7 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) { // Poke user activity for this event. if (mPendingEvent->policyFlags & POLICY_FLAG_PASS_TO_USER) { - pokeUserActivityLocked(*mPendingEvent); + pokeUserActivityLocked(mPendingEvent); } } @@ -1344,7 +1344,7 @@ void InputDispatcher::dispatchEventLocked(nsecs_t currentTime, EventEntry* event ALOG_ASSERT(eventEntry->dispatchInProgress); // should already have been set to true - pokeUserActivityLocked(*eventEntry); + pokeUserActivityLocked(eventEntry); for (const InputTarget& inputTarget : inputTargets) { sp<Connection> connection = @@ -2151,12 +2151,12 @@ std::string InputDispatcher::getApplicationWindowLabel( } } -void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) { - if (eventEntry.type == EventEntry::Type::FOCUS) { +void InputDispatcher::pokeUserActivityLocked(const EventEntry* eventEntry) { + if (eventEntry->type == EventEntry::Type::FOCUS) { // Focus events are passed to apps, but do not represent user activity. return; } - int32_t displayId = getTargetDisplayId(eventEntry); + int32_t displayId = getTargetDisplayId(*eventEntry); sp<InputWindowHandle> focusedWindowHandle = getValueByKey(mFocusedWindowHandlesByDisplay, displayId); if (focusedWindowHandle != nullptr) { @@ -2170,21 +2170,21 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) { } int32_t eventType = USER_ACTIVITY_EVENT_OTHER; - switch (eventEntry.type) { + switch (eventEntry->type) { case EventEntry::Type::MOTION: { - const MotionEntry& motionEntry = static_cast<const MotionEntry&>(eventEntry); - if (motionEntry.action == AMOTION_EVENT_ACTION_CANCEL) { + const MotionEntry* motionEntry = static_cast<const MotionEntry*>(eventEntry); + if (motionEntry->action == AMOTION_EVENT_ACTION_CANCEL) { return; } - if (MotionEvent::isTouchEvent(motionEntry.source, motionEntry.action)) { + if (MotionEvent::isTouchEvent(motionEntry->source, motionEntry->action)) { eventType = USER_ACTIVITY_EVENT_TOUCH; } break; } case EventEntry::Type::KEY: { - const KeyEntry& keyEntry = static_cast<const KeyEntry&>(eventEntry); - if (keyEntry.flags & AKEY_EVENT_FLAG_CANCELED) { + const KeyEntry* keyEntry = static_cast<const KeyEntry*>(eventEntry); + if (keyEntry->flags & AKEY_EVENT_FLAG_CANCELED) { return; } eventType = USER_ACTIVITY_EVENT_BUTTON; @@ -2194,15 +2194,20 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) { case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: { LOG_ALWAYS_FATAL("%s events are not user activity", - EventEntry::typeToString(eventEntry.type)); + EventEntry::typeToString(eventEntry->type)); break; } } std::unique_ptr<CommandEntry> commandEntry = std::make_unique<CommandEntry>(&InputDispatcher::doPokeUserActivityLockedInterruptible); - commandEntry->eventTime = eventEntry.eventTime; + commandEntry->eventTime = eventEntry->eventTime; commandEntry->userActivityEventType = eventType; + if (eventType == USER_ACTIVITY_EVENT_BUTTON) { + const KeyEntry* keyEntry = static_cast<const KeyEntry*>(eventEntry); + commandEntry->keyEntry = const_cast<KeyEntry*>(keyEntry); + keyEntry->refCount += 1; + } postCommandLocked(std::move(commandEntry)); } @@ -4992,7 +4997,20 @@ bool InputDispatcher::afterMotionEventLockedInterruptible(const sp<Connection>& void InputDispatcher::doPokeUserActivityLockedInterruptible(CommandEntry* commandEntry) { mLock.unlock(); - mPolicy->pokeUserActivity(commandEntry->eventTime, commandEntry->userActivityEventType); + int32_t keyCode = AKEYCODE_UNKNOWN; + + if (commandEntry->userActivityEventType == USER_ACTIVITY_EVENT_BUTTON && + commandEntry->keyEntry) { + keyCode = commandEntry->keyEntry->keyCode; + } + + mPolicy->pokeUserActivity(commandEntry->eventTime, commandEntry->userActivityEventType, + keyCode); + + if (commandEntry->userActivityEventType == USER_ACTIVITY_EVENT_BUTTON && + commandEntry->keyEntry) { + commandEntry->keyEntry->release(); + } mLock.lock(); } diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index e679c6b06f..9b47b40933 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -411,7 +411,7 @@ private: void addGlobalMonitoringTargetsLocked(std::vector<InputTarget>& inputTargets, int32_t displayId, float xOffset = 0, float yOffset = 0) REQUIRES(mLock); - void pokeUserActivityLocked(const EventEntry& eventEntry) REQUIRES(mLock); + void pokeUserActivityLocked(const EventEntry* eventEntry) REQUIRES(mLock); bool checkInjectionPermission(const sp<InputWindowHandle>& windowHandle, const InjectionState* injectionState); bool isWindowObscuredAtPointLocked(const sp<InputWindowHandle>& windowHandle, int32_t x, diff --git a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h index 667af9bbd8..4cb083d4f3 100644 --- a/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h +++ b/services/inputflinger/dispatcher/include/InputDispatcherPolicyInterface.h @@ -99,7 +99,7 @@ public: uint32_t policyFlags) = 0; /* Poke user activity for an event dispatched to a window. */ - virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType) = 0; + virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType, int32_t keyCode) = 0; /* Checks whether a given application pid/uid has permission to inject input events * into other applications. |