blob: 865e8277c09aba31cac2afa1343cb8e8c089323c [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 Pradhan2707f8c2024-01-26 21:10:15 +000030 * A representation of an Android KeyEvent used by the tracing backend.
31 */
32struct TracedKeyEvent {
33 int32_t id;
34 nsecs_t eventTime;
35 uint32_t policyFlags;
36 int32_t deviceId;
37 uint32_t source;
38 int32_t displayId;
39 int32_t action;
40 int32_t keyCode;
41 int32_t scanCode;
42 int32_t metaState;
43 nsecs_t downTime;
44 int32_t flags;
45 int32_t repeatCount;
46};
47
48/**
49 * A representation of an Android MotionEvent used by the tracing backend.
50 */
51struct TracedMotionEvent {
52 int32_t id;
53 nsecs_t eventTime;
54 uint32_t policyFlags;
55 int32_t deviceId;
56 uint32_t source;
57 int32_t displayId;
58 int32_t action;
59 int32_t actionButton;
60 int32_t flags;
61 int32_t metaState;
62 int32_t buttonState;
63 MotionClassification classification;
64 int32_t edgeFlags;
65 float xPrecision;
66 float yPrecision;
67 float xCursorPosition;
68 float yCursorPosition;
69 nsecs_t downTime;
70 std::vector<PointerProperties> pointerProperties;
71 std::vector<PointerCoords> pointerCoords;
72};
73
74/** A representation of a traced input event. */
75using TracedEvent = std::variant<TracedKeyEvent, TracedMotionEvent>;
76
Prabir Pradhan8c3b1432024-02-09 23:34:16 +000077/** Additional information about an input event being traced. */
78struct TracedEventArgs {
79 // True if the event is targeting at least one secure window.
80 bool isSecure;
81};
82
Prabir Pradhan2707f8c2024-01-26 21:10:15 +000083/**
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000084 * An interface for the tracing backend, used for setting a custom backend for testing.
85 */
86class InputTracingBackendInterface {
87public:
88 virtual ~InputTracingBackendInterface() = default;
89
90 /** Trace a KeyEvent. */
Prabir Pradhan8c3b1432024-02-09 23:34:16 +000091 virtual void traceKeyEvent(const TracedKeyEvent&, const TracedEventArgs&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000092
93 /** Trace a MotionEvent. */
Prabir Pradhan8c3b1432024-02-09 23:34:16 +000094 virtual void traceMotionEvent(const TracedMotionEvent&, const TracedEventArgs&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000095
96 /** Trace an event being sent to a window. */
97 struct WindowDispatchArgs {
Prabir Pradhan2707f8c2024-01-26 21:10:15 +000098 TracedEvent eventEntry;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000099 nsecs_t deliveryTime;
100 int32_t resolvedFlags;
101 gui::Uid targetUid;
102 int64_t vsyncId;
103 int32_t windowId;
104 ui::Transform transform;
105 ui::Transform rawTransform;
106 std::array<uint8_t, 32> hmac;
Prabir Pradhan560d0d12024-03-07 18:08:27 +0000107 int32_t resolvedKeyRepeatCount;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +0000108 };
Prabir Pradhan8c3b1432024-02-09 23:34:16 +0000109 virtual void traceWindowDispatch(const WindowDispatchArgs&, const TracedEventArgs&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +0000110};
111
112} // namespace android::inputdispatcher::trace