Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 1 | /* |
| 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 Pradhan | 2707f8c | 2024-01-26 21:10:15 +0000 | [diff] [blame] | 19 | #include <gui/PidUid.h> |
| 20 | #include <input/Input.h> |
| 21 | #include <ui/Transform.h> |
| 22 | |
| 23 | #include <array> |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 24 | #include <set> |
Prabir Pradhan | 2707f8c | 2024-01-26 21:10:15 +0000 | [diff] [blame] | 25 | #include <variant> |
| 26 | #include <vector> |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 27 | |
| 28 | namespace android::inputdispatcher::trace { |
| 29 | |
| 30 | /** |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 31 | * Describes the type of this event being traced, with respect to InputDispatcher. |
| 32 | */ |
| 33 | enum class EventType { |
| 34 | // This is an event that was reported through the InputListener interface or was injected. |
| 35 | INBOUND, |
| 36 | // This is an event that was synthesized within InputDispatcher; either being derived |
| 37 | // from an inbound event (e.g. a split motion event), or synthesized completely |
| 38 | // (e.g. a CANCEL event generated when the inbound stream is not canceled). |
| 39 | SYNTHESIZED, |
| 40 | |
| 41 | ftl_last = SYNTHESIZED, |
| 42 | }; |
| 43 | |
| 44 | /** |
Prabir Pradhan | 2707f8c | 2024-01-26 21:10:15 +0000 | [diff] [blame] | 45 | * A representation of an Android KeyEvent used by the tracing backend. |
| 46 | */ |
| 47 | struct TracedKeyEvent { |
| 48 | int32_t id; |
| 49 | nsecs_t eventTime; |
| 50 | uint32_t policyFlags; |
| 51 | int32_t deviceId; |
| 52 | uint32_t source; |
| 53 | int32_t displayId; |
| 54 | int32_t action; |
| 55 | int32_t keyCode; |
| 56 | int32_t scanCode; |
| 57 | int32_t metaState; |
| 58 | nsecs_t downTime; |
| 59 | int32_t flags; |
| 60 | int32_t repeatCount; |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 61 | EventType eventType; |
Prabir Pradhan | 2707f8c | 2024-01-26 21:10:15 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | /** |
| 65 | * A representation of an Android MotionEvent used by the tracing backend. |
| 66 | */ |
| 67 | struct TracedMotionEvent { |
| 68 | int32_t id; |
| 69 | nsecs_t eventTime; |
| 70 | uint32_t policyFlags; |
| 71 | int32_t deviceId; |
| 72 | uint32_t source; |
| 73 | int32_t displayId; |
| 74 | int32_t action; |
| 75 | int32_t actionButton; |
| 76 | int32_t flags; |
| 77 | int32_t metaState; |
| 78 | int32_t buttonState; |
| 79 | MotionClassification classification; |
| 80 | int32_t edgeFlags; |
| 81 | float xPrecision; |
| 82 | float yPrecision; |
| 83 | float xCursorPosition; |
| 84 | float yCursorPosition; |
| 85 | nsecs_t downTime; |
| 86 | std::vector<PointerProperties> pointerProperties; |
| 87 | std::vector<PointerCoords> pointerCoords; |
Prabir Pradhan | 4c49aad | 2024-02-08 20:42:35 +0000 | [diff] [blame] | 88 | EventType eventType; |
Prabir Pradhan | 2707f8c | 2024-01-26 21:10:15 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | /** A representation of a traced input event. */ |
| 92 | using TracedEvent = std::variant<TracedKeyEvent, TracedMotionEvent>; |
| 93 | |
Prabir Pradhan | 8c3b143 | 2024-02-09 23:34:16 +0000 | [diff] [blame] | 94 | /** Additional information about an input event being traced. */ |
Prabir Pradhan | c7edaaa | 2024-03-15 15:31:02 +0000 | [diff] [blame] | 95 | struct TracedEventMetadata { |
Prabir Pradhan | 8c3b143 | 2024-02-09 23:34:16 +0000 | [diff] [blame] | 96 | // True if the event is targeting at least one secure window. |
| 97 | bool isSecure; |
Prabir Pradhan | bf3c832 | 2024-02-23 02:38:36 +0000 | [diff] [blame] | 98 | // The list of possible UIDs that this event could be targeting. |
| 99 | std::set<gui::Uid> targets; |
Prabir Pradhan | 04a6642 | 2024-03-15 22:45:27 +0000 | [diff] [blame] | 100 | // True if the there was an active input method connection while this event was processed. |
| 101 | bool isImeConnectionActive; |
Prabir Pradhan | 8c3b143 | 2024-02-09 23:34:16 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
Prabir Pradhan | 4b408be | 2024-02-21 19:19:47 +0000 | [diff] [blame] | 104 | /** Additional information about an input event being dispatched to a window. */ |
| 105 | struct WindowDispatchArgs { |
| 106 | TracedEvent eventEntry; |
| 107 | nsecs_t deliveryTime; |
| 108 | int32_t resolvedFlags; |
| 109 | gui::Uid targetUid; |
| 110 | int64_t vsyncId; |
| 111 | int32_t windowId; |
| 112 | ui::Transform transform; |
| 113 | ui::Transform rawTransform; |
| 114 | std::array<uint8_t, 32> hmac; |
| 115 | int32_t resolvedKeyRepeatCount; |
| 116 | }; |
| 117 | |
Prabir Pradhan | 2707f8c | 2024-01-26 21:10:15 +0000 | [diff] [blame] | 118 | /** |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 119 | * An interface for the tracing backend, used for setting a custom backend for testing. |
| 120 | */ |
| 121 | class InputTracingBackendInterface { |
| 122 | public: |
| 123 | virtual ~InputTracingBackendInterface() = default; |
| 124 | |
| 125 | /** Trace a KeyEvent. */ |
Prabir Pradhan | c7edaaa | 2024-03-15 15:31:02 +0000 | [diff] [blame] | 126 | virtual void traceKeyEvent(const TracedKeyEvent&, const TracedEventMetadata&) = 0; |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 127 | |
| 128 | /** Trace a MotionEvent. */ |
Prabir Pradhan | c7edaaa | 2024-03-15 15:31:02 +0000 | [diff] [blame] | 129 | virtual void traceMotionEvent(const TracedMotionEvent&, const TracedEventMetadata&) = 0; |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 130 | |
| 131 | /** Trace an event being sent to a window. */ |
Prabir Pradhan | c7edaaa | 2024-03-15 15:31:02 +0000 | [diff] [blame] | 132 | virtual void traceWindowDispatch(const WindowDispatchArgs&, const TracedEventMetadata&) = 0; |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | } // namespace android::inputdispatcher::trace |