blob: b0eadfe51f22ce26d8a921a1becf7140d5c93778 [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
77/**
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000078 * An interface for the tracing backend, used for setting a custom backend for testing.
79 */
80class InputTracingBackendInterface {
81public:
82 virtual ~InputTracingBackendInterface() = default;
83
84 /** Trace a KeyEvent. */
Prabir Pradhanbb7a0202024-02-10 02:09:01 +000085 virtual void traceKeyEvent(const TracedKeyEvent&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000086
87 /** Trace a MotionEvent. */
Prabir Pradhanbb7a0202024-02-10 02:09:01 +000088 virtual void traceMotionEvent(const TracedMotionEvent&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000089
90 /** Trace an event being sent to a window. */
91 struct WindowDispatchArgs {
Prabir Pradhan2707f8c2024-01-26 21:10:15 +000092 TracedEvent eventEntry;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +000093 nsecs_t deliveryTime;
94 int32_t resolvedFlags;
95 gui::Uid targetUid;
96 int64_t vsyncId;
97 int32_t windowId;
98 ui::Transform transform;
99 ui::Transform rawTransform;
100 std::array<uint8_t, 32> hmac;
101 };
Prabir Pradhanbb7a0202024-02-10 02:09:01 +0000102 virtual void traceWindowDispatch(const WindowDispatchArgs&) = 0;
Prabir Pradhanabcdf5c2023-12-15 07:30:22 +0000103};
104
105} // namespace android::inputdispatcher::trace