Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
Prabir Pradhan | 6561380 | 2023-02-22 23:36:58 +0000 | [diff] [blame] | 17 | #define LOG_TAG "InputDispatcher" |
| 18 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 19 | #include "Entry.h" |
| 20 | |
| 21 | #include "Connection.h" |
Prabir Pradhan | 6561380 | 2023-02-22 23:36:58 +0000 | [diff] [blame] | 22 | #include "DebugConfig.h" |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 23 | |
| 24 | #include <android-base/stringprintf.h> |
| 25 | #include <cutils/atomic.h> |
Harry Cutts | c57cd3c | 2024-04-24 13:52:55 +0000 | [diff] [blame] | 26 | #include <ftl/enum.h> |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 27 | #include <inttypes.h> |
| 28 | |
| 29 | using android::base::StringPrintf; |
| 30 | |
| 31 | namespace android::inputdispatcher { |
| 32 | |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 33 | VerifiedKeyEvent verifiedKeyEventFromKeyEntry(const KeyEntry& entry) { |
| 34 | return {{VerifiedInputEvent::Type::KEY, entry.deviceId, entry.eventTime, entry.source, |
| 35 | entry.displayId}, |
| 36 | entry.action, |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 37 | entry.flags & VERIFIED_KEY_EVENT_FLAGS, |
Siarhei Vishniakou | f355bf9 | 2021-12-09 10:43:21 -0800 | [diff] [blame] | 38 | entry.downTime, |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 39 | entry.keyCode, |
| 40 | entry.scanCode, |
| 41 | entry.metaState, |
| 42 | entry.repeatCount}; |
| 43 | } |
| 44 | |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 45 | VerifiedMotionEvent verifiedMotionEventFromMotionEntry(const MotionEntry& entry, |
| 46 | const ui::Transform& rawTransform) { |
| 47 | const vec2 rawXY = MotionEvent::calculateTransformedXY(entry.source, rawTransform, |
| 48 | entry.pointerCoords[0].getXYValue()); |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 49 | const int actionMasked = entry.action & AMOTION_EVENT_ACTION_MASK; |
| 50 | return {{VerifiedInputEvent::Type::MOTION, entry.deviceId, entry.eventTime, entry.source, |
| 51 | entry.displayId}, |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 52 | rawXY.x, |
| 53 | rawXY.y, |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 54 | actionMasked, |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 55 | entry.flags & VERIFIED_MOTION_EVENT_FLAGS, |
Siarhei Vishniakou | f355bf9 | 2021-12-09 10:43:21 -0800 | [diff] [blame] | 56 | entry.downTime, |
Gang Wang | e908789 | 2020-01-07 12:17:14 -0500 | [diff] [blame] | 57 | entry.metaState, |
| 58 | entry.buttonState}; |
| 59 | } |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 60 | |
| 61 | // --- EventEntry --- |
| 62 | |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 63 | EventEntry::EventEntry(int32_t id, Type type, nsecs_t eventTime, uint32_t policyFlags) |
| 64 | : id(id), |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 65 | type(type), |
| 66 | eventTime(eventTime), |
| 67 | policyFlags(policyFlags), |
| 68 | injectionState(nullptr), |
| 69 | dispatchInProgress(false) {} |
| 70 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 71 | // --- ConfigurationChangedEntry --- |
| 72 | |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 73 | ConfigurationChangedEntry::ConfigurationChangedEntry(int32_t id, nsecs_t eventTime) |
| 74 | : EventEntry(id, Type::CONFIGURATION_CHANGED, eventTime, 0) {} |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 75 | |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 76 | std::string ConfigurationChangedEntry::getDescription() const { |
| 77 | return StringPrintf("ConfigurationChangedEvent(), policyFlags=0x%08x", policyFlags); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | // --- DeviceResetEntry --- |
| 81 | |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 82 | DeviceResetEntry::DeviceResetEntry(int32_t id, nsecs_t eventTime, int32_t deviceId) |
| 83 | : EventEntry(id, Type::DEVICE_RESET, eventTime, 0), deviceId(deviceId) {} |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 84 | |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 85 | std::string DeviceResetEntry::getDescription() const { |
| 86 | return StringPrintf("DeviceResetEvent(deviceId=%d), policyFlags=0x%08x", deviceId, policyFlags); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 89 | // --- FocusEntry --- |
| 90 | |
| 91 | // Focus notifications always go to apps, so set the flag POLICY_FLAG_PASS_TO_USER for all entries |
Vishnu Nair | 7d3d00d | 2020-08-03 11:20:42 -0700 | [diff] [blame] | 92 | FocusEntry::FocusEntry(int32_t id, nsecs_t eventTime, sp<IBinder> connectionToken, bool hasFocus, |
Vishnu Nair | c519ff7 | 2021-01-21 08:23:08 -0800 | [diff] [blame] | 93 | const std::string& reason) |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 94 | : EventEntry(id, Type::FOCUS, eventTime, POLICY_FLAG_PASS_TO_USER), |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 95 | connectionToken(connectionToken), |
Vishnu Nair | 7d3d00d | 2020-08-03 11:20:42 -0700 | [diff] [blame] | 96 | hasFocus(hasFocus), |
| 97 | reason(reason) {} |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 98 | |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 99 | std::string FocusEntry::getDescription() const { |
| 100 | return StringPrintf("FocusEvent(hasFocus=%s)", hasFocus ? "true" : "false"); |
Siarhei Vishniakou | f1035d4 | 2019-09-20 16:32:01 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 103 | // --- PointerCaptureChangedEntry --- |
| 104 | |
| 105 | // PointerCaptureChanged notifications always go to apps, so set the flag POLICY_FLAG_PASS_TO_USER |
| 106 | // for all entries. |
| 107 | PointerCaptureChangedEntry::PointerCaptureChangedEntry(int32_t id, nsecs_t eventTime, |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 108 | const PointerCaptureRequest& request) |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 109 | : EventEntry(id, Type::POINTER_CAPTURE_CHANGED, eventTime, POLICY_FLAG_PASS_TO_USER), |
Prabir Pradhan | 5cc1a69 | 2021-08-06 14:01:18 +0000 | [diff] [blame] | 110 | pointerCaptureRequest(request) {} |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 111 | |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 112 | std::string PointerCaptureChangedEntry::getDescription() const { |
| 113 | return StringPrintf("PointerCaptureChangedEvent(pointerCaptureEnabled=%s)", |
Hiroki Sato | 2504023 | 2024-02-22 17:21:22 +0900 | [diff] [blame] | 114 | pointerCaptureRequest.isEnable() ? "true" : "false"); |
Prabir Pradhan | 9998771 | 2020-11-10 18:43:05 -0800 | [diff] [blame] | 115 | } |
| 116 | |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 117 | // --- DragEntry --- |
| 118 | |
| 119 | // Drag notifications always go to apps, so set the flag POLICY_FLAG_PASS_TO_USER for all entries |
| 120 | DragEntry::DragEntry(int32_t id, nsecs_t eventTime, sp<IBinder> connectionToken, bool isExiting, |
| 121 | float x, float y) |
| 122 | : EventEntry(id, Type::DRAG, eventTime, POLICY_FLAG_PASS_TO_USER), |
| 123 | connectionToken(connectionToken), |
| 124 | isExiting(isExiting), |
| 125 | x(x), |
| 126 | y(y) {} |
| 127 | |
arthurhung | b89ccb0 | 2020-12-30 16:19:01 +0800 | [diff] [blame] | 128 | std::string DragEntry::getDescription() const { |
| 129 | return StringPrintf("DragEntry(isExiting=%s, x=%f, y=%f)", isExiting ? "true" : "false", x, y); |
| 130 | } |
| 131 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 132 | // --- KeyEntry --- |
| 133 | |
Prabir Pradhan | a8cdbe1 | 2023-11-01 21:30:02 +0000 | [diff] [blame] | 134 | KeyEntry::KeyEntry(int32_t id, std::shared_ptr<InjectionState> injectionState, nsecs_t eventTime, |
| 135 | int32_t deviceId, uint32_t source, int32_t displayId, uint32_t policyFlags, |
| 136 | int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode, |
| 137 | int32_t metaState, int32_t repeatCount, nsecs_t downTime) |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 138 | : EventEntry(id, Type::KEY, eventTime, policyFlags), |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 139 | deviceId(deviceId), |
| 140 | source(source), |
| 141 | displayId(displayId), |
| 142 | action(action), |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 143 | keyCode(keyCode), |
| 144 | scanCode(scanCode), |
| 145 | metaState(metaState), |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 146 | downTime(downTime), |
| 147 | syntheticRepeat(false), |
Michael Wright | 5caf55a | 2022-11-24 22:31:42 +0000 | [diff] [blame] | 148 | interceptKeyResult(KeyEntry::InterceptKeyResult::UNKNOWN), |
Prabir Pradhan | 2404754 | 2023-11-02 17:14:59 +0000 | [diff] [blame] | 149 | interceptKeyWakeupTime(0), |
| 150 | flags(flags), |
| 151 | repeatCount(repeatCount) { |
Prabir Pradhan | a8cdbe1 | 2023-11-01 21:30:02 +0000 | [diff] [blame] | 152 | EventEntry::injectionState = std::move(injectionState); |
| 153 | } |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 154 | |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 155 | std::string KeyEntry::getDescription() const { |
Prabir Pradhan | 6561380 | 2023-02-22 23:36:58 +0000 | [diff] [blame] | 156 | if (!IS_DEBUGGABLE_BUILD) { |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 157 | return "KeyEvent"; |
Ashwini Oruganti | d399a52 | 2019-10-10 11:16:45 -0700 | [diff] [blame] | 158 | } |
Siarhei Vishniakou | d948957 | 2021-11-12 20:08:38 -0800 | [diff] [blame] | 159 | return StringPrintf("KeyEvent(deviceId=%d, eventTime=%" PRIu64 ", source=%s, displayId=%" PRId32 |
| 160 | ", action=%s, " |
Siarhei Vishniakou | 5b6c96f | 2021-02-25 00:21:51 -1000 | [diff] [blame] | 161 | "flags=0x%08x, keyCode=%s(%d), scanCode=%d, metaState=0x%08x, " |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 162 | "repeatCount=%d), policyFlags=0x%08x", |
Siarhei Vishniakou | d948957 | 2021-11-12 20:08:38 -0800 | [diff] [blame] | 163 | deviceId, eventTime, inputEventSourceToString(source).c_str(), displayId, |
| 164 | KeyEvent::actionToString(action), flags, KeyEvent::getLabel(keyCode), |
| 165 | keyCode, scanCode, metaState, repeatCount, policyFlags); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Prabir Pradhan | abcdf5c | 2023-12-15 07:30:22 +0000 | [diff] [blame] | 168 | std::ostream& operator<<(std::ostream& out, const KeyEntry& keyEntry) { |
| 169 | out << keyEntry.getDescription(); |
| 170 | return out; |
| 171 | } |
| 172 | |
Antonio Kantek | 7242d8b | 2021-08-05 16:07:20 -0700 | [diff] [blame] | 173 | // --- TouchModeEntry --- |
| 174 | |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 175 | TouchModeEntry::TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode, int displayId) |
Antonio Kantek | 7242d8b | 2021-08-05 16:07:20 -0700 | [diff] [blame] | 176 | : EventEntry(id, Type::TOUCH_MODE_CHANGED, eventTime, POLICY_FLAG_PASS_TO_USER), |
Antonio Kantek | 15beb51 | 2022-06-13 22:35:41 +0000 | [diff] [blame] | 177 | inTouchMode(inTouchMode), |
| 178 | displayId(displayId) {} |
Antonio Kantek | 7242d8b | 2021-08-05 16:07:20 -0700 | [diff] [blame] | 179 | |
Antonio Kantek | 7242d8b | 2021-08-05 16:07:20 -0700 | [diff] [blame] | 180 | std::string TouchModeEntry::getDescription() const { |
| 181 | return StringPrintf("TouchModeEvent(inTouchMode=%s)", inTouchMode ? "true" : "false"); |
| 182 | } |
| 183 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 184 | // --- MotionEntry --- |
| 185 | |
Prabir Pradhan | a8cdbe1 | 2023-11-01 21:30:02 +0000 | [diff] [blame] | 186 | MotionEntry::MotionEntry(int32_t id, std::shared_ptr<InjectionState> injectionState, |
| 187 | nsecs_t eventTime, int32_t deviceId, uint32_t source, int32_t displayId, |
| 188 | uint32_t policyFlags, int32_t action, int32_t actionButton, int32_t flags, |
| 189 | int32_t metaState, int32_t buttonState, |
| 190 | MotionClassification classification, int32_t edgeFlags, float xPrecision, |
| 191 | float yPrecision, float xCursorPosition, float yCursorPosition, |
| 192 | nsecs_t downTime, const std::vector<PointerProperties>& pointerProperties, |
Siarhei Vishniakou | edd6120 | 2023-10-18 11:22:40 -0700 | [diff] [blame] | 193 | const std::vector<PointerCoords>& pointerCoords) |
Garfield Tan | c51d1ba | 2020-01-28 13:24:04 -0800 | [diff] [blame] | 194 | : EventEntry(id, Type::MOTION, eventTime, policyFlags), |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 195 | deviceId(deviceId), |
| 196 | source(source), |
| 197 | displayId(displayId), |
| 198 | action(action), |
| 199 | actionButton(actionButton), |
| 200 | flags(flags), |
| 201 | metaState(metaState), |
| 202 | buttonState(buttonState), |
| 203 | classification(classification), |
| 204 | edgeFlags(edgeFlags), |
| 205 | xPrecision(xPrecision), |
| 206 | yPrecision(yPrecision), |
| 207 | xCursorPosition(xCursorPosition), |
| 208 | yCursorPosition(yCursorPosition), |
| 209 | downTime(downTime), |
Siarhei Vishniakou | edd6120 | 2023-10-18 11:22:40 -0700 | [diff] [blame] | 210 | pointerProperties(pointerProperties), |
Prabir Pradhan | a8cdbe1 | 2023-11-01 21:30:02 +0000 | [diff] [blame] | 211 | pointerCoords(pointerCoords) { |
| 212 | EventEntry::injectionState = std::move(injectionState); |
| 213 | } |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 214 | |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 215 | std::string MotionEntry::getDescription() const { |
Prabir Pradhan | 6561380 | 2023-02-22 23:36:58 +0000 | [diff] [blame] | 216 | if (!IS_DEBUGGABLE_BUILD) { |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 217 | return "MotionEvent"; |
Ashwini Oruganti | d399a52 | 2019-10-10 11:16:45 -0700 | [diff] [blame] | 218 | } |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 219 | std::string msg; |
Siarhei Vishniakou | a1188f5 | 2020-10-20 20:14:52 -0500 | [diff] [blame] | 220 | msg += StringPrintf("MotionEvent(deviceId=%d, eventTime=%" PRIu64 |
Siarhei Vishniakou | d948957 | 2021-11-12 20:08:38 -0800 | [diff] [blame] | 221 | ", source=%s, displayId=%" PRId32 |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 222 | ", action=%s, actionButton=0x%08x, flags=0x%08x, metaState=0x%08x, " |
| 223 | "buttonState=0x%08x, " |
| 224 | "classification=%s, edgeFlags=0x%08x, xPrecision=%.1f, yPrecision=%.1f, " |
| 225 | "xCursorPosition=%0.1f, yCursorPosition=%0.1f, pointers=[", |
Siarhei Vishniakou | d948957 | 2021-11-12 20:08:38 -0800 | [diff] [blame] | 226 | deviceId, eventTime, inputEventSourceToString(source).c_str(), displayId, |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 227 | MotionEvent::actionToString(action).c_str(), actionButton, flags, metaState, |
| 228 | buttonState, motionClassificationToString(classification), edgeFlags, |
| 229 | xPrecision, yPrecision, xCursorPosition, yCursorPosition); |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 230 | |
Siarhei Vishniakou | edd6120 | 2023-10-18 11:22:40 -0700 | [diff] [blame] | 231 | for (uint32_t i = 0; i < getPointerCount(); i++) { |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 232 | if (i) { |
| 233 | msg += ", "; |
| 234 | } |
| 235 | msg += StringPrintf("%d: (%.1f, %.1f)", pointerProperties[i].id, pointerCoords[i].getX(), |
| 236 | pointerCoords[i].getY()); |
| 237 | } |
| 238 | msg += StringPrintf("]), policyFlags=0x%08x", policyFlags); |
Siarhei Vishniakou | 14411c9 | 2020-09-18 21:15:05 -0500 | [diff] [blame] | 239 | return msg; |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Siarhei Vishniakou | 72945a0 | 2023-09-18 18:30:25 -0700 | [diff] [blame] | 242 | std::ostream& operator<<(std::ostream& out, const MotionEntry& motionEntry) { |
| 243 | out << motionEntry.getDescription(); |
| 244 | return out; |
| 245 | } |
| 246 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 247 | // --- SensorEntry --- |
| 248 | |
| 249 | SensorEntry::SensorEntry(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source, |
| 250 | uint32_t policyFlags, nsecs_t hwTimestamp, |
| 251 | InputDeviceSensorType sensorType, InputDeviceSensorAccuracy accuracy, |
| 252 | bool accuracyChanged, std::vector<float> values) |
| 253 | : EventEntry(id, Type::SENSOR, eventTime, policyFlags), |
| 254 | deviceId(deviceId), |
| 255 | source(source), |
| 256 | sensorType(sensorType), |
| 257 | accuracy(accuracy), |
| 258 | accuracyChanged(accuracyChanged), |
| 259 | hwTimestamp(hwTimestamp), |
| 260 | values(std::move(values)) {} |
| 261 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 262 | std::string SensorEntry::getDescription() const { |
| 263 | std::string msg; |
Siarhei Vishniakou | d948957 | 2021-11-12 20:08:38 -0800 | [diff] [blame] | 264 | msg += StringPrintf("SensorEntry(deviceId=%d, source=%s, sensorType=%s, " |
Harry Cutts | c57cd3c | 2024-04-24 13:52:55 +0000 | [diff] [blame] | 265 | "accuracy=%s, hwTimestamp=%" PRId64, |
Siarhei Vishniakou | f12f2f7 | 2021-11-17 17:49:45 -0800 | [diff] [blame] | 266 | deviceId, inputEventSourceToString(source).c_str(), |
Harry Cutts | c57cd3c | 2024-04-24 13:52:55 +0000 | [diff] [blame] | 267 | ftl::enum_string(sensorType).c_str(), ftl::enum_string(accuracy).c_str(), |
| 268 | hwTimestamp); |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 269 | |
Prabir Pradhan | 6561380 | 2023-02-22 23:36:58 +0000 | [diff] [blame] | 270 | if (IS_DEBUGGABLE_BUILD) { |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 271 | for (size_t i = 0; i < values.size(); i++) { |
| 272 | if (i > 0) { |
| 273 | msg += ", "; |
| 274 | } |
| 275 | msg += StringPrintf("(%.3f)", values[i]); |
| 276 | } |
| 277 | } |
| 278 | msg += StringPrintf(", policyFlags=0x%08x", policyFlags); |
| 279 | return msg; |
| 280 | } |
| 281 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 282 | // --- DispatchEntry --- |
| 283 | |
| 284 | volatile int32_t DispatchEntry::sNextSeqAtomic; |
| 285 | |
Prabir Pradhan | 2404754 | 2023-11-02 17:14:59 +0000 | [diff] [blame] | 286 | DispatchEntry::DispatchEntry(std::shared_ptr<const EventEntry> eventEntry, |
Siarhei Vishniakou | 18cbdb8 | 2024-01-31 17:58:13 -0800 | [diff] [blame] | 287 | ftl::Flags<InputTargetFlags> targetFlags, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 288 | const ui::Transform& transform, const ui::Transform& rawTransform, |
Prabir Pradhan | adc59b4 | 2023-12-15 05:34:11 +0000 | [diff] [blame] | 289 | float globalScaleFactor, gui::Uid targetUid, int64_t vsyncId, |
| 290 | std::optional<int32_t> windowId) |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 291 | : seq(nextSeq()), |
Siarhei Vishniakou | a9a7ee8 | 2019-10-14 16:28:19 -0700 | [diff] [blame] | 292 | eventEntry(std::move(eventEntry)), |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 293 | targetFlags(targetFlags), |
chaviw | 1ff3d1e | 2020-07-01 15:53:47 -0700 | [diff] [blame] | 294 | transform(transform), |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 295 | rawTransform(rawTransform), |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 296 | globalScaleFactor(globalScaleFactor), |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 297 | deliveryTime(0), |
Prabir Pradhan | adc59b4 | 2023-12-15 05:34:11 +0000 | [diff] [blame] | 298 | resolvedFlags(0), |
| 299 | targetUid(targetUid), |
| 300 | vsyncId(vsyncId), |
| 301 | windowId(windowId) { |
Siarhei Vishniakou | 2af5b03 | 2023-07-10 18:52:17 -0700 | [diff] [blame] | 302 | switch (this->eventEntry->type) { |
| 303 | case EventEntry::Type::KEY: { |
Prabir Pradhan | 2404754 | 2023-11-02 17:14:59 +0000 | [diff] [blame] | 304 | const KeyEntry& keyEntry = static_cast<const KeyEntry&>(*this->eventEntry); |
Siarhei Vishniakou | 2af5b03 | 2023-07-10 18:52:17 -0700 | [diff] [blame] | 305 | resolvedFlags = keyEntry.flags; |
Siarhei Vishniakou | 2af5b03 | 2023-07-10 18:52:17 -0700 | [diff] [blame] | 306 | break; |
| 307 | } |
| 308 | case EventEntry::Type::MOTION: { |
Prabir Pradhan | 2404754 | 2023-11-02 17:14:59 +0000 | [diff] [blame] | 309 | const MotionEntry& motionEntry = static_cast<const MotionEntry&>(*this->eventEntry); |
Siarhei Vishniakou | 2af5b03 | 2023-07-10 18:52:17 -0700 | [diff] [blame] | 310 | resolvedFlags = motionEntry.flags; |
| 311 | break; |
| 312 | } |
| 313 | default: { |
| 314 | break; |
| 315 | } |
| 316 | } |
| 317 | } |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 318 | |
| 319 | uint32_t DispatchEntry::nextSeq() { |
| 320 | // Sequence number 0 is reserved and will never be returned. |
| 321 | uint32_t seq; |
| 322 | do { |
| 323 | seq = android_atomic_inc(&sNextSeqAtomic); |
| 324 | } while (!seq); |
| 325 | return seq; |
| 326 | } |
| 327 | |
Siarhei Vishniakou | d010b01 | 2023-01-18 15:00:53 -0800 | [diff] [blame] | 328 | std::ostream& operator<<(std::ostream& out, const DispatchEntry& entry) { |
Siarhei Vishniakou | d010b01 | 2023-01-18 15:00:53 -0800 | [diff] [blame] | 329 | std::string transform; |
| 330 | entry.transform.dump(transform, "transform"); |
Prabir Pradhan | 2a2da1d | 2023-11-03 02:16:20 +0000 | [diff] [blame] | 331 | out << "DispatchEntry{resolvedFlags=" << entry.resolvedFlags |
Siarhei Vishniakou | d010b01 | 2023-01-18 15:00:53 -0800 | [diff] [blame] | 332 | << ", targetFlags=" << entry.targetFlags.string() << ", transform=" << transform |
Siarhei Vishniakou | adb9fc9 | 2023-05-26 10:46:09 -0700 | [diff] [blame] | 333 | << "} original: " << entry.eventEntry->getDescription(); |
Siarhei Vishniakou | d010b01 | 2023-01-18 15:00:53 -0800 | [diff] [blame] | 334 | return out; |
| 335 | } |
| 336 | |
Garfield Tan | e84e6f9 | 2019-08-29 17:28:41 -0700 | [diff] [blame] | 337 | } // namespace android::inputdispatcher |