blob: c6cd7de4b616b5a0b3b7013070a15011ec4b4223 [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;
55
56 /**
57 * Notify the tracer that the traced event will be sent to the given InputTarget.
58 * The tracer may change how the event is logged depending on the target. For example,
59 * events targeting certain UIDs may be logged as sensitive events.
60 * This may be called 0 or more times for each tracked event before event processing is
61 * completed.
62 */
63 virtual void dispatchToTargetHint(const EventTrackerInterface&, const InputTarget&) = 0;
64
65 /**
66 * Notify the tracer that the event processing is complete. This may be called at most once
67 * for each traced event. If a tracked event is dropped before it can be processed, it is
68 * possible that this is never called before the EventTracker is destroyed.
69 *
70 * This is used to commit the event to the trace in a timely manner, rather than always
71 * waiting for the event to go out of scope (and thus for the EventTracker to be destroyed)
72 * before committing. The point at which the event is destroyed can depend on several factors
73 * outside of our control, such as how long apps take to respond, so we don't want to depend on
74 * that.
75 */
76 virtual void eventProcessingComplete(const EventTrackerInterface&) = 0;
77
78 /**
79 * Trace an input event being successfully dispatched to a window. The dispatched event may
80 * be a previously traced inbound event, or it may be a synthesized event that has not been
81 * previously traced. For inbound events that were previously traced, the EventTracker cookie
82 * must be provided. For events that were not previously traced, the cookie must be null.
83 */
84 virtual void traceEventDispatch(const DispatchEntry&, const EventTrackerInterface*) = 0;
85};
86
87} // namespace android::inputdispatcher::trace