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> |
| 24 | #include <variant> |
| 25 | #include <vector> |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 26 | |
| 27 | namespace android::inputdispatcher::trace { |
| 28 | |
| 29 | /** |
Prabir Pradhan | 2707f8c | 2024-01-26 21:10:15 +0000 | [diff] [blame] | 30 | * A representation of an Android KeyEvent used by the tracing backend. |
| 31 | */ |
| 32 | struct 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 | */ |
| 51 | struct 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. */ |
| 75 | using TracedEvent = std::variant<TracedKeyEvent, TracedMotionEvent>; |
| 76 | |
| 77 | /** |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 78 | * An interface for the tracing backend, used for setting a custom backend for testing. |
| 79 | */ |
| 80 | class InputTracingBackendInterface { |
| 81 | public: |
| 82 | virtual ~InputTracingBackendInterface() = default; |
| 83 | |
| 84 | /** Trace a KeyEvent. */ |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 85 | virtual void traceKeyEvent(const TracedKeyEvent&) = 0; |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 86 | |
| 87 | /** Trace a MotionEvent. */ |
Prabir Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 88 | virtual void traceMotionEvent(const TracedMotionEvent&) = 0; |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 89 | |
| 90 | /** Trace an event being sent to a window. */ |
| 91 | struct WindowDispatchArgs { |
Prabir Pradhan | 2707f8c | 2024-01-26 21:10:15 +0000 | [diff] [blame] | 92 | TracedEvent eventEntry; |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 93 | 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 Pradhan | bb7a020 | 2024-02-10 02:09:01 +0000 | [diff] [blame] | 102 | virtual void traceWindowDispatch(const WindowDispatchArgs&) = 0; |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | } // namespace android::inputdispatcher::trace |