blob: daf716f9938a63461d38c7316ec5d6bd59c41e82 [file] [log] [blame]
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +00001/*
2 * Copyright 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include "../Entry.h"
20#include "../InputTarget.h"
21#include "EventTrackerInterface.h"
22
23namespace android::inputdispatcher::trace {
24
25/**
26 * InputTracerInterface is the tracing interface for InputDispatcher.
27 *
28 * The tracer is responsible for tracing information about input events and where they are
29 * dispatched. The trace is logged to the backend using the InputTracingBackendInterface.
30 *
31 * A normal traced event should have the following lifecycle:
32 * - The EventTracker is obtained from traceInboundEvent(), after which point the event
33 * should not change.
34 * - While the event is being processed, dispatchToTargetHint() is called for each target that
35 * the event will be eventually sent to.
36 * - Once all targets have been determined, eventProcessingComplete() is called, at which point
37 * the tracer will have enough information to commit the event to the trace.
38 * - For each event that is dispatched to the client, traceEventDispatch() is called, and the
39 * tracer will record that the event was sent to the client.
40 */
41class InputTracerInterface {
42public:
43 InputTracerInterface() = default;
44 virtual ~InputTracerInterface() = default;
45 InputTracerInterface(const InputTracerInterface&) = delete;
46 InputTracerInterface& operator=(const InputTracerInterface&) = delete;
47
48 /**
49 * Trace an input event that is being processed by InputDispatcher. The event must not be
50 * modified after it is traced to keep the traced event consistent with the event that is
51 * eventually dispatched. An EventTracker is returned for each traced event that should be used
52 * to track the event's lifecycle inside InputDispatcher.
53 */
54 virtual std::unique_ptr<EventTrackerInterface> traceInboundEvent(const EventEntry&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000055 /**
56 * Notify the tracer that the traced event will be sent to the given InputTarget.
57 * The tracer may change how the event is logged depending on the target. For example,
58 * events targeting certain UIDs may be logged as sensitive events.
59 * This may be called 0 or more times for each tracked event before event processing is
60 * completed.
61 */
62 virtual void dispatchToTargetHint(const EventTrackerInterface&, const InputTarget&) = 0;
63
64 /**
65 * Notify the tracer that the event processing is complete. This may be called at most once
66 * for each traced event. If a tracked event is dropped before it can be processed, it is
67 * possible that this is never called before the EventTracker is destroyed.
68 *
69 * This is used to commit the event to the trace in a timely manner, rather than always
70 * waiting for the event to go out of scope (and thus for the EventTracker to be destroyed)
71 * before committing. The point at which the event is destroyed can depend on several factors
72 * outside of our control, such as how long apps take to respond, so we don't want to depend on
73 * that.
74 */
75 virtual void eventProcessingComplete(const EventTrackerInterface&) = 0;
76
77 /**
Prabir Pradhana67623c2024-02-21 06:57:36 +000078 * Trace an input event that is derived from another event. This is used in cases where an event
79 * is modified from the original, such as when a touch is split across multiple windows, or
80 * when a HOVER_MOVE event is modified to be a HOVER_EXIT, etc. The original event's tracker
81 * must be provided, and a new EventTracker is returned that should be used to track the event's
82 * lifecycle.
83 *
84 * NOTE: The derived tracker cannot be used to change the targets of the original event, meaning
85 * it cannot be used with {@link #dispatchToTargetHint} or {@link eventProcessingComplete}.
86 */
87 virtual std::unique_ptr<EventTrackerInterface> traceDerivedEvent(
88 const EventEntry&, const EventTrackerInterface& originalEventTracker) = 0;
89
90 /**
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000091 * Trace an input event being successfully dispatched to a window. The dispatched event may
92 * be a previously traced inbound event, or it may be a synthesized event that has not been
93 * previously traced. For inbound events that were previously traced, the EventTracker cookie
94 * must be provided. For events that were not previously traced, the cookie must be null.
95 */
96 virtual void traceEventDispatch(const DispatchEntry&, const EventTrackerInterface*) = 0;
97};
98
99} // namespace android::inputdispatcher::trace