blob: 4bb5799d7213933c2f7435fe295b877354111cc0 [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
Prabir Pradhan2707f8c2024-01-26 21:10:15 +000019#include <gui/PidUid.h>
20#include <input/Input.h>
21#include <ui/Transform.h>
22
23#include <array>
24#include <variant>
25#include <vector>
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000026
27namespace android::inputdispatcher::trace {
28
29/**
Prabir Pradhan4c49aad2024-02-08 20:42:35 +000030 * Describes the type of this event being traced, with respect to InputDispatcher.
31 */
32enum class EventType {
33 // This is an event that was reported through the InputListener interface or was injected.
34 INBOUND,
35 // This is an event that was synthesized within InputDispatcher; either being derived
36 // from an inbound event (e.g. a split motion event), or synthesized completely
37 // (e.g. a CANCEL event generated when the inbound stream is not canceled).
38 SYNTHESIZED,
39
40 ftl_last = SYNTHESIZED,
41};
42
43/**
Prabir Pradhan2707f8c2024-01-26 21:10:15 +000044 * A representation of an Android KeyEvent used by the tracing backend.
45 */
46struct TracedKeyEvent {
47 int32_t id;
48 nsecs_t eventTime;
49 uint32_t policyFlags;
50 int32_t deviceId;
51 uint32_t source;
52 int32_t displayId;
53 int32_t action;
54 int32_t keyCode;
55 int32_t scanCode;
56 int32_t metaState;
57 nsecs_t downTime;
58 int32_t flags;
59 int32_t repeatCount;
Prabir Pradhan4c49aad2024-02-08 20:42:35 +000060 EventType eventType;
Prabir Pradhan2707f8c2024-01-26 21:10:15 +000061};
62
63/**
64 * A representation of an Android MotionEvent used by the tracing backend.
65 */
66struct TracedMotionEvent {
67 int32_t id;
68 nsecs_t eventTime;
69 uint32_t policyFlags;
70 int32_t deviceId;
71 uint32_t source;
72 int32_t displayId;
73 int32_t action;
74 int32_t actionButton;
75 int32_t flags;
76 int32_t metaState;
77 int32_t buttonState;
78 MotionClassification classification;
79 int32_t edgeFlags;
80 float xPrecision;
81 float yPrecision;
82 float xCursorPosition;
83 float yCursorPosition;
84 nsecs_t downTime;
85 std::vector<PointerProperties> pointerProperties;
86 std::vector<PointerCoords> pointerCoords;
Prabir Pradhan4c49aad2024-02-08 20:42:35 +000087 EventType eventType;
Prabir Pradhan2707f8c2024-01-26 21:10:15 +000088};
89
90/** A representation of a traced input event. */
91using TracedEvent = std::variant<TracedKeyEvent, TracedMotionEvent>;
92
Prabir Pradhan8c3b1432024-02-09 23:34:16 +000093/** Additional information about an input event being traced. */
94struct TracedEventArgs {
95 // True if the event is targeting at least one secure window.
96 bool isSecure;
97};
98
Prabir Pradhan4b408be2024-02-21 19:19:47 +000099/** Additional information about an input event being dispatched to a window. */
100struct WindowDispatchArgs {
101 TracedEvent eventEntry;
102 nsecs_t deliveryTime;
103 int32_t resolvedFlags;
104 gui::Uid targetUid;
105 int64_t vsyncId;
106 int32_t windowId;
107 ui::Transform transform;
108 ui::Transform rawTransform;
109 std::array<uint8_t, 32> hmac;
110 int32_t resolvedKeyRepeatCount;
111};
112
Prabir Pradhan2707f8c2024-01-26 21:10:15 +0000113/**
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +0000114 * An interface for the tracing backend, used for setting a custom backend for testing.
115 */
116class InputTracingBackendInterface {
117public:
118 virtual ~InputTracingBackendInterface() = default;
119
120 /** Trace a KeyEvent. */
Prabir Pradhan8c3b1432024-02-09 23:34:16 +0000121 virtual void traceKeyEvent(const TracedKeyEvent&, const TracedEventArgs&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +0000122
123 /** Trace a MotionEvent. */
Prabir Pradhan8c3b1432024-02-09 23:34:16 +0000124 virtual void traceMotionEvent(const TracedMotionEvent&, const TracedEventArgs&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +0000125
126 /** Trace an event being sent to a window. */
Prabir Pradhan8c3b1432024-02-09 23:34:16 +0000127 virtual void traceWindowDispatch(const WindowDispatchArgs&, const TracedEventArgs&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +0000128};
129
130} // namespace android::inputdispatcher::trace