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