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