InputTracer: Trace events derived from other events separately

InputDispatcher goes through multiple "phases" when dispatching
new event, roughly corresponding to the following:

1. Inbound event processing (e.g. InputFilter, policy filtering,
   generating key repeats, etc.)
2. Target finding (finding the touched/focused window(s) that should
   receive the event)
3. Event modification (generating new events based on the original, such
   as for split motions)
4. Publishing

When an event is modified in step 3, we always create a new EventEntry
with a new event ID to distinguish it from the original. These derived
events need to be traced separately, but need to share the same trace
context as the original event. For example, an event is split across
windows A and B, and the whole event is sent to spy window C. In this
case, windows A and B receive a derived event, and C receives the whole
event. If B is a trace-sensitive window, we must not leak the sensitive
info from the event by tracing the original event through C.

Since event modification (step 3) always happens after target finding
(step 2) for a dispatch entry, we will trace the derived (modified)
events separately. The modified event will never affect
target-finding, so the derived events are more limited, but they share
the same context as the original event by using the same State under the
hood.

Bug: 210460522
Test: atest inputflinger_tests
Change-Id: I772a04b7dfd0322357dd4dfa95387244ca6230e9
diff --git a/services/inputflinger/dispatcher/trace/InputTracerInterface.h b/services/inputflinger/dispatcher/trace/InputTracerInterface.h
index c6cd7de..daf716f 100644
--- a/services/inputflinger/dispatcher/trace/InputTracerInterface.h
+++ b/services/inputflinger/dispatcher/trace/InputTracerInterface.h
@@ -52,7 +52,6 @@
      * to track the event's lifecycle inside InputDispatcher.
      */
     virtual std::unique_ptr<EventTrackerInterface> traceInboundEvent(const EventEntry&) = 0;
-
     /**
      * Notify the tracer that the traced event will be sent to the given InputTarget.
      * The tracer may change how the event is logged depending on the target. For example,
@@ -76,6 +75,19 @@
     virtual void eventProcessingComplete(const EventTrackerInterface&) = 0;
 
     /**
+     * Trace an input event that is derived from another event. This is used in cases where an event
+     * is modified from the original, such as when a touch is split across multiple windows, or
+     * when a HOVER_MOVE event is modified to be a HOVER_EXIT, etc. The original event's tracker
+     * must be provided, and a new EventTracker is returned that should be used to track the event's
+     * lifecycle.
+     *
+     * NOTE: The derived tracker cannot be used to change the targets of the original event, meaning
+     * it cannot be used with {@link #dispatchToTargetHint} or {@link eventProcessingComplete}.
+     */
+    virtual std::unique_ptr<EventTrackerInterface> traceDerivedEvent(
+            const EventEntry&, const EventTrackerInterface& originalEventTracker) = 0;
+
+    /**
      * Trace an input event being successfully dispatched to a window. The dispatched event may
      * be a previously traced inbound event, or it may be a synthesized event that has not been
      * previously traced. For inbound events that were previously traced, the EventTracker cookie