InputTracer: Introduce TracedEventArgs to track secure events

Introduce TracedEventArgs to give the tracing backend additional
information about the traced event.

We start by tracking whether an event is secure. An event is marked as
secure if it is targeting at least one secure window.

For now, do not trace secure events in the perfetto backend.

Bug: 210460522
Test: manual with perfetto
Change-Id: I41648d769319e47486556d0a2d6b8f02142048d2
diff --git a/services/inputflinger/dispatcher/trace/InputTracer.cpp b/services/inputflinger/dispatcher/trace/InputTracer.cpp
index 4cf6a89..47e27be 100644
--- a/services/inputflinger/dispatcher/trace/InputTracer.cpp
+++ b/services/inputflinger/dispatcher/trace/InputTracer.cpp
@@ -59,9 +59,10 @@
                           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 @@
         // 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 @@
         // 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 @@
     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 @@
                                                 /*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 @@
 
 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();