diff options
| author | 2024-02-23 21:03:12 +0000 | |
|---|---|---|
| committer | 2024-02-24 00:10:43 +0000 | |
| commit | 052fb0b3f235249578ca4352d2b08e70bfbd8fe1 (patch) | |
| tree | e0db8bc2fab5449a0c51a11fa346acda93641f7a | |
| parent | 1ea04a33e42b15ed0d60963e1a385738c5b3f146 (diff) | |
InputTracer: Ensure eventProcessingComplete called after dropping events
There should be no more dispatching decisions made after notifying the
tracer that event processing is complete. However, there was a codepath
where we were previously dropping events and synthesizing cancelations
after calling eventProcessingComplete().
Move the eventProcessingComplete() call to after handling dropped
events.
Bug: 210460522
Test: atest inputflinger_tests
Change-Id: I4b61ef85f6caef345171bfd0a5a01c4367573512
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 8858f0caec..ef7b7805a0 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -103,6 +103,26 @@ void ensureEventTraced(const Entry& entry) { } } +// Helper to get a trace tracker from a traced key or motion entry. +const std::unique_ptr<trace::EventTrackerInterface>& getTraceTracker(const EventEntry& entry) { + switch (entry.type) { + case EventEntry::Type::MOTION: { + const auto& motion = static_cast<const MotionEntry&>(entry); + ensureEventTraced(motion); + return motion.traceTracker; + } + case EventEntry::Type::KEY: { + const auto& key = static_cast<const KeyEntry&>(entry); + ensureEventTraced(key); + return key.traceTracker; + } + default: { + const static std::unique_ptr<trace::EventTrackerInterface> kNullTracker; + return kNullTracker; + } + } +} + // Temporarily releases a held mutex for the lifetime of the instance. // Named to match std::scoped_lock class scoped_unlock { @@ -1147,10 +1167,6 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t& nextWakeupTime) { dropReason = DropReason::BLOCKED; } done = dispatchKeyLocked(currentTime, keyEntry, &dropReason, nextWakeupTime); - if (done && mTracer) { - ensureEventTraced(*keyEntry); - mTracer->eventProcessingComplete(*keyEntry->traceTracker); - } break; } @@ -1176,10 +1192,6 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t& nextWakeupTime) { } } done = dispatchMotionLocked(currentTime, motionEntry, &dropReason, nextWakeupTime); - if (done && mTracer) { - ensureEventTraced(*motionEntry); - mTracer->eventProcessingComplete(*motionEntry->traceTracker); - } break; } @@ -1205,6 +1217,12 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t& nextWakeupTime) { } mLastDropReason = dropReason; + if (mTracer) { + if (auto& traceTracker = getTraceTracker(*mPendingEvent); traceTracker != nullptr) { + mTracer->eventProcessingComplete(*traceTracker); + } + } + releasePendingEventLocked(); nextWakeupTime = LLONG_MIN; // force next poll to wake up immediately } |