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

Commit 67cf0027 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I3417aee3,I22885650 into main

* changes:
  InputTracer: Create tracker for tracing synthetic events
  InputTracer: Consolidate logic for marking event processing complete
parents 7fcacac5 d6b2b05f
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#pragma once

#include "trace/EventTrackerInterface.h"

#include <input/Input.h>
#include <bitset>
#include <optional>
@@ -51,7 +53,13 @@ struct CancelationOptions {
    // The specific pointers to cancel, or nullopt to cancel all pointer events
    std::optional<std::bitset<MAX_POINTER_ID + 1>> pointerIds = std::nullopt;

    CancelationOptions(Mode mode, const char* reason) : mode(mode), reason(reason) {}
    const std::unique_ptr<trace::EventTrackerInterface>& traceTracker;

    explicit CancelationOptions(Mode mode, const char* reason,
                                const std::unique_ptr<trace::EventTrackerInterface>& traceTracker)
          : mode(mode), reason(reason), traceTracker(traceTracker) {}
    CancelationOptions(const CancelationOptions&) = delete;
    CancelationOptions operator=(const CancelationOptions&) = delete;
};

} // namespace inputdispatcher
+103 −32

File changed.

Preview size limit exceeded, changes collapsed.

+6 −2
Original line number Diff line number Diff line
@@ -628,7 +628,8 @@ private:

    void synthesizePointerDownEventsForConnectionLocked(
            const nsecs_t downTime, const std::shared_ptr<Connection>& connection,
            ftl::Flags<InputTarget::Flags> targetFlags) REQUIRES(mLock);
            ftl::Flags<InputTarget::Flags> targetFlags,
            const std::unique_ptr<trace::EventTrackerInterface>& traceTracker) REQUIRES(mLock);

    // Splitting motion events across windows. When splitting motion event for a target,
    // splitDownTime refers to the time of first 'down' event on that particular target
@@ -657,6 +658,7 @@ private:
    void doInterceptKeyBeforeDispatchingCommand(const sp<IBinder>& focusedWindowToken,
                                                const KeyEntry& entry) REQUIRES(mLock);
    void onFocusChangedLocked(const FocusResolver::FocusChanges& changes,
                              const std::unique_ptr<trace::EventTrackerInterface>& traceTracker,
                              const sp<gui::WindowInfoHandle> removedFocusedWindowHandle = nullptr)
            REQUIRES(mLock);
    void sendFocusChangedCommandLocked(const sp<IBinder>& oldToken, const sp<IBinder>& newToken)
@@ -704,7 +706,9 @@ private:
                                const sp<android::gui::WindowInfoHandle> fromWindowHandle,
                                const sp<android::gui::WindowInfoHandle> toWindowHandle,
                                TouchState& state, int32_t deviceId,
                                const std::vector<PointerProperties>& pointers) REQUIRES(mLock);
                                const std::vector<PointerProperties>& pointers,
                                const std::unique_ptr<trace::EventTrackerInterface>& traceTracker)
            REQUIRES(mLock);

    sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow(
            const sp<android::gui::WindowInfoHandle>& windowHandle) const REQUIRES(mLock);
+32 −15
Original line number Diff line number Diff line
@@ -65,6 +65,10 @@ void writeEventToBackend(const TracedEvent& event, InputTracingBackendInterface&
               event);
}

inline auto getId(const trace::TracedEvent& v) {
    return std::visit([](const auto& event) { return event.id; }, v);
}

} // namespace

// --- InputTracer ---
@@ -89,6 +93,12 @@ std::unique_ptr<EventTrackerInterface> InputTracer::traceInboundEvent(const Even
    return std::make_unique<EventTrackerImpl>(std::move(eventState), /*isDerived=*/false);
}

std::unique_ptr<EventTrackerInterface> InputTracer::createTrackerForSyntheticEvent() {
    // Create a new EventState to track events derived from this tracker.
    return std::make_unique<EventTrackerImpl>(std::make_shared<EventState>(*this),
                                              /*isDerived=*/false);
}

void InputTracer::dispatchToTargetHint(const EventTrackerInterface& cookie,
                                       const InputTarget& target) {
    if (isDerivedCookie(cookie)) {
@@ -111,11 +121,7 @@ void InputTracer::eventProcessingComplete(const EventTrackerInterface& cookie) {
        LOG(FATAL) << "Traced event was already logged. "
                      "eventProcessingComplete() was likely called more than once.";
    }

    for (const auto& event : eventState->events) {
        writeEventToBackend(event, *mBackend);
    }
    eventState->isEventProcessingComplete = true;
    eventState->onEventProcessingComplete();
}

std::unique_ptr<EventTrackerInterface> InputTracer::traceDerivedEvent(
@@ -144,7 +150,8 @@ std::unique_ptr<EventTrackerInterface> InputTracer::traceDerivedEvent(
}

void InputTracer::traceEventDispatch(const DispatchEntry& dispatchEntry,
                                     const EventTrackerInterface* cookie) {
                                     const EventTrackerInterface& cookie) {
    auto& eventState = getState(cookie);
    const EventEntry& entry = *dispatchEntry.eventEntry;
    // TODO(b/328618922): Remove resolved key repeats after making repeatCount non-mutable.
    // The KeyEntry's repeatCount is mutable and can be modified after an event is initially traced,
@@ -163,9 +170,13 @@ void InputTracer::traceEventDispatch(const DispatchEntry& dispatchEntry,
        LOG(FATAL) << "Cannot trace EventEntry of type: " << ftl::enum_string(entry.type);
    }

    if (!cookie) {
        // This event was not tracked as an inbound event, so trace it now.
        writeEventToBackend(traced, *mBackend);
    auto tracedEventIt =
            std::find_if(eventState->events.begin(), eventState->events.end(),
                         [&traced](const auto& event) { return getId(traced) == getId(event); });
    if (tracedEventIt == eventState->events.end()) {
        LOG(FATAL)
                << __func__
                << ": Failed to find a previously traced event that matches the dispatched event";
    }

    // The vsyncId only has meaning if the event is targeting a window.
@@ -189,18 +200,24 @@ bool InputTracer::isDerivedCookie(const EventTrackerInterface& cookie) {

// --- InputTracer::EventState ---

void InputTracer::EventState::onEventProcessingComplete() {
    // Write all of the events known so far to the trace.
    for (const auto& event : events) {
        writeEventToBackend(event, *tracer.mBackend);
    }
    isEventProcessingComplete = true;
}

InputTracer::EventState::~EventState() {
    if (isEventProcessingComplete) {
        // This event has already been written to the trace as expected.
        return;
    }
    // The event processing was never marked as complete, so do it now.
    // TODO(b/210460522): Determine why/where the event is being destroyed before
    //   eventProcessingComplete() is called.
    for (const auto& event : events) {
        writeEventToBackend(event, *tracer.mBackend);
    }
    isEventProcessingComplete = true;
    // We should never end up here in normal operation. However, in tests, it's possible that we
    // stop and destroy InputDispatcher without waiting for it to finish processing events, at
    // which point an event (and thus its EventState) may be destroyed before processing finishes.
    onEventProcessingComplete();
}

} // namespace android::inputdispatcher::trace::impl
+4 −1

File changed.

Preview size limit exceeded, changes collapsed.

Loading