diff options
| author | 2024-03-25 23:29:00 +0000 | |
|---|---|---|
| committer | 2024-03-25 23:29:00 +0000 | |
| commit | 257374e8c66974240924eba960ee49a8190d763c (patch) | |
| tree | aa5e385c25e2594061fa053278d02ed53cfb0c73 | |
| parent | 3f74bbfe4fc06be2f8da732646f748aee10ef73c (diff) | |
| parent | ac63702623f28862b8bec2c5c3fb800568cd207f (diff) | |
Merge "InputTracer: Store Metadata directly in EventState" into main
| -rw-r--r-- | services/inputflinger/dispatcher/trace/InputTracer.cpp | 40 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/trace/InputTracer.h | 7 |
2 files changed, 12 insertions, 35 deletions
diff --git a/services/inputflinger/dispatcher/trace/InputTracer.cpp b/services/inputflinger/dispatcher/trace/InputTracer.cpp index 32fa740565..1d4d11c13a 100644 --- a/services/inputflinger/dispatcher/trace/InputTracer.cpp +++ b/services/inputflinger/dispatcher/trace/InputTracer.cpp @@ -126,21 +126,21 @@ void InputTracer::dispatchToTargetHint(const EventTrackerInterface& cookie, const InputTargetInfo& targetInfo = getTargetInfo(target); if (eventState->isEventProcessingComplete) { // Disallow adding new targets after eventProcessingComplete() is called. - if (eventState->targets.find(targetInfo.uid) == eventState->targets.end()) { + if (eventState->metadata.targets.count(targetInfo.uid) == 0) { LOG(FATAL) << __func__ << ": Cannot add new target after eventProcessingComplete"; } return; } if (isDerivedCookie(cookie)) { // Disallow adding new targets from a derived cookie. - if (eventState->targets.find(targetInfo.uid) == eventState->targets.end()) { + if (eventState->metadata.targets.count(targetInfo.uid) == 0) { LOG(FATAL) << __func__ << ": Cannot add new target from a derived cookie"; } return; } - eventState->targets.emplace(targetInfo.uid); - eventState->isSecure |= targetInfo.isSecureWindow; + eventState->metadata.targets.emplace(targetInfo.uid); + eventState->metadata.isSecure |= targetInfo.isSecureWindow; } void InputTracer::eventProcessingComplete(const EventTrackerInterface& cookie) { @@ -176,12 +176,7 @@ std::unique_ptr<EventTrackerInterface> InputTracer::traceDerivedEvent( // is dispatched, such as in the case of key fallback events. To account for these cases, // derived events can be traced after the processing is complete for the original event. const auto& event = eventState->events.back(); - const TracedEventMetadata metadata{ - .isSecure = eventState->isSecure, - .targets = eventState->targets, - .isImeConnectionActive = eventState->isImeConnectionActive, - }; - writeEventToBackend(event, std::move(metadata), *mBackend); + writeEventToBackend(event, eventState->metadata, *mBackend); } return std::make_unique<EventTrackerImpl>(std::move(eventState), /*isDerived=*/true); } @@ -208,7 +203,7 @@ void InputTracer::traceEventDispatch(const DispatchEntry& dispatchEntry, << ": Failed to find a previously traced event that matches the dispatched event"; } - if (eventState->targets.count(dispatchEntry.targetUid) == 0) { + if (eventState->metadata.targets.count(dispatchEntry.targetUid) == 0) { LOG(FATAL) << __func__ << ": Event is being dispatched to UID that it is not targeting"; } @@ -228,12 +223,7 @@ void InputTracer::traceEventDispatch(const DispatchEntry& dispatchEntry, /*hmac=*/{}, resolvedKeyRepeatCount}; if (eventState->isEventProcessingComplete) { - const TracedEventMetadata metadata{ - .isSecure = eventState->isSecure, - .targets = eventState->targets, - .isImeConnectionActive = eventState->isImeConnectionActive, - }; - mBackend->traceWindowDispatch(std::move(windowDispatchArgs), std::move(metadata)); + mBackend->traceWindowDispatch(std::move(windowDispatchArgs), eventState->metadata); } else { eventState->pendingDispatchArgs.emplace_back(std::move(windowDispatchArgs)); } @@ -251,16 +241,11 @@ bool InputTracer::isDerivedCookie(const EventTrackerInterface& cookie) { // --- InputTracer::EventState --- void InputTracer::EventState::onEventProcessingComplete() { - isImeConnectionActive = tracer.mIsImeConnectionActive; + metadata.isImeConnectionActive = tracer.mIsImeConnectionActive; // Write all of the events known so far to the trace. for (const auto& event : events) { - const TracedEventMetadata metadata{ - .isSecure = isSecure, - .targets = targets, - .isImeConnectionActive = isImeConnectionActive, - }; - writeEventToBackend(event, std::move(metadata), *tracer.mBackend); + writeEventToBackend(event, metadata, *tracer.mBackend); } // Write all pending dispatch args to the trace. for (const auto& windowDispatchArgs : pendingDispatchArgs) { @@ -274,12 +259,7 @@ void InputTracer::EventState::onEventProcessingComplete() { << ": Failed to find a previously traced event that matches the dispatched " "event"; } - const TracedEventMetadata metadata{ - .isSecure = isSecure, - .targets = targets, - .isImeConnectionActive = isImeConnectionActive, - }; - tracer.mBackend->traceWindowDispatch(windowDispatchArgs, std::move(metadata)); + tracer.mBackend->traceWindowDispatch(windowDispatchArgs, metadata); } pendingDispatchArgs.clear(); diff --git a/services/inputflinger/dispatcher/trace/InputTracer.h b/services/inputflinger/dispatcher/trace/InputTracer.h index dfaf7c3146..ab175bef4a 100644 --- a/services/inputflinger/dispatcher/trace/InputTracer.h +++ b/services/inputflinger/dispatcher/trace/InputTracer.h @@ -68,11 +68,8 @@ private: bool isEventProcessingComplete{false}; // A queue to hold dispatch args from being traced until event processing is complete. std::vector<const WindowDispatchArgs> pendingDispatchArgs; - // True if the event is targeting at least one secure window; - bool isSecure{false}; - // The list of all possible UIDs that this event could be targeting. - std::set<gui::Uid> targets; - bool isImeConnectionActive{false}; + // The metadata should not be modified after event processing is complete. + TracedEventMetadata metadata{}; }; // Get the event state associated with a tracking cookie. |