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