Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52ec3ff3 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputTracer: Wait to trace dispatch events to the backend

... until event processing is complete. This is because we need to wait
until processing complete to get information about the targets and
sensitivity of an event, which is required to write the dispatch event
to the backend.

Bug: 210460522
Test: atest inputflinger_tests
Change-Id: I227c207d6a5667f9297e74b4c8be9f8e980d6d13
parent d6b2b05f
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -183,10 +183,21 @@ void InputTracer::traceEventDispatch(const DispatchEntry& dispatchEntry,
    const int32_t windowId = dispatchEntry.windowId.value_or(0);
    const int32_t vsyncId = dispatchEntry.windowId.has_value() ? dispatchEntry.vsyncId : 0;

    mBackend->traceWindowDispatch({std::move(traced), dispatchEntry.deliveryTime,
                                   dispatchEntry.resolvedFlags, dispatchEntry.targetUid, vsyncId,
                                   windowId, dispatchEntry.transform, dispatchEntry.rawTransform,
                                   /*hmac=*/{}, resolvedKeyRepeatCount});
    const WindowDispatchArgs windowDispatchArgs{std::move(traced),
                                                dispatchEntry.deliveryTime,
                                                dispatchEntry.resolvedFlags,
                                                dispatchEntry.targetUid,
                                                vsyncId,
                                                windowId,
                                                dispatchEntry.transform,
                                                dispatchEntry.rawTransform,
                                                /*hmac=*/{},
                                                resolvedKeyRepeatCount};
    if (eventState->isEventProcessingComplete) {
        mBackend->traceWindowDispatch(std::move(windowDispatchArgs));
    } else {
        eventState->pendingDispatchArgs.emplace_back(std::move(windowDispatchArgs));
    }
}

std::shared_ptr<InputTracer::EventState>& InputTracer::getState(
@@ -205,6 +216,12 @@ void InputTracer::EventState::onEventProcessingComplete() {
    for (const auto& event : events) {
        writeEventToBackend(event, *tracer.mBackend);
    }
    // Write all pending dispatch args to the trace.
    for (const auto& windowDispatchArgs : pendingDispatchArgs) {
        tracer.mBackend->traceWindowDispatch(windowDispatchArgs);
    }
    pendingDispatchArgs.clear();

    isEventProcessingComplete = true;
}

+4 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ public:
private:
    std::unique_ptr<InputTracingBackendInterface> mBackend;

    using WindowDispatchArgs = InputTracingBackendInterface::WindowDispatchArgs;

    // The state of a tracked event, shared across all events derived from the original event.
    struct EventState {
        explicit inline EventState(InputTracer& tracer) : tracer(tracer){};
@@ -62,6 +64,8 @@ private:
        InputTracer& tracer;
        std::vector<const TracedEvent> events;
        bool isEventProcessingComplete{false};
        // A queue to hold dispatch args from being traced until event processing is complete.
        std::vector<const WindowDispatchArgs> pendingDispatchArgs;
        // TODO(b/210460522): Add additional args for tracking event sensitivity and
        //  dispatch target UIDs.
    };