InputTracer: Create tracker for tracing synthetic events

Allow the creation of a trace tracker for a synthetic event that does
not stem from an inbound input event. This is used for any dispatching
cycle that has a non-input event root, such as ANR timers, window
removals, API interactions (e.g. pilfer pointers), etc.

Any key or motion events generated for this synthetic event should be
traced as a derived event. We achieve this by passing the trace tracker
through the dispatching pipeline, and tracing all of the synthesized
events for that root using the same tracker.

Since all synthetic events can now be traced, we can now enforce that
all dispatched events have been previously traced as either an inbound
or derived event. This makes the event cookie non-nullable.

Bug: 210460522
Test: atest inputflinger_tests
Change-Id: I3417aee300edc251e2f7cb76c1f719502a5f5b8b
diff --git a/services/inputflinger/dispatcher/trace/InputTracerInterface.h b/services/inputflinger/dispatcher/trace/InputTracerInterface.h
index daf716f..609d10c 100644
--- a/services/inputflinger/dispatcher/trace/InputTracerInterface.h
+++ b/services/inputflinger/dispatcher/trace/InputTracerInterface.h
@@ -52,6 +52,15 @@
      * to track the event's lifecycle inside InputDispatcher.
      */
     virtual std::unique_ptr<EventTrackerInterface> traceInboundEvent(const EventEntry&) = 0;
+
+    /**
+     * Create a trace tracker for a synthetic event that does not stem from an inbound input event.
+     * This includes things like generating cancellations or down events for various reasons,
+     * such as ANR, pilfering, transfer touch, etc. Any key or motion events generated for this
+     * synthetic event should be traced as a derived event using {@link #traceDerivedEvent}.
+     */
+    virtual std::unique_ptr<EventTrackerInterface> createTrackerForSyntheticEvent() = 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,
@@ -89,11 +98,11 @@
 
     /**
      * 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
-     * must be provided. For events that were not previously traced, the cookie must be null.
+     * be a previously traced inbound event, or it may be a synthesized event. All dispatched events
+     * must have been previously traced, so the trace tracker associated with the event must be
+     * provided.
      */
-    virtual void traceEventDispatch(const DispatchEntry&, const EventTrackerInterface*) = 0;
+    virtual void traceEventDispatch(const DispatchEntry&, const EventTrackerInterface&) = 0;
 };
 
 } // namespace android::inputdispatcher::trace