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

Commit d8b0cc3f authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge changes I9fe98448,I41648d76 into main

* changes:
  InputTracer: Don't make WindowDispatchArgs an inner class
  InputTracer: Introduce TracedEventArgs to track secure events
parents 000cb1b9 4b408beb
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -72,8 +72,7 @@ void AndroidInputEventProtoConverter::toProtoKeyEvent(const TracedKeyEvent& even
}

void AndroidInputEventProtoConverter::toProtoWindowDispatchEvent(
        const InputTracingBackendInterface::WindowDispatchArgs& args,
        proto::AndroidWindowInputDispatchEvent& outProto) {
        const WindowDispatchArgs& args, proto::AndroidWindowInputDispatchEvent& outProto) {
    std::visit([&](auto entry) { outProto.set_event_id(entry.id); }, args.eventEntry);
    outProto.set_vsync_id(args.vsyncId);
    outProto.set_window_id(args.windowId);
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ public:
    static void toProtoMotionEvent(const TracedMotionEvent& event,
                                   proto::AndroidMotionEvent& outProto);
    static void toProtoKeyEvent(const TracedKeyEvent& event, proto::AndroidKeyEvent& outProto);
    static void toProtoWindowDispatchEvent(const InputTracingBackendInterface::WindowDispatchArgs&,
    static void toProtoWindowDispatchEvent(const WindowDispatchArgs&,
                                           proto::AndroidWindowInputDispatchEvent& outProto);
};

+17 −8
Original line number Diff line number Diff line
@@ -59,9 +59,10 @@ TracedEvent createTracedEvent(const KeyEntry& e) {
                          e.downTime,  e.flags,     e.repeatCount};
}

void writeEventToBackend(const TracedEvent& event, InputTracingBackendInterface& backend) {
    std::visit(Visitor{[&](const TracedMotionEvent& e) { backend.traceMotionEvent(e); },
                       [&](const TracedKeyEvent& e) { backend.traceKeyEvent(e); }},
void writeEventToBackend(const TracedEvent& event, const TracedEventArgs args,
                         InputTracingBackendInterface& backend) {
    std::visit(Visitor{[&](const TracedMotionEvent& e) { backend.traceMotionEvent(e, args); },
                       [&](const TracedKeyEvent& e) { backend.traceKeyEvent(e, args); }},
               event);
}

@@ -110,7 +111,11 @@ void InputTracer::dispatchToTargetHint(const EventTrackerInterface& cookie,
        // TODO(b/210460522): Disallow adding new targets from a derived cookie.
        return;
    }
    // TODO(b/210460522): Determine if the event is sensitive based on the target.
    if (target.windowHandle != nullptr) {
        eventState->isSecure |= target.windowHandle->getInfo()->layoutParamsFlags.test(
                gui::WindowInfo::Flag::SECURE);
        // TODO(b/210460522): Set events as sensitive when the IME connection is active.
    }
}

void InputTracer::eventProcessingComplete(const EventTrackerInterface& cookie) {
@@ -145,7 +150,8 @@ std::unique_ptr<EventTrackerInterface> InputTracer::traceDerivedEvent(
        // It is possible for a derived event to be dispatched some time after the original event
        // 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.
        writeEventToBackend(eventState->events.back(), *mBackend);
        const TracedEventArgs traceArgs{.isSecure = eventState->isSecure};
        writeEventToBackend(eventState->events.back(), traceArgs, *mBackend);
    }
    return std::make_unique<EventTrackerImpl>(std::move(eventState), /*isDerived=*/true);
}
@@ -184,6 +190,7 @@ 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;

    // TODO(b/210460522): Pass HMAC into traceEventDispatch.
    const WindowDispatchArgs windowDispatchArgs{std::move(traced),
                                                dispatchEntry.deliveryTime,
                                                dispatchEntry.resolvedFlags,
@@ -195,7 +202,8 @@ void InputTracer::traceEventDispatch(const DispatchEntry& dispatchEntry,
                                                /*hmac=*/{},
                                                resolvedKeyRepeatCount};
    if (eventState->isEventProcessingComplete) {
        mBackend->traceWindowDispatch(std::move(windowDispatchArgs));
        mBackend->traceWindowDispatch(std::move(windowDispatchArgs),
                                      TracedEventArgs{.isSecure = eventState->isSecure});
    } else {
        eventState->pendingDispatchArgs.emplace_back(std::move(windowDispatchArgs));
    }
@@ -214,12 +222,13 @@ bool InputTracer::isDerivedCookie(const EventTrackerInterface& cookie) {

void InputTracer::EventState::onEventProcessingComplete() {
    // Write all of the events known so far to the trace.
    const TracedEventArgs traceArgs{.isSecure = isSecure};
    for (const auto& event : events) {
        writeEventToBackend(event, *tracer.mBackend);
        writeEventToBackend(event, traceArgs, *tracer.mBackend);
    }
    // Write all pending dispatch args to the trace.
    for (const auto& windowDispatchArgs : pendingDispatchArgs) {
        tracer.mBackend->traceWindowDispatch(windowDispatchArgs);
        tracer.mBackend->traceWindowDispatch(windowDispatchArgs, traceArgs);
    }
    pendingDispatchArgs.clear();

+2 −4
Original line number Diff line number Diff line
@@ -52,8 +52,6 @@ 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){};
@@ -66,8 +64,8 @@ private:
        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.
        // True if the event is targeting at least one secure window;
        bool isSecure{false};
    };

    // Get the event state associated with a tracking cookie.
+23 −15
Original line number Diff line number Diff line
@@ -74,20 +74,13 @@ struct TracedMotionEvent {
/** A representation of a traced input event. */
using TracedEvent = std::variant<TracedKeyEvent, TracedMotionEvent>;

/**
 * An interface for the tracing backend, used for setting a custom backend for testing.
 */
class InputTracingBackendInterface {
public:
    virtual ~InputTracingBackendInterface() = default;

    /** Trace a KeyEvent. */
    virtual void traceKeyEvent(const TracedKeyEvent&) = 0;

    /** Trace a MotionEvent. */
    virtual void traceMotionEvent(const TracedMotionEvent&) = 0;
/** Additional information about an input event being traced. */
struct TracedEventArgs {
    // True if the event is targeting at least one secure window.
    bool isSecure;
};

    /** Trace an event being sent to a window. */
/** Additional information about an input event being dispatched to a window. */
struct WindowDispatchArgs {
    TracedEvent eventEntry;
    nsecs_t deliveryTime;
@@ -100,7 +93,22 @@ public:
    std::array<uint8_t, 32> hmac;
    int32_t resolvedKeyRepeatCount;
};
    virtual void traceWindowDispatch(const WindowDispatchArgs&) = 0;

/**
 * An interface for the tracing backend, used for setting a custom backend for testing.
 */
class InputTracingBackendInterface {
public:
    virtual ~InputTracingBackendInterface() = default;

    /** Trace a KeyEvent. */
    virtual void traceKeyEvent(const TracedKeyEvent&, const TracedEventArgs&) = 0;

    /** Trace a MotionEvent. */
    virtual void traceMotionEvent(const TracedMotionEvent&, const TracedEventArgs&) = 0;

    /** Trace an event being sent to a window. */
    virtual void traceWindowDispatch(const WindowDispatchArgs&, const TracedEventArgs&) = 0;
};

} // namespace android::inputdispatcher::trace
Loading