Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #define LOG_TAG "Input" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
chaviw | 09c8d2d | 2020-08-24 15:48:26 -0700 | [diff] [blame] | 20 | #include <attestation/HmacKeyManager.h> |
Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 21 | #include <cutils/compiler.h> |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 22 | #include <inttypes.h> |
Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 23 | #include <string.h> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 24 | |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 25 | #include <android-base/stringprintf.h> |
chaviw | 98318de | 2021-05-19 16:45:23 -0500 | [diff] [blame] | 26 | #include <gui/constants.h> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 27 | #include <input/Input.h> |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 28 | #include <input/InputDevice.h> |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 29 | #include <input/InputEventLabels.h> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 30 | |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 31 | #ifdef __linux__ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 32 | #include <binder/Parcel.h> |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 33 | #endif |
Brett Chabot | 5820852 | 2020-09-09 13:55:24 -0700 | [diff] [blame] | 34 | #ifdef __ANDROID__ |
Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 35 | #include <sys/random.h> |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 36 | #endif |
| 37 | |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 38 | using android::base::StringPrintf; |
| 39 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 42 | namespace { |
| 43 | |
| 44 | float transformAngle(const ui::Transform& transform, float angleRadians) { |
| 45 | // Construct and transform a vector oriented at the specified clockwise angle from vertical. |
| 46 | // Coordinate system: down is increasing Y, right is increasing X. |
| 47 | float x = sinf(angleRadians); |
| 48 | float y = -cosf(angleRadians); |
| 49 | vec2 transformedPoint = transform.transform(x, y); |
| 50 | |
| 51 | // Determine how the origin is transformed by the matrix so that we |
| 52 | // can transform orientation vectors. |
| 53 | const vec2 origin = transform.transform(0, 0); |
| 54 | |
| 55 | transformedPoint.x -= origin.x; |
| 56 | transformedPoint.y -= origin.y; |
| 57 | |
| 58 | // Derive the transformed vector's clockwise angle from vertical. |
Prabir Pradhan | d2b0267 | 2021-10-19 11:24:45 -0700 | [diff] [blame] | 59 | // The return value of atan2f is in range [-pi, pi] which conforms to the orientation API. |
| 60 | return atan2f(transformedPoint.x, -transformedPoint.y); |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 63 | vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy) { |
| 64 | const vec2 transformedXy = transform.transform(xy); |
Prabir Pradhan | 9f38881 | 2021-05-13 16:54:53 -0700 | [diff] [blame] | 65 | const vec2 transformedOrigin = transform.transform(0, 0); |
| 66 | return transformedXy - transformedOrigin; |
| 67 | } |
| 68 | |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 69 | bool shouldDisregardTranslation(uint32_t source) { |
Prabir Pradhan | 9f38881 | 2021-05-13 16:54:53 -0700 | [diff] [blame] | 70 | // Pointer events are the only type of events that refer to absolute coordinates on the display, |
| 71 | // so we should apply the entire window transform. For other types of events, we should make |
| 72 | // sure to not apply the window translation/offset. |
| 73 | return (source & AINPUT_SOURCE_CLASS_POINTER) == 0; |
| 74 | } |
| 75 | |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 76 | } // namespace |
| 77 | |
Siarhei Vishniakou | 16a2e30 | 2019-01-14 19:21:45 -0800 | [diff] [blame] | 78 | const char* motionClassificationToString(MotionClassification classification) { |
| 79 | switch (classification) { |
| 80 | case MotionClassification::NONE: |
| 81 | return "NONE"; |
| 82 | case MotionClassification::AMBIGUOUS_GESTURE: |
| 83 | return "AMBIGUOUS_GESTURE"; |
| 84 | case MotionClassification::DEEP_PRESS: |
| 85 | return "DEEP_PRESS"; |
| 86 | } |
| 87 | } |
| 88 | |
Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 89 | // --- IdGenerator --- |
| 90 | IdGenerator::IdGenerator(Source source) : mSource(source) {} |
| 91 | |
| 92 | int32_t IdGenerator::nextId() const { |
| 93 | constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK; |
| 94 | int32_t id = 0; |
| 95 | |
| 96 | // Avoid building against syscall getrandom(2) on host, which will fail build on Mac. Host doesn't |
| 97 | // use sequence number so just always return mSource. |
| 98 | #ifdef __ANDROID__ |
| 99 | constexpr size_t BUF_LEN = sizeof(id); |
| 100 | size_t totalBytes = 0; |
| 101 | while (totalBytes < BUF_LEN) { |
| 102 | ssize_t bytes = TEMP_FAILURE_RETRY(getrandom(&id, BUF_LEN, GRND_NONBLOCK)); |
| 103 | if (CC_UNLIKELY(bytes < 0)) { |
| 104 | ALOGW("Failed to fill in random number for sequence number: %s.", strerror(errno)); |
| 105 | id = 0; |
| 106 | break; |
| 107 | } |
| 108 | totalBytes += bytes; |
| 109 | } |
| 110 | #endif // __ANDROID__ |
| 111 | |
| 112 | return (id & SEQUENCE_NUMBER_MASK) | static_cast<int32_t>(mSource); |
| 113 | } |
| 114 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 115 | // --- InputEvent --- |
| 116 | |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 117 | const char* inputEventTypeToString(int32_t type) { |
| 118 | switch (type) { |
| 119 | case AINPUT_EVENT_TYPE_KEY: { |
| 120 | return "KEY"; |
| 121 | } |
| 122 | case AINPUT_EVENT_TYPE_MOTION: { |
| 123 | return "MOTION"; |
| 124 | } |
| 125 | case AINPUT_EVENT_TYPE_FOCUS: { |
| 126 | return "FOCUS"; |
| 127 | } |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 128 | case AINPUT_EVENT_TYPE_CAPTURE: { |
| 129 | return "CAPTURE"; |
| 130 | } |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 131 | case AINPUT_EVENT_TYPE_DRAG: { |
| 132 | return "DRAG"; |
| 133 | } |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 134 | case AINPUT_EVENT_TYPE_TOUCH_MODE: { |
| 135 | return "TOUCH_MODE"; |
| 136 | } |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 137 | } |
| 138 | return "UNKNOWN"; |
| 139 | } |
| 140 | |
Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 141 | VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) { |
| 142 | return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(), |
| 143 | event.getSource(), event.getDisplayId()}, |
| 144 | event.getAction(), |
| 145 | event.getDownTime(), |
| 146 | event.getFlags() & VERIFIED_KEY_EVENT_FLAGS, |
| 147 | event.getKeyCode(), |
| 148 | event.getScanCode(), |
| 149 | event.getMetaState(), |
| 150 | event.getRepeatCount()}; |
| 151 | } |
| 152 | |
| 153 | VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event) { |
| 154 | return {{VerifiedInputEvent::Type::MOTION, event.getDeviceId(), event.getEventTime(), |
| 155 | event.getSource(), event.getDisplayId()}, |
| 156 | event.getRawX(0), |
| 157 | event.getRawY(0), |
| 158 | event.getActionMasked(), |
| 159 | event.getDownTime(), |
| 160 | event.getFlags() & VERIFIED_MOTION_EVENT_FLAGS, |
| 161 | event.getMetaState(), |
| 162 | event.getButtonState()}; |
| 163 | } |
| 164 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 165 | void InputEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 166 | std::array<uint8_t, 32> hmac) { |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 167 | mId = id; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 168 | mDeviceId = deviceId; |
| 169 | mSource = source; |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 170 | mDisplayId = displayId; |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 171 | mHmac = hmac; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void InputEvent::initialize(const InputEvent& from) { |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 175 | mId = from.mId; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 176 | mDeviceId = from.mDeviceId; |
| 177 | mSource = from.mSource; |
Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 178 | mDisplayId = from.mDisplayId; |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 179 | mHmac = from.mHmac; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 182 | int32_t InputEvent::nextId() { |
| 183 | static IdGenerator idGen(IdGenerator::Source::OTHER); |
| 184 | return idGen.nextId(); |
| 185 | } |
| 186 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 187 | // --- KeyEvent --- |
| 188 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 189 | const char* KeyEvent::getLabel(int32_t keyCode) { |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 190 | return InputEventLookup::getLabelByKeyCode(keyCode); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 193 | int32_t KeyEvent::getKeyCodeFromLabel(const char* label) { |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 194 | return InputEventLookup::getKeyCodeByLabel(label); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 197 | void KeyEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 198 | std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, |
| 199 | int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount, |
| 200 | nsecs_t downTime, nsecs_t eventTime) { |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 201 | InputEvent::initialize(id, deviceId, source, displayId, hmac); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 202 | mAction = action; |
| 203 | mFlags = flags; |
| 204 | mKeyCode = keyCode; |
| 205 | mScanCode = scanCode; |
| 206 | mMetaState = metaState; |
| 207 | mRepeatCount = repeatCount; |
| 208 | mDownTime = downTime; |
| 209 | mEventTime = eventTime; |
| 210 | } |
| 211 | |
| 212 | void KeyEvent::initialize(const KeyEvent& from) { |
| 213 | InputEvent::initialize(from); |
| 214 | mAction = from.mAction; |
| 215 | mFlags = from.mFlags; |
| 216 | mKeyCode = from.mKeyCode; |
| 217 | mScanCode = from.mScanCode; |
| 218 | mMetaState = from.mMetaState; |
| 219 | mRepeatCount = from.mRepeatCount; |
| 220 | mDownTime = from.mDownTime; |
| 221 | mEventTime = from.mEventTime; |
| 222 | } |
| 223 | |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 224 | const char* KeyEvent::actionToString(int32_t action) { |
| 225 | // Convert KeyEvent action to string |
| 226 | switch (action) { |
| 227 | case AKEY_EVENT_ACTION_DOWN: |
| 228 | return "DOWN"; |
| 229 | case AKEY_EVENT_ACTION_UP: |
| 230 | return "UP"; |
| 231 | case AKEY_EVENT_ACTION_MULTIPLE: |
| 232 | return "MULTIPLE"; |
| 233 | } |
| 234 | return "UNKNOWN"; |
| 235 | } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 236 | |
| 237 | // --- PointerCoords --- |
| 238 | |
| 239 | float PointerCoords::getAxisValue(int32_t axis) const { |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 240 | if (axis < 0 || axis > 63 || !BitSet64::hasBit(bits, axis)){ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 241 | return 0; |
| 242 | } |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 243 | return values[BitSet64::getIndexOfBit(bits, axis)]; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | status_t PointerCoords::setAxisValue(int32_t axis, float value) { |
| 247 | if (axis < 0 || axis > 63) { |
| 248 | return NAME_NOT_FOUND; |
| 249 | } |
| 250 | |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 251 | uint32_t index = BitSet64::getIndexOfBit(bits, axis); |
| 252 | if (!BitSet64::hasBit(bits, axis)) { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 253 | if (value == 0) { |
| 254 | return OK; // axes with value 0 do not need to be stored |
| 255 | } |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 256 | |
| 257 | uint32_t count = BitSet64::count(bits); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 258 | if (count >= MAX_AXES) { |
| 259 | tooManyAxes(axis); |
| 260 | return NO_MEMORY; |
| 261 | } |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 262 | BitSet64::markBit(bits, axis); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 263 | for (uint32_t i = count; i > index; i--) { |
| 264 | values[i] = values[i - 1]; |
| 265 | } |
| 266 | } |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 267 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 268 | values[index] = value; |
| 269 | return OK; |
| 270 | } |
| 271 | |
| 272 | static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) { |
| 273 | float value = c.getAxisValue(axis); |
| 274 | if (value != 0) { |
| 275 | c.setAxisValue(axis, value * scaleFactor); |
| 276 | } |
| 277 | } |
| 278 | |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 279 | void PointerCoords::scale(float globalScaleFactor, float windowXScale, float windowYScale) { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 280 | // No need to scale pressure or size since they are normalized. |
| 281 | // No need to scale orientation since it is meaningless to do so. |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 282 | |
| 283 | // If there is a global scale factor, it is included in the windowX/YScale |
| 284 | // so we don't need to apply it twice to the X/Y axes. |
| 285 | // However we don't want to apply any windowXYScale not included in the global scale |
| 286 | // to the TOUCH_MAJOR/MINOR coordinates. |
| 287 | scaleAxisValue(*this, AMOTION_EVENT_AXIS_X, windowXScale); |
| 288 | scaleAxisValue(*this, AMOTION_EVENT_AXIS_Y, windowYScale); |
| 289 | scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MAJOR, globalScaleFactor); |
| 290 | scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MINOR, globalScaleFactor); |
| 291 | scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MAJOR, globalScaleFactor); |
| 292 | scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MINOR, globalScaleFactor); |
Prabir Pradhan | c652358 | 2021-05-14 18:02:55 -0700 | [diff] [blame] | 293 | scaleAxisValue(*this, AMOTION_EVENT_AXIS_RELATIVE_X, windowXScale); |
| 294 | scaleAxisValue(*this, AMOTION_EVENT_AXIS_RELATIVE_Y, windowYScale); |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 295 | } |
| 296 | |
Jeff Brown | f086ddb | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 297 | void PointerCoords::applyOffset(float xOffset, float yOffset) { |
| 298 | setAxisValue(AMOTION_EVENT_AXIS_X, getX() + xOffset); |
| 299 | setAxisValue(AMOTION_EVENT_AXIS_Y, getY() + yOffset); |
| 300 | } |
| 301 | |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 302 | #ifdef __linux__ |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 303 | status_t PointerCoords::readFromParcel(Parcel* parcel) { |
| 304 | bits = parcel->readInt64(); |
| 305 | |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 306 | uint32_t count = BitSet64::count(bits); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 307 | if (count > MAX_AXES) { |
| 308 | return BAD_VALUE; |
| 309 | } |
| 310 | |
| 311 | for (uint32_t i = 0; i < count; i++) { |
| 312 | values[i] = parcel->readFloat(); |
| 313 | } |
| 314 | return OK; |
| 315 | } |
| 316 | |
| 317 | status_t PointerCoords::writeToParcel(Parcel* parcel) const { |
| 318 | parcel->writeInt64(bits); |
| 319 | |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 320 | uint32_t count = BitSet64::count(bits); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 321 | for (uint32_t i = 0; i < count; i++) { |
| 322 | parcel->writeFloat(values[i]); |
| 323 | } |
| 324 | return OK; |
| 325 | } |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 326 | #endif |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 327 | |
| 328 | void PointerCoords::tooManyAxes(int axis) { |
| 329 | ALOGW("Could not set value for axis %d because the PointerCoords structure is full and " |
| 330 | "cannot contain more than %d axis values.", axis, int(MAX_AXES)); |
| 331 | } |
| 332 | |
| 333 | bool PointerCoords::operator==(const PointerCoords& other) const { |
| 334 | if (bits != other.bits) { |
| 335 | return false; |
| 336 | } |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 337 | uint32_t count = BitSet64::count(bits); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 338 | for (uint32_t i = 0; i < count; i++) { |
| 339 | if (values[i] != other.values[i]) { |
| 340 | return false; |
| 341 | } |
| 342 | } |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | void PointerCoords::copyFrom(const PointerCoords& other) { |
| 347 | bits = other.bits; |
Michael Wright | 38dcdff | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 348 | uint32_t count = BitSet64::count(bits); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 349 | for (uint32_t i = 0; i < count; i++) { |
| 350 | values[i] = other.values[i]; |
| 351 | } |
| 352 | } |
| 353 | |
chaviw | c01e137 | 2020-07-01 12:37:31 -0700 | [diff] [blame] | 354 | void PointerCoords::transform(const ui::Transform& transform) { |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 355 | const vec2 xy = transform.transform(getXYValue()); |
| 356 | setAxisValue(AMOTION_EVENT_AXIS_X, xy.x); |
| 357 | setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y); |
| 358 | |
Prabir Pradhan | c652358 | 2021-05-14 18:02:55 -0700 | [diff] [blame] | 359 | if (BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_RELATIVE_X) || |
| 360 | BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_RELATIVE_Y)) { |
| 361 | const ui::Transform rotation(transform.getOrientation()); |
| 362 | const vec2 relativeXy = rotation.transform(getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), |
| 363 | getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y)); |
| 364 | setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, relativeXy.x); |
| 365 | setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, relativeXy.y); |
| 366 | } |
| 367 | |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 368 | if (BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_ORIENTATION)) { |
| 369 | const float val = getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION); |
| 370 | setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, transformAngle(transform, val)); |
| 371 | } |
chaviw | c01e137 | 2020-07-01 12:37:31 -0700 | [diff] [blame] | 372 | } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 373 | |
| 374 | // --- PointerProperties --- |
| 375 | |
| 376 | bool PointerProperties::operator==(const PointerProperties& other) const { |
| 377 | return id == other.id |
| 378 | && toolType == other.toolType; |
| 379 | } |
| 380 | |
| 381 | void PointerProperties::copyFrom(const PointerProperties& other) { |
| 382 | id = other.id; |
| 383 | toolType = other.toolType; |
| 384 | } |
| 385 | |
| 386 | |
| 387 | // --- MotionEvent --- |
| 388 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 389 | void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 390 | std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, |
| 391 | int32_t flags, int32_t edgeFlags, int32_t metaState, |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 392 | int32_t buttonState, MotionClassification classification, |
| 393 | const ui::Transform& transform, float xPrecision, float yPrecision, |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 394 | float rawXCursorPosition, float rawYCursorPosition, |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 395 | const ui::Transform& rawTransform, nsecs_t downTime, nsecs_t eventTime, |
Evan Rosky | 0957669 | 2021-07-01 12:22:09 -0700 | [diff] [blame] | 396 | size_t pointerCount, const PointerProperties* pointerProperties, |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 397 | const PointerCoords* pointerCoords) { |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 398 | InputEvent::initialize(id, deviceId, source, displayId, hmac); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 399 | mAction = action; |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 400 | mActionButton = actionButton; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 401 | mFlags = flags; |
| 402 | mEdgeFlags = edgeFlags; |
| 403 | mMetaState = metaState; |
| 404 | mButtonState = buttonState; |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 405 | mClassification = classification; |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 406 | mTransform = transform; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 407 | mXPrecision = xPrecision; |
| 408 | mYPrecision = yPrecision; |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 409 | mRawXCursorPosition = rawXCursorPosition; |
| 410 | mRawYCursorPosition = rawYCursorPosition; |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 411 | mRawTransform = rawTransform; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 412 | mDownTime = downTime; |
| 413 | mPointerProperties.clear(); |
| 414 | mPointerProperties.appendArray(pointerProperties, pointerCount); |
| 415 | mSampleEventTimes.clear(); |
| 416 | mSamplePointerCoords.clear(); |
| 417 | addSample(eventTime, pointerCoords); |
| 418 | } |
| 419 | |
| 420 | void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) { |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 421 | InputEvent::initialize(other->mId, other->mDeviceId, other->mSource, other->mDisplayId, |
| 422 | other->mHmac); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 423 | mAction = other->mAction; |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 424 | mActionButton = other->mActionButton; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 425 | mFlags = other->mFlags; |
| 426 | mEdgeFlags = other->mEdgeFlags; |
| 427 | mMetaState = other->mMetaState; |
| 428 | mButtonState = other->mButtonState; |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 429 | mClassification = other->mClassification; |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 430 | mTransform = other->mTransform; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 431 | mXPrecision = other->mXPrecision; |
| 432 | mYPrecision = other->mYPrecision; |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 433 | mRawXCursorPosition = other->mRawXCursorPosition; |
| 434 | mRawYCursorPosition = other->mRawYCursorPosition; |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 435 | mRawTransform = other->mRawTransform; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 436 | mDownTime = other->mDownTime; |
| 437 | mPointerProperties = other->mPointerProperties; |
| 438 | |
| 439 | if (keepHistory) { |
| 440 | mSampleEventTimes = other->mSampleEventTimes; |
| 441 | mSamplePointerCoords = other->mSamplePointerCoords; |
| 442 | } else { |
| 443 | mSampleEventTimes.clear(); |
Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 444 | mSampleEventTimes.push_back(other->getEventTime()); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 445 | mSamplePointerCoords.clear(); |
| 446 | size_t pointerCount = other->getPointerCount(); |
| 447 | size_t historySize = other->getHistorySize(); |
| 448 | mSamplePointerCoords.appendArray(other->mSamplePointerCoords.array() |
| 449 | + (historySize * pointerCount), pointerCount); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | void MotionEvent::addSample( |
| 454 | int64_t eventTime, |
| 455 | const PointerCoords* pointerCoords) { |
Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 456 | mSampleEventTimes.push_back(eventTime); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 457 | mSamplePointerCoords.appendArray(pointerCoords, getPointerCount()); |
| 458 | } |
| 459 | |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 460 | float MotionEvent::getXCursorPosition() const { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 461 | vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition()); |
| 462 | return vals.x; |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | float MotionEvent::getYCursorPosition() const { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 466 | vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition()); |
| 467 | return vals.y; |
Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 468 | } |
| 469 | |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 470 | void MotionEvent::setCursorPosition(float x, float y) { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 471 | ui::Transform inverse = mTransform.inverse(); |
| 472 | vec2 vals = inverse.transform(x, y); |
| 473 | mRawXCursorPosition = vals.x; |
| 474 | mRawYCursorPosition = vals.y; |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 475 | } |
| 476 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 477 | const PointerCoords* MotionEvent::getRawPointerCoords(size_t pointerIndex) const { |
| 478 | return &mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex]; |
| 479 | } |
| 480 | |
| 481 | float MotionEvent::getRawAxisValue(int32_t axis, size_t pointerIndex) const { |
Evan Rosky | 84f07f0 | 2021-04-16 10:42:42 -0700 | [diff] [blame] | 482 | return getHistoricalRawAxisValue(axis, pointerIndex, getHistorySize()); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | float MotionEvent::getAxisValue(int32_t axis, size_t pointerIndex) const { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 486 | return getHistoricalAxisValue(axis, pointerIndex, getHistorySize()); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | const PointerCoords* MotionEvent::getHistoricalRawPointerCoords( |
| 490 | size_t pointerIndex, size_t historicalIndex) const { |
| 491 | return &mSamplePointerCoords[historicalIndex * getPointerCount() + pointerIndex]; |
| 492 | } |
| 493 | |
| 494 | float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex, |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 495 | size_t historicalIndex) const { |
Prabir Pradhan | 9eb02c0 | 2021-10-19 14:02:20 -0700 | [diff] [blame] | 496 | const PointerCoords& coords = *getHistoricalRawPointerCoords(pointerIndex, historicalIndex); |
| 497 | return calculateTransformedAxisValue(axis, mSource, mRawTransform, coords); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex, |
Prabir Pradhan | 9f38881 | 2021-05-13 16:54:53 -0700 | [diff] [blame] | 501 | size_t historicalIndex) const { |
Prabir Pradhan | 9eb02c0 | 2021-10-19 14:02:20 -0700 | [diff] [blame] | 502 | const PointerCoords& coords = *getHistoricalRawPointerCoords(pointerIndex, historicalIndex); |
| 503 | return calculateTransformedAxisValue(axis, mSource, mTransform, coords); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 504 | } |
| 505 | |
| 506 | ssize_t MotionEvent::findPointerIndex(int32_t pointerId) const { |
| 507 | size_t pointerCount = mPointerProperties.size(); |
| 508 | for (size_t i = 0; i < pointerCount; i++) { |
| 509 | if (mPointerProperties.itemAt(i).id == pointerId) { |
| 510 | return i; |
| 511 | } |
| 512 | } |
| 513 | return -1; |
| 514 | } |
| 515 | |
| 516 | void MotionEvent::offsetLocation(float xOffset, float yOffset) { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 517 | float currXOffset = mTransform.tx(); |
| 518 | float currYOffset = mTransform.ty(); |
| 519 | mTransform.set(currXOffset + xOffset, currYOffset + yOffset); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 522 | void MotionEvent::scale(float globalScaleFactor) { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 523 | mTransform.set(mTransform.tx() * globalScaleFactor, mTransform.ty() * globalScaleFactor); |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 524 | mRawTransform.set(mRawTransform.tx() * globalScaleFactor, |
| 525 | mRawTransform.ty() * globalScaleFactor); |
Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 526 | mXPrecision *= globalScaleFactor; |
| 527 | mYPrecision *= globalScaleFactor; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 528 | |
| 529 | size_t numSamples = mSamplePointerCoords.size(); |
| 530 | for (size_t i = 0; i < numSamples; i++) { |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 531 | mSamplePointerCoords.editItemAt(i).scale(globalScaleFactor, globalScaleFactor, |
| 532 | globalScaleFactor); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 536 | void MotionEvent::transform(const std::array<float, 9>& matrix) { |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 537 | // We want to preserve the raw axes values stored in the PointerCoords, so we just update the |
| 538 | // transform using the values passed in. |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 539 | ui::Transform newTransform; |
| 540 | newTransform.set(matrix); |
| 541 | mTransform = newTransform * mTransform; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Evan Rosky | d4d4d80 | 2021-05-03 20:12:21 -0700 | [diff] [blame] | 544 | void MotionEvent::applyTransform(const std::array<float, 9>& matrix) { |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 545 | ui::Transform transform; |
| 546 | transform.set(matrix); |
Evan Rosky | d4d4d80 | 2021-05-03 20:12:21 -0700 | [diff] [blame] | 547 | |
| 548 | // Apply the transformation to all samples. |
Prabir Pradhan | 6b38461 | 2021-05-14 16:56:25 -0700 | [diff] [blame] | 549 | std::for_each(mSamplePointerCoords.begin(), mSamplePointerCoords.end(), |
| 550 | [&transform](PointerCoords& c) { c.transform(transform); }); |
Prabir Pradhan | 4b19bd0 | 2021-06-01 17:34:59 -0700 | [diff] [blame] | 551 | |
| 552 | if (mRawXCursorPosition != AMOTION_EVENT_INVALID_CURSOR_POSITION && |
| 553 | mRawYCursorPosition != AMOTION_EVENT_INVALID_CURSOR_POSITION) { |
| 554 | const vec2 cursor = transform.transform(mRawXCursorPosition, mRawYCursorPosition); |
| 555 | mRawXCursorPosition = cursor.x; |
| 556 | mRawYCursorPosition = cursor.y; |
| 557 | } |
Evan Rosky | d4d4d80 | 2021-05-03 20:12:21 -0700 | [diff] [blame] | 558 | } |
| 559 | |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 560 | #ifdef __linux__ |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 561 | static status_t readFromParcel(ui::Transform& transform, const Parcel& parcel) { |
| 562 | float dsdx, dtdx, tx, dtdy, dsdy, ty; |
| 563 | status_t status = parcel.readFloat(&dsdx); |
| 564 | status |= parcel.readFloat(&dtdx); |
| 565 | status |= parcel.readFloat(&tx); |
| 566 | status |= parcel.readFloat(&dtdy); |
| 567 | status |= parcel.readFloat(&dsdy); |
| 568 | status |= parcel.readFloat(&ty); |
| 569 | |
| 570 | transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1}); |
| 571 | return status; |
| 572 | } |
| 573 | |
| 574 | static status_t writeToParcel(const ui::Transform& transform, Parcel& parcel) { |
| 575 | status_t status = parcel.writeFloat(transform.dsdx()); |
| 576 | status |= parcel.writeFloat(transform.dtdx()); |
| 577 | status |= parcel.writeFloat(transform.tx()); |
| 578 | status |= parcel.writeFloat(transform.dtdy()); |
| 579 | status |= parcel.writeFloat(transform.dsdy()); |
| 580 | status |= parcel.writeFloat(transform.ty()); |
| 581 | return status; |
| 582 | } |
| 583 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 584 | status_t MotionEvent::readFromParcel(Parcel* parcel) { |
| 585 | size_t pointerCount = parcel->readInt32(); |
| 586 | size_t sampleCount = parcel->readInt32(); |
Flanker | 552a8a5 | 2015-09-07 15:28:58 +0800 | [diff] [blame] | 587 | if (pointerCount == 0 || pointerCount > MAX_POINTERS || |
| 588 | sampleCount == 0 || sampleCount > MAX_SAMPLES) { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 589 | return BAD_VALUE; |
| 590 | } |
| 591 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 592 | mId = parcel->readInt32(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 593 | mDeviceId = parcel->readInt32(); |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 594 | mSource = parcel->readUint32(); |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 595 | mDisplayId = parcel->readInt32(); |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 596 | std::vector<uint8_t> hmac; |
| 597 | status_t result = parcel->readByteVector(&hmac); |
| 598 | if (result != OK || hmac.size() != 32) { |
| 599 | return BAD_VALUE; |
| 600 | } |
| 601 | std::move(hmac.begin(), hmac.begin() + hmac.size(), mHmac.begin()); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 602 | mAction = parcel->readInt32(); |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 603 | mActionButton = parcel->readInt32(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 604 | mFlags = parcel->readInt32(); |
| 605 | mEdgeFlags = parcel->readInt32(); |
| 606 | mMetaState = parcel->readInt32(); |
| 607 | mButtonState = parcel->readInt32(); |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 608 | mClassification = static_cast<MotionClassification>(parcel->readByte()); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 609 | |
| 610 | result = android::readFromParcel(mTransform, *parcel); |
| 611 | if (result != OK) { |
| 612 | return result; |
| 613 | } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 614 | mXPrecision = parcel->readFloat(); |
| 615 | mYPrecision = parcel->readFloat(); |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 616 | mRawXCursorPosition = parcel->readFloat(); |
| 617 | mRawYCursorPosition = parcel->readFloat(); |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 618 | |
| 619 | result = android::readFromParcel(mRawTransform, *parcel); |
| 620 | if (result != OK) { |
| 621 | return result; |
| 622 | } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 623 | mDownTime = parcel->readInt64(); |
| 624 | |
| 625 | mPointerProperties.clear(); |
| 626 | mPointerProperties.setCapacity(pointerCount); |
| 627 | mSampleEventTimes.clear(); |
Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 628 | mSampleEventTimes.reserve(sampleCount); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 629 | mSamplePointerCoords.clear(); |
| 630 | mSamplePointerCoords.setCapacity(sampleCount * pointerCount); |
| 631 | |
| 632 | for (size_t i = 0; i < pointerCount; i++) { |
| 633 | mPointerProperties.push(); |
| 634 | PointerProperties& properties = mPointerProperties.editTop(); |
| 635 | properties.id = parcel->readInt32(); |
| 636 | properties.toolType = parcel->readInt32(); |
| 637 | } |
| 638 | |
Dan Austin | c94fc45 | 2015-09-22 14:22:41 -0700 | [diff] [blame] | 639 | while (sampleCount > 0) { |
| 640 | sampleCount--; |
Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 641 | mSampleEventTimes.push_back(parcel->readInt64()); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 642 | for (size_t i = 0; i < pointerCount; i++) { |
| 643 | mSamplePointerCoords.push(); |
| 644 | status_t status = mSamplePointerCoords.editTop().readFromParcel(parcel); |
| 645 | if (status) { |
| 646 | return status; |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | return OK; |
| 651 | } |
| 652 | |
| 653 | status_t MotionEvent::writeToParcel(Parcel* parcel) const { |
| 654 | size_t pointerCount = mPointerProperties.size(); |
| 655 | size_t sampleCount = mSampleEventTimes.size(); |
| 656 | |
| 657 | parcel->writeInt32(pointerCount); |
| 658 | parcel->writeInt32(sampleCount); |
| 659 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 660 | parcel->writeInt32(mId); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 661 | parcel->writeInt32(mDeviceId); |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 662 | parcel->writeUint32(mSource); |
Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 663 | parcel->writeInt32(mDisplayId); |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 664 | std::vector<uint8_t> hmac(mHmac.begin(), mHmac.end()); |
| 665 | parcel->writeByteVector(hmac); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 666 | parcel->writeInt32(mAction); |
Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 667 | parcel->writeInt32(mActionButton); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 668 | parcel->writeInt32(mFlags); |
| 669 | parcel->writeInt32(mEdgeFlags); |
| 670 | parcel->writeInt32(mMetaState); |
| 671 | parcel->writeInt32(mButtonState); |
Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 672 | parcel->writeByte(static_cast<int8_t>(mClassification)); |
chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 673 | |
| 674 | status_t result = android::writeToParcel(mTransform, *parcel); |
| 675 | if (result != OK) { |
| 676 | return result; |
| 677 | } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 678 | parcel->writeFloat(mXPrecision); |
| 679 | parcel->writeFloat(mYPrecision); |
Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 680 | parcel->writeFloat(mRawXCursorPosition); |
| 681 | parcel->writeFloat(mRawYCursorPosition); |
Prabir Pradhan | b9b1850 | 2021-08-26 12:30:32 -0700 | [diff] [blame] | 682 | |
| 683 | result = android::writeToParcel(mRawTransform, *parcel); |
| 684 | if (result != OK) { |
| 685 | return result; |
| 686 | } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 687 | parcel->writeInt64(mDownTime); |
| 688 | |
| 689 | for (size_t i = 0; i < pointerCount; i++) { |
| 690 | const PointerProperties& properties = mPointerProperties.itemAt(i); |
| 691 | parcel->writeInt32(properties.id); |
| 692 | parcel->writeInt32(properties.toolType); |
| 693 | } |
| 694 | |
| 695 | const PointerCoords* pc = mSamplePointerCoords.array(); |
| 696 | for (size_t h = 0; h < sampleCount; h++) { |
Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 697 | parcel->writeInt64(mSampleEventTimes[h]); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 698 | for (size_t i = 0; i < pointerCount; i++) { |
| 699 | status_t status = (pc++)->writeToParcel(parcel); |
| 700 | if (status) { |
| 701 | return status; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | return OK; |
| 706 | } |
Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 707 | #endif |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 708 | |
Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 709 | bool MotionEvent::isTouchEvent(uint32_t source, int32_t action) { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 710 | if (source & AINPUT_SOURCE_CLASS_POINTER) { |
| 711 | // Specifically excludes HOVER_MOVE and SCROLL. |
| 712 | switch (action & AMOTION_EVENT_ACTION_MASK) { |
| 713 | case AMOTION_EVENT_ACTION_DOWN: |
| 714 | case AMOTION_EVENT_ACTION_MOVE: |
| 715 | case AMOTION_EVENT_ACTION_UP: |
| 716 | case AMOTION_EVENT_ACTION_POINTER_DOWN: |
| 717 | case AMOTION_EVENT_ACTION_POINTER_UP: |
| 718 | case AMOTION_EVENT_ACTION_CANCEL: |
| 719 | case AMOTION_EVENT_ACTION_OUTSIDE: |
| 720 | return true; |
| 721 | } |
| 722 | } |
| 723 | return false; |
| 724 | } |
| 725 | |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 726 | const char* MotionEvent::getLabel(int32_t axis) { |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 727 | return InputEventLookup::getAxisLabel(axis); |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | int32_t MotionEvent::getAxisFromLabel(const char* label) { |
Chris Ye | 4958d06 | 2020-08-20 13:21:10 -0700 | [diff] [blame] | 731 | return InputEventLookup::getAxisByLabel(label); |
Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 734 | std::string MotionEvent::actionToString(int32_t action) { |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 735 | // Convert MotionEvent action to string |
| 736 | switch (action & AMOTION_EVENT_ACTION_MASK) { |
| 737 | case AMOTION_EVENT_ACTION_DOWN: |
| 738 | return "DOWN"; |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 739 | case AMOTION_EVENT_ACTION_UP: |
| 740 | return "UP"; |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 741 | case AMOTION_EVENT_ACTION_MOVE: |
| 742 | return "MOVE"; |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 743 | case AMOTION_EVENT_ACTION_CANCEL: |
| 744 | return "CANCEL"; |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 745 | case AMOTION_EVENT_ACTION_OUTSIDE: |
| 746 | return "OUTSIDE"; |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 747 | case AMOTION_EVENT_ACTION_POINTER_DOWN: |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 748 | return StringPrintf("POINTER_DOWN(%" PRId32 ")", MotionEvent::getActionIndex(action)); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 749 | case AMOTION_EVENT_ACTION_POINTER_UP: |
Siarhei Vishniakou | ca20550 | 2021-07-16 21:31:58 +0000 | [diff] [blame] | 750 | return StringPrintf("POINTER_UP(%" PRId32 ")", MotionEvent::getActionIndex(action)); |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 751 | case AMOTION_EVENT_ACTION_HOVER_MOVE: |
| 752 | return "HOVER_MOVE"; |
| 753 | case AMOTION_EVENT_ACTION_SCROLL: |
| 754 | return "SCROLL"; |
| 755 | case AMOTION_EVENT_ACTION_HOVER_ENTER: |
| 756 | return "HOVER_ENTER"; |
| 757 | case AMOTION_EVENT_ACTION_HOVER_EXIT: |
| 758 | return "HOVER_EXIT"; |
| 759 | case AMOTION_EVENT_ACTION_BUTTON_PRESS: |
| 760 | return "BUTTON_PRESS"; |
| 761 | case AMOTION_EVENT_ACTION_BUTTON_RELEASE: |
| 762 | return "BUTTON_RELEASE"; |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 763 | } |
Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 764 | return android::base::StringPrintf("%" PRId32, action); |
Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 765 | } |
| 766 | |
Prabir Pradhan | b5cb957 | 2021-09-24 06:35:16 -0700 | [diff] [blame] | 767 | vec2 MotionEvent::calculateTransformedXY(uint32_t source, const ui::Transform& transform, |
| 768 | const vec2& xy) { |
| 769 | return shouldDisregardTranslation(source) ? transformWithoutTranslation(transform, xy) |
| 770 | : transform.transform(xy); |
| 771 | } |
| 772 | |
Prabir Pradhan | 9eb02c0 | 2021-10-19 14:02:20 -0700 | [diff] [blame] | 773 | float MotionEvent::calculateTransformedAxisValue(int32_t axis, uint32_t source, |
| 774 | const ui::Transform& transform, |
| 775 | const PointerCoords& coords) { |
| 776 | if (axis == AMOTION_EVENT_AXIS_X || axis == AMOTION_EVENT_AXIS_Y) { |
| 777 | const vec2 xy = calculateTransformedXY(source, transform, coords.getXYValue()); |
| 778 | static_assert(AMOTION_EVENT_AXIS_X == 0 && AMOTION_EVENT_AXIS_Y == 1); |
| 779 | return xy[axis]; |
| 780 | } |
| 781 | |
| 782 | if (axis == AMOTION_EVENT_AXIS_RELATIVE_X || axis == AMOTION_EVENT_AXIS_RELATIVE_Y) { |
| 783 | const vec2 relativeXy = |
| 784 | transformWithoutTranslation(transform, |
| 785 | {coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X), |
| 786 | coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y)}); |
| 787 | return axis == AMOTION_EVENT_AXIS_RELATIVE_X ? relativeXy.x : relativeXy.y; |
| 788 | } |
| 789 | |
| 790 | if (axis == AMOTION_EVENT_AXIS_ORIENTATION) { |
| 791 | return transformAngle(transform, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION)); |
| 792 | } |
| 793 | |
| 794 | return coords.getAxisValue(axis); |
| 795 | } |
| 796 | |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 797 | // --- FocusEvent --- |
| 798 | |
Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 799 | void FocusEvent::initialize(int32_t id, bool hasFocus, bool inTouchMode) { |
| 800 | InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, |
Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 801 | ADISPLAY_ID_NONE, INVALID_HMAC); |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 802 | mHasFocus = hasFocus; |
| 803 | mInTouchMode = inTouchMode; |
| 804 | } |
| 805 | |
| 806 | void FocusEvent::initialize(const FocusEvent& from) { |
| 807 | InputEvent::initialize(from); |
| 808 | mHasFocus = from.mHasFocus; |
| 809 | mInTouchMode = from.mInTouchMode; |
| 810 | } |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 811 | |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 812 | // --- CaptureEvent --- |
| 813 | |
| 814 | void CaptureEvent::initialize(int32_t id, bool pointerCaptureEnabled) { |
| 815 | InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, |
| 816 | ADISPLAY_ID_NONE, INVALID_HMAC); |
| 817 | mPointerCaptureEnabled = pointerCaptureEnabled; |
| 818 | } |
| 819 | |
| 820 | void CaptureEvent::initialize(const CaptureEvent& from) { |
| 821 | InputEvent::initialize(from); |
| 822 | mPointerCaptureEnabled = from.mPointerCaptureEnabled; |
| 823 | } |
| 824 | |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 825 | // --- DragEvent --- |
| 826 | |
| 827 | void DragEvent::initialize(int32_t id, float x, float y, bool isExiting) { |
| 828 | InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, |
| 829 | ADISPLAY_ID_NONE, INVALID_HMAC); |
| 830 | mIsExiting = isExiting; |
| 831 | mX = x; |
| 832 | mY = y; |
| 833 | } |
| 834 | |
| 835 | void DragEvent::initialize(const DragEvent& from) { |
| 836 | InputEvent::initialize(from); |
| 837 | mIsExiting = from.mIsExiting; |
| 838 | mX = from.mX; |
| 839 | mY = from.mY; |
| 840 | } |
| 841 | |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 842 | // --- TouchModeEvent --- |
| 843 | |
| 844 | void TouchModeEvent::initialize(int32_t id, bool isInTouchMode) { |
| 845 | InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN, |
| 846 | ADISPLAY_ID_NONE, INVALID_HMAC); |
| 847 | mIsInTouchMode = isInTouchMode; |
| 848 | } |
| 849 | |
| 850 | void TouchModeEvent::initialize(const TouchModeEvent& from) { |
| 851 | InputEvent::initialize(from); |
| 852 | mIsInTouchMode = from.mIsInTouchMode; |
| 853 | } |
| 854 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 855 | // --- PooledInputEventFactory --- |
| 856 | |
| 857 | PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) : |
| 858 | mMaxPoolSize(maxPoolSize) { |
| 859 | } |
| 860 | |
| 861 | PooledInputEventFactory::~PooledInputEventFactory() { |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | KeyEvent* PooledInputEventFactory::createKeyEvent() { |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 865 | if (mKeyEventPool.empty()) { |
| 866 | return new KeyEvent(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 867 | } |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 868 | KeyEvent* event = mKeyEventPool.front().release(); |
| 869 | mKeyEventPool.pop(); |
| 870 | return event; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | MotionEvent* PooledInputEventFactory::createMotionEvent() { |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 874 | if (mMotionEventPool.empty()) { |
| 875 | return new MotionEvent(); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 876 | } |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 877 | MotionEvent* event = mMotionEventPool.front().release(); |
| 878 | mMotionEventPool.pop(); |
| 879 | return event; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 882 | FocusEvent* PooledInputEventFactory::createFocusEvent() { |
| 883 | if (mFocusEventPool.empty()) { |
| 884 | return new FocusEvent(); |
| 885 | } |
| 886 | FocusEvent* event = mFocusEventPool.front().release(); |
| 887 | mFocusEventPool.pop(); |
| 888 | return event; |
| 889 | } |
| 890 | |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 891 | CaptureEvent* PooledInputEventFactory::createCaptureEvent() { |
| 892 | if (mCaptureEventPool.empty()) { |
| 893 | return new CaptureEvent(); |
| 894 | } |
| 895 | CaptureEvent* event = mCaptureEventPool.front().release(); |
| 896 | mCaptureEventPool.pop(); |
| 897 | return event; |
| 898 | } |
| 899 | |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 900 | DragEvent* PooledInputEventFactory::createDragEvent() { |
| 901 | if (mDragEventPool.empty()) { |
| 902 | return new DragEvent(); |
| 903 | } |
| 904 | DragEvent* event = mDragEventPool.front().release(); |
| 905 | mDragEventPool.pop(); |
| 906 | return event; |
| 907 | } |
| 908 | |
Antonio Kantek | 7cdf8ef | 2021-07-13 18:04:53 -0700 | [diff] [blame] | 909 | TouchModeEvent* PooledInputEventFactory::createTouchModeEvent() { |
| 910 | if (mTouchModeEventPool.empty()) { |
| 911 | return new TouchModeEvent(); |
| 912 | } |
| 913 | TouchModeEvent* event = mTouchModeEventPool.front().release(); |
| 914 | mTouchModeEventPool.pop(); |
| 915 | return event; |
| 916 | } |
| 917 | |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 918 | void PooledInputEventFactory::recycle(InputEvent* event) { |
| 919 | switch (event->getType()) { |
| 920 | case AINPUT_EVENT_TYPE_KEY: |
| 921 | if (mKeyEventPool.size() < mMaxPoolSize) { |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 922 | mKeyEventPool.push(std::unique_ptr<KeyEvent>(static_cast<KeyEvent*>(event))); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 923 | return; |
| 924 | } |
| 925 | break; |
| 926 | case AINPUT_EVENT_TYPE_MOTION: |
| 927 | if (mMotionEventPool.size() < mMaxPoolSize) { |
Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 928 | mMotionEventPool.push(std::unique_ptr<MotionEvent>(static_cast<MotionEvent*>(event))); |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 929 | return; |
| 930 | } |
| 931 | break; |
Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 932 | case AINPUT_EVENT_TYPE_FOCUS: |
| 933 | if (mFocusEventPool.size() < mMaxPoolSize) { |
| 934 | mFocusEventPool.push(std::unique_ptr<FocusEvent>(static_cast<FocusEvent*>(event))); |
| 935 | return; |
| 936 | } |
| 937 | break; |
Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 938 | case AINPUT_EVENT_TYPE_CAPTURE: |
| 939 | if (mCaptureEventPool.size() < mMaxPoolSize) { |
| 940 | mCaptureEventPool.push( |
| 941 | std::unique_ptr<CaptureEvent>(static_cast<CaptureEvent*>(event))); |
| 942 | return; |
| 943 | } |
| 944 | break; |
arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 945 | case AINPUT_EVENT_TYPE_DRAG: |
| 946 | if (mDragEventPool.size() < mMaxPoolSize) { |
| 947 | mDragEventPool.push(std::unique_ptr<DragEvent>(static_cast<DragEvent*>(event))); |
| 948 | return; |
| 949 | } |
| 950 | break; |
Antonio Kantek | eb4a30c | 2021-09-28 17:49:49 -0700 | [diff] [blame] | 951 | case AINPUT_EVENT_TYPE_TOUCH_MODE: |
| 952 | if (mTouchModeEventPool.size() < mMaxPoolSize) { |
| 953 | mTouchModeEventPool.push( |
| 954 | std::unique_ptr<TouchModeEvent>(static_cast<TouchModeEvent*>(event))); |
| 955 | return; |
| 956 | } |
| 957 | break; |
Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 958 | } |
| 959 | delete event; |
| 960 | } |
| 961 | |
| 962 | } // namespace android |