blob: c356c2e5e9fe8a1b1d766290a686c5e5be3ddb22 [file] [log] [blame]
Jeff Brown5912f952013-07-01 19:10:31 -07001/*
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
chaviw09c8d2d2020-08-24 15:48:26 -070020#include <attestation/HmacKeyManager.h>
Garfield Tan84b087e2020-01-23 10:49:05 -080021#include <cutils/compiler.h>
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -050022#include <inttypes.h>
Garfield Tan84b087e2020-01-23 10:49:05 -080023#include <string.h>
Michael Wright635422b2022-12-02 00:43:56 +000024#include <optional>
Jeff Brown5912f952013-07-01 19:10:31 -070025
Siarhei Vishniakou31977182022-09-30 08:51:23 -070026#include <android-base/file.h>
Siarhei Vishniakou4ded0b02022-05-26 00:36:48 +000027#include <android-base/logging.h>
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -050028#include <android-base/stringprintf.h>
Siarhei Vishniakou4ded0b02022-05-26 00:36:48 +000029#include <cutils/compiler.h>
chaviw98318de2021-05-19 16:45:23 -050030#include <gui/constants.h>
Prabir Pradhan092f3a92021-11-25 10:53:27 -080031#include <input/DisplayViewport.h>
Jeff Brown5912f952013-07-01 19:10:31 -070032#include <input/Input.h>
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -080033#include <input/InputDevice.h>
Michael Wright872db4f2014-04-22 15:03:51 -070034#include <input/InputEventLabels.h>
Jeff Brown5912f952013-07-01 19:10:31 -070035
Brett Chabotfaa986c2020-11-04 17:39:36 -080036#ifdef __linux__
Jeff Brown5912f952013-07-01 19:10:31 -070037#include <binder/Parcel.h>
Brett Chabotfaa986c2020-11-04 17:39:36 -080038#endif
Siarhei Vishniakou63740b92022-10-20 10:28:08 -070039#if defined(__ANDROID__)
40#include <sys/random.h>
41#endif
Jeff Brown5912f952013-07-01 19:10:31 -070042
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -050043using android::base::StringPrintf;
44
Jeff Brown5912f952013-07-01 19:10:31 -070045namespace android {
46
Prabir Pradhan6b384612021-05-14 16:56:25 -070047namespace {
48
Prabir Pradhan7e1ee562021-10-26 10:19:49 -070049bool shouldDisregardTransformation(uint32_t source) {
Prabir Pradhan258e2b92022-06-24 18:37:04 +000050 // Do not apply any transformations to axes from joysticks, touchpads, or relative mice.
Prabir Pradhan7e1ee562021-10-26 10:19:49 -070051 return isFromSource(source, AINPUT_SOURCE_CLASS_JOYSTICK) ||
Prabir Pradhan258e2b92022-06-24 18:37:04 +000052 isFromSource(source, AINPUT_SOURCE_CLASS_POSITION) ||
53 isFromSource(source, AINPUT_SOURCE_MOUSE_RELATIVE);
Prabir Pradhan7e1ee562021-10-26 10:19:49 -070054}
55
56bool shouldDisregardOffset(uint32_t source) {
Prabir Pradhan9f388812021-05-13 16:54:53 -070057 // Pointer events are the only type of events that refer to absolute coordinates on the display,
58 // so we should apply the entire window transform. For other types of events, we should make
59 // sure to not apply the window translation/offset.
Prabir Pradhan7e1ee562021-10-26 10:19:49 -070060 return !isFromSource(source, AINPUT_SOURCE_CLASS_POINTER);
Prabir Pradhan9f388812021-05-13 16:54:53 -070061}
62
Prabir Pradhan6b384612021-05-14 16:56:25 -070063} // namespace
64
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -080065const char* motionClassificationToString(MotionClassification classification) {
66 switch (classification) {
67 case MotionClassification::NONE:
68 return "NONE";
69 case MotionClassification::AMBIGUOUS_GESTURE:
70 return "AMBIGUOUS_GESTURE";
71 case MotionClassification::DEEP_PRESS:
72 return "DEEP_PRESS";
Harry Cutts2800fb02022-09-15 13:49:23 +000073 case MotionClassification::TWO_FINGER_SWIPE:
74 return "TWO_FINGER_SWIPE";
Harry Cuttsc5748d12022-12-02 17:30:18 +000075 case MotionClassification::MULTI_FINGER_SWIPE:
76 return "MULTI_FINGER_SWIPE";
Harry Cuttsb1e83552022-12-20 11:02:26 +000077 case MotionClassification::PINCH:
78 return "PINCH";
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -080079 }
80}
81
Siarhei Vishniakoud5fe5182022-07-20 23:28:40 +000082const char* motionToolTypeToString(int32_t toolType) {
83 switch (toolType) {
84 case AMOTION_EVENT_TOOL_TYPE_UNKNOWN:
85 return "UNKNOWN";
86 case AMOTION_EVENT_TOOL_TYPE_FINGER:
87 return "FINGER";
88 case AMOTION_EVENT_TOOL_TYPE_STYLUS:
89 return "STYLUS";
90 case AMOTION_EVENT_TOOL_TYPE_MOUSE:
91 return "MOUSE";
92 case AMOTION_EVENT_TOOL_TYPE_ERASER:
93 return "ERASER";
94 case AMOTION_EVENT_TOOL_TYPE_PALM:
95 return "PALM";
96 default:
97 return "INVALID";
98 }
99}
100
Garfield Tan84b087e2020-01-23 10:49:05 -0800101// --- IdGenerator ---
Siarhei Vishniakou63740b92022-10-20 10:28:08 -0700102#if defined(__ANDROID__)
103[[maybe_unused]]
104#endif
105static status_t
106getRandomBytes(uint8_t* data, size_t size) {
Siarhei Vishniakou31977182022-09-30 08:51:23 -0700107 int ret = TEMP_FAILURE_RETRY(open("/dev/urandom", O_RDONLY | O_CLOEXEC | O_NOFOLLOW));
108 if (ret == -1) {
109 return -errno;
110 }
111
112 base::unique_fd fd(ret);
113 if (!base::ReadFully(fd, data, size)) {
114 return -errno;
115 }
116 return OK;
117}
118
Garfield Tan84b087e2020-01-23 10:49:05 -0800119IdGenerator::IdGenerator(Source source) : mSource(source) {}
120
121int32_t IdGenerator::nextId() const {
122 constexpr uint32_t SEQUENCE_NUMBER_MASK = ~SOURCE_MASK;
123 int32_t id = 0;
124
Siarhei Vishniakou63740b92022-10-20 10:28:08 -0700125#if defined(__ANDROID__)
126 // On device, prefer 'getrandom' to '/dev/urandom' because it's faster.
127 constexpr size_t BUF_LEN = sizeof(id);
128 size_t totalBytes = 0;
129 while (totalBytes < BUF_LEN) {
130 ssize_t bytes = TEMP_FAILURE_RETRY(getrandom(&id, BUF_LEN, GRND_NONBLOCK));
131 if (CC_UNLIKELY(bytes < 0)) {
132 ALOGW("Failed to fill in random number for sequence number: %s.", strerror(errno));
133 id = 0;
134 break;
135 }
136 totalBytes += bytes;
137 }
138#else
Siarhei Vishniakou31977182022-09-30 08:51:23 -0700139#if defined(__linux__)
Siarhei Vishniakou63740b92022-10-20 10:28:08 -0700140 // On host, <sys/random.h> / GRND_NONBLOCK is not available
Siarhei Vishniakou31977182022-09-30 08:51:23 -0700141 while (true) {
142 status_t result = getRandomBytes(reinterpret_cast<uint8_t*>(&id), sizeof(id));
143 if (result == OK) {
Garfield Tan84b087e2020-01-23 10:49:05 -0800144 break;
145 }
Garfield Tan84b087e2020-01-23 10:49:05 -0800146 }
Siarhei Vishniakou31977182022-09-30 08:51:23 -0700147#endif // __linux__
Siarhei Vishniakou63740b92022-10-20 10:28:08 -0700148#endif // __ANDROID__
Garfield Tan84b087e2020-01-23 10:49:05 -0800149 return (id & SEQUENCE_NUMBER_MASK) | static_cast<int32_t>(mSource);
150}
151
Jeff Brown5912f952013-07-01 19:10:31 -0700152// --- InputEvent ---
153
Prabir Pradhande69f8a2021-11-18 16:40:34 +0000154vec2 transformWithoutTranslation(const ui::Transform& transform, const vec2& xy) {
155 const vec2 transformedXy = transform.transform(xy);
156 const vec2 transformedOrigin = transform.transform(0, 0);
157 return transformedXy - transformedOrigin;
158}
159
Prabir Pradhane2e10b42022-11-17 20:59:36 +0000160float transformAngle(const ui::Transform& transform, float angleRadians) {
161 // Construct and transform a vector oriented at the specified clockwise angle from vertical.
162 // Coordinate system: down is increasing Y, right is increasing X.
163 float x = sinf(angleRadians);
164 float y = -cosf(angleRadians);
165 vec2 transformedPoint = transform.transform(x, y);
166
167 // Determine how the origin is transformed by the matrix so that we
168 // can transform orientation vectors.
169 const vec2 origin = transform.transform(0, 0);
170
171 transformedPoint.x -= origin.x;
172 transformedPoint.y -= origin.y;
173
174 // Derive the transformed vector's clockwise angle from vertical.
175 // The return value of atan2f is in range [-pi, pi] which conforms to the orientation API.
176 return atan2f(transformedPoint.x, -transformedPoint.y);
177}
178
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800179const char* inputEventTypeToString(int32_t type) {
180 switch (type) {
181 case AINPUT_EVENT_TYPE_KEY: {
182 return "KEY";
183 }
184 case AINPUT_EVENT_TYPE_MOTION: {
185 return "MOTION";
186 }
187 case AINPUT_EVENT_TYPE_FOCUS: {
188 return "FOCUS";
189 }
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800190 case AINPUT_EVENT_TYPE_CAPTURE: {
191 return "CAPTURE";
192 }
arthurhung7632c332020-12-30 16:58:01 +0800193 case AINPUT_EVENT_TYPE_DRAG: {
194 return "DRAG";
195 }
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -0700196 case AINPUT_EVENT_TYPE_TOUCH_MODE: {
197 return "TOUCH_MODE";
198 }
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800199 }
200 return "UNKNOWN";
201}
202
Siarhei Vishniakoud9489572021-11-12 20:08:38 -0800203std::string inputEventSourceToString(int32_t source) {
204 if (source == AINPUT_SOURCE_UNKNOWN) {
205 return "UNKNOWN";
206 }
207 if (source == static_cast<int32_t>(AINPUT_SOURCE_ANY)) {
208 return "ANY";
209 }
210 static const std::map<int32_t, const char*> SOURCES{
211 {AINPUT_SOURCE_KEYBOARD, "KEYBOARD"},
212 {AINPUT_SOURCE_DPAD, "DPAD"},
213 {AINPUT_SOURCE_GAMEPAD, "GAMEPAD"},
214 {AINPUT_SOURCE_TOUCHSCREEN, "TOUCHSCREEN"},
215 {AINPUT_SOURCE_MOUSE, "MOUSE"},
216 {AINPUT_SOURCE_STYLUS, "STYLUS"},
217 {AINPUT_SOURCE_BLUETOOTH_STYLUS, "BLUETOOTH_STYLUS"},
218 {AINPUT_SOURCE_TRACKBALL, "TRACKBALL"},
219 {AINPUT_SOURCE_MOUSE_RELATIVE, "MOUSE_RELATIVE"},
220 {AINPUT_SOURCE_TOUCHPAD, "TOUCHPAD"},
221 {AINPUT_SOURCE_TOUCH_NAVIGATION, "TOUCH_NAVIGATION"},
222 {AINPUT_SOURCE_JOYSTICK, "JOYSTICK"},
223 {AINPUT_SOURCE_HDMI, "HDMI"},
224 {AINPUT_SOURCE_SENSOR, "SENSOR"},
225 {AINPUT_SOURCE_ROTARY_ENCODER, "ROTARY_ENCODER"},
226 };
227 std::string result;
228 for (const auto& [source_entry, str] : SOURCES) {
229 if ((source & source_entry) == source_entry) {
230 if (!result.empty()) {
231 result += " | ";
232 }
233 result += str;
234 }
235 }
236 if (result.empty()) {
237 result = StringPrintf("0x%08x", source);
238 }
239 return result;
240}
241
242bool isFromSource(uint32_t source, uint32_t test) {
243 return (source & test) == test;
244}
245
Prabir Pradhane5626962022-10-27 20:30:53 +0000246bool isStylusToolType(uint32_t toolType) {
247 return toolType == AMOTION_EVENT_TOOL_TYPE_STYLUS || toolType == AMOTION_EVENT_TOOL_TYPE_ERASER;
248}
249
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800250VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) {
251 return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(),
252 event.getSource(), event.getDisplayId()},
253 event.getAction(),
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800254 event.getFlags() & VERIFIED_KEY_EVENT_FLAGS,
Siarhei Vishniakouf355bf92021-12-09 10:43:21 -0800255 event.getDownTime(),
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800256 event.getKeyCode(),
257 event.getScanCode(),
258 event.getMetaState(),
259 event.getRepeatCount()};
260}
261
262VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event) {
263 return {{VerifiedInputEvent::Type::MOTION, event.getDeviceId(), event.getEventTime(),
264 event.getSource(), event.getDisplayId()},
265 event.getRawX(0),
266 event.getRawY(0),
267 event.getActionMasked(),
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800268 event.getFlags() & VERIFIED_MOTION_EVENT_FLAGS,
Siarhei Vishniakouf355bf92021-12-09 10:43:21 -0800269 event.getDownTime(),
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800270 event.getMetaState(),
271 event.getButtonState()};
272}
273
Garfield Tan4cc839f2020-01-24 11:26:14 -0800274void InputEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600275 std::array<uint8_t, 32> hmac) {
Garfield Tan4cc839f2020-01-24 11:26:14 -0800276 mId = id;
Jeff Brown5912f952013-07-01 19:10:31 -0700277 mDeviceId = deviceId;
278 mSource = source;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100279 mDisplayId = displayId;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600280 mHmac = hmac;
Jeff Brown5912f952013-07-01 19:10:31 -0700281}
282
283void InputEvent::initialize(const InputEvent& from) {
Garfield Tan4cc839f2020-01-24 11:26:14 -0800284 mId = from.mId;
Jeff Brown5912f952013-07-01 19:10:31 -0700285 mDeviceId = from.mDeviceId;
286 mSource = from.mSource;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100287 mDisplayId = from.mDisplayId;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600288 mHmac = from.mHmac;
Jeff Brown5912f952013-07-01 19:10:31 -0700289}
290
Garfield Tan4cc839f2020-01-24 11:26:14 -0800291int32_t InputEvent::nextId() {
292 static IdGenerator idGen(IdGenerator::Source::OTHER);
293 return idGen.nextId();
294}
295
Jeff Brown5912f952013-07-01 19:10:31 -0700296// --- KeyEvent ---
297
Michael Wright872db4f2014-04-22 15:03:51 -0700298const char* KeyEvent::getLabel(int32_t keyCode) {
Chris Ye4958d062020-08-20 13:21:10 -0700299 return InputEventLookup::getLabelByKeyCode(keyCode);
Jeff Brown5912f952013-07-01 19:10:31 -0700300}
301
Michael Wright872db4f2014-04-22 15:03:51 -0700302int32_t KeyEvent::getKeyCodeFromLabel(const char* label) {
Chris Ye4958d062020-08-20 13:21:10 -0700303 return InputEventLookup::getKeyCodeByLabel(label);
Jeff Brown5912f952013-07-01 19:10:31 -0700304}
305
Garfield Tan4cc839f2020-01-24 11:26:14 -0800306void KeyEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600307 std::array<uint8_t, 32> hmac, int32_t action, int32_t flags,
308 int32_t keyCode, int32_t scanCode, int32_t metaState, int32_t repeatCount,
309 nsecs_t downTime, nsecs_t eventTime) {
Garfield Tan4cc839f2020-01-24 11:26:14 -0800310 InputEvent::initialize(id, deviceId, source, displayId, hmac);
Jeff Brown5912f952013-07-01 19:10:31 -0700311 mAction = action;
312 mFlags = flags;
313 mKeyCode = keyCode;
314 mScanCode = scanCode;
315 mMetaState = metaState;
316 mRepeatCount = repeatCount;
317 mDownTime = downTime;
318 mEventTime = eventTime;
319}
320
321void KeyEvent::initialize(const KeyEvent& from) {
322 InputEvent::initialize(from);
323 mAction = from.mAction;
324 mFlags = from.mFlags;
325 mKeyCode = from.mKeyCode;
326 mScanCode = from.mScanCode;
327 mMetaState = from.mMetaState;
328 mRepeatCount = from.mRepeatCount;
329 mDownTime = from.mDownTime;
330 mEventTime = from.mEventTime;
331}
332
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700333const char* KeyEvent::actionToString(int32_t action) {
334 // Convert KeyEvent action to string
335 switch (action) {
336 case AKEY_EVENT_ACTION_DOWN:
337 return "DOWN";
338 case AKEY_EVENT_ACTION_UP:
339 return "UP";
340 case AKEY_EVENT_ACTION_MULTIPLE:
341 return "MULTIPLE";
342 }
343 return "UNKNOWN";
344}
Jeff Brown5912f952013-07-01 19:10:31 -0700345
Siarhei Vishniakoud010b012023-01-18 15:00:53 -0800346std::ostream& operator<<(std::ostream& out, const KeyEvent& event) {
347 out << "KeyEvent { action=" << KeyEvent::actionToString(event.getAction());
348
349 out << ", keycode=" << event.getKeyCode() << "(" << KeyEvent::getLabel(event.getKeyCode())
350 << ")";
351
352 if (event.getMetaState() != 0) {
353 out << ", metaState=" << event.getMetaState();
354 }
355
356 out << ", eventTime=" << event.getEventTime();
357 out << ", downTime=" << event.getDownTime();
358 out << ", flags=" << std::hex << event.getFlags() << std::dec;
359 out << ", repeatCount=" << event.getRepeatCount();
360 out << ", deviceId=" << event.getDeviceId();
361 out << ", source=" << inputEventSourceToString(event.getSource());
362 out << ", displayId=" << event.getDisplayId();
363 out << ", eventId=" << event.getId();
364 out << "}";
365 return out;
366}
367
Jeff Brown5912f952013-07-01 19:10:31 -0700368// --- PointerCoords ---
369
370float PointerCoords::getAxisValue(int32_t axis) const {
Michael Wright38dcdff2014-03-19 12:06:10 -0700371 if (axis < 0 || axis > 63 || !BitSet64::hasBit(bits, axis)){
Jeff Brown5912f952013-07-01 19:10:31 -0700372 return 0;
373 }
Michael Wright38dcdff2014-03-19 12:06:10 -0700374 return values[BitSet64::getIndexOfBit(bits, axis)];
Jeff Brown5912f952013-07-01 19:10:31 -0700375}
376
377status_t PointerCoords::setAxisValue(int32_t axis, float value) {
378 if (axis < 0 || axis > 63) {
379 return NAME_NOT_FOUND;
380 }
381
Michael Wright38dcdff2014-03-19 12:06:10 -0700382 uint32_t index = BitSet64::getIndexOfBit(bits, axis);
383 if (!BitSet64::hasBit(bits, axis)) {
Jeff Brown5912f952013-07-01 19:10:31 -0700384 if (value == 0) {
385 return OK; // axes with value 0 do not need to be stored
386 }
Michael Wright38dcdff2014-03-19 12:06:10 -0700387
388 uint32_t count = BitSet64::count(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700389 if (count >= MAX_AXES) {
390 tooManyAxes(axis);
391 return NO_MEMORY;
392 }
Michael Wright38dcdff2014-03-19 12:06:10 -0700393 BitSet64::markBit(bits, axis);
Jeff Brown5912f952013-07-01 19:10:31 -0700394 for (uint32_t i = count; i > index; i--) {
395 values[i] = values[i - 1];
396 }
397 }
Michael Wright38dcdff2014-03-19 12:06:10 -0700398
Jeff Brown5912f952013-07-01 19:10:31 -0700399 values[index] = value;
400 return OK;
401}
402
403static inline void scaleAxisValue(PointerCoords& c, int axis, float scaleFactor) {
404 float value = c.getAxisValue(axis);
405 if (value != 0) {
406 c.setAxisValue(axis, value * scaleFactor);
407 }
408}
409
Robert Carre07e1032018-11-26 12:55:53 -0800410void PointerCoords::scale(float globalScaleFactor, float windowXScale, float windowYScale) {
Jeff Brown5912f952013-07-01 19:10:31 -0700411 // No need to scale pressure or size since they are normalized.
412 // No need to scale orientation since it is meaningless to do so.
Robert Carre07e1032018-11-26 12:55:53 -0800413
414 // If there is a global scale factor, it is included in the windowX/YScale
415 // so we don't need to apply it twice to the X/Y axes.
416 // However we don't want to apply any windowXYScale not included in the global scale
417 // to the TOUCH_MAJOR/MINOR coordinates.
418 scaleAxisValue(*this, AMOTION_EVENT_AXIS_X, windowXScale);
419 scaleAxisValue(*this, AMOTION_EVENT_AXIS_Y, windowYScale);
420 scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MAJOR, globalScaleFactor);
421 scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOUCH_MINOR, globalScaleFactor);
422 scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MAJOR, globalScaleFactor);
423 scaleAxisValue(*this, AMOTION_EVENT_AXIS_TOOL_MINOR, globalScaleFactor);
Prabir Pradhanc6523582021-05-14 18:02:55 -0700424 scaleAxisValue(*this, AMOTION_EVENT_AXIS_RELATIVE_X, windowXScale);
425 scaleAxisValue(*this, AMOTION_EVENT_AXIS_RELATIVE_Y, windowYScale);
Robert Carre07e1032018-11-26 12:55:53 -0800426}
427
Brett Chabotfaa986c2020-11-04 17:39:36 -0800428#ifdef __linux__
Jeff Brown5912f952013-07-01 19:10:31 -0700429status_t PointerCoords::readFromParcel(Parcel* parcel) {
430 bits = parcel->readInt64();
431
Michael Wright38dcdff2014-03-19 12:06:10 -0700432 uint32_t count = BitSet64::count(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700433 if (count > MAX_AXES) {
434 return BAD_VALUE;
435 }
436
437 for (uint32_t i = 0; i < count; i++) {
438 values[i] = parcel->readFloat();
439 }
Philip Quinnafb31282022-12-20 18:17:55 -0800440
441 isResampled = parcel->readBool();
Jeff Brown5912f952013-07-01 19:10:31 -0700442 return OK;
443}
444
445status_t PointerCoords::writeToParcel(Parcel* parcel) const {
446 parcel->writeInt64(bits);
447
Michael Wright38dcdff2014-03-19 12:06:10 -0700448 uint32_t count = BitSet64::count(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700449 for (uint32_t i = 0; i < count; i++) {
450 parcel->writeFloat(values[i]);
451 }
Philip Quinnafb31282022-12-20 18:17:55 -0800452
453 parcel->writeBool(isResampled);
Jeff Brown5912f952013-07-01 19:10:31 -0700454 return OK;
455}
Brett Chabotfaa986c2020-11-04 17:39:36 -0800456#endif
Jeff Brown5912f952013-07-01 19:10:31 -0700457
458void PointerCoords::tooManyAxes(int axis) {
459 ALOGW("Could not set value for axis %d because the PointerCoords structure is full and "
460 "cannot contain more than %d axis values.", axis, int(MAX_AXES));
461}
462
463bool PointerCoords::operator==(const PointerCoords& other) const {
464 if (bits != other.bits) {
465 return false;
466 }
Michael Wright38dcdff2014-03-19 12:06:10 -0700467 uint32_t count = BitSet64::count(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700468 for (uint32_t i = 0; i < count; i++) {
469 if (values[i] != other.values[i]) {
470 return false;
471 }
472 }
Philip Quinnafb31282022-12-20 18:17:55 -0800473 if (isResampled != other.isResampled) {
474 return false;
475 }
Jeff Brown5912f952013-07-01 19:10:31 -0700476 return true;
477}
478
chaviwc01e1372020-07-01 12:37:31 -0700479void PointerCoords::transform(const ui::Transform& transform) {
Prabir Pradhan6b384612021-05-14 16:56:25 -0700480 const vec2 xy = transform.transform(getXYValue());
481 setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
482 setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
483
Prabir Pradhanc6523582021-05-14 18:02:55 -0700484 if (BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_RELATIVE_X) ||
485 BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_RELATIVE_Y)) {
486 const ui::Transform rotation(transform.getOrientation());
487 const vec2 relativeXy = rotation.transform(getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X),
488 getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y));
489 setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, relativeXy.x);
490 setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, relativeXy.y);
491 }
492
Prabir Pradhan6b384612021-05-14 16:56:25 -0700493 if (BitSet64::hasBit(bits, AMOTION_EVENT_AXIS_ORIENTATION)) {
494 const float val = getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION);
495 setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, transformAngle(transform, val));
496 }
chaviwc01e1372020-07-01 12:37:31 -0700497}
Jeff Brown5912f952013-07-01 19:10:31 -0700498
499// --- PointerProperties ---
500
501bool PointerProperties::operator==(const PointerProperties& other) const {
502 return id == other.id
503 && toolType == other.toolType;
504}
505
506void PointerProperties::copyFrom(const PointerProperties& other) {
507 id = other.id;
508 toolType = other.toolType;
509}
510
511
512// --- MotionEvent ---
513
Garfield Tan4cc839f2020-01-24 11:26:14 -0800514void MotionEvent::initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600515 std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton,
516 int32_t flags, int32_t edgeFlags, int32_t metaState,
chaviw9eaa22c2020-07-01 16:21:27 -0700517 int32_t buttonState, MotionClassification classification,
518 const ui::Transform& transform, float xPrecision, float yPrecision,
Evan Rosky84f07f02021-04-16 10:42:42 -0700519 float rawXCursorPosition, float rawYCursorPosition,
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700520 const ui::Transform& rawTransform, nsecs_t downTime, nsecs_t eventTime,
Evan Rosky09576692021-07-01 12:22:09 -0700521 size_t pointerCount, const PointerProperties* pointerProperties,
Garfield Tan00f511d2019-06-12 16:55:40 -0700522 const PointerCoords* pointerCoords) {
Garfield Tan4cc839f2020-01-24 11:26:14 -0800523 InputEvent::initialize(id, deviceId, source, displayId, hmac);
Jeff Brown5912f952013-07-01 19:10:31 -0700524 mAction = action;
Michael Wright7b159c92015-05-14 14:48:03 +0100525 mActionButton = actionButton;
Jeff Brown5912f952013-07-01 19:10:31 -0700526 mFlags = flags;
527 mEdgeFlags = edgeFlags;
528 mMetaState = metaState;
529 mButtonState = buttonState;
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800530 mClassification = classification;
chaviw9eaa22c2020-07-01 16:21:27 -0700531 mTransform = transform;
Jeff Brown5912f952013-07-01 19:10:31 -0700532 mXPrecision = xPrecision;
533 mYPrecision = yPrecision;
Garfield Tan937bb832019-07-25 17:48:31 -0700534 mRawXCursorPosition = rawXCursorPosition;
535 mRawYCursorPosition = rawYCursorPosition;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700536 mRawTransform = rawTransform;
Jeff Brown5912f952013-07-01 19:10:31 -0700537 mDownTime = downTime;
538 mPointerProperties.clear();
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800539 mPointerProperties.insert(mPointerProperties.end(), &pointerProperties[0],
540 &pointerProperties[pointerCount]);
Jeff Brown5912f952013-07-01 19:10:31 -0700541 mSampleEventTimes.clear();
542 mSamplePointerCoords.clear();
543 addSample(eventTime, pointerCoords);
544}
545
546void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) {
Garfield Tan4cc839f2020-01-24 11:26:14 -0800547 InputEvent::initialize(other->mId, other->mDeviceId, other->mSource, other->mDisplayId,
548 other->mHmac);
Jeff Brown5912f952013-07-01 19:10:31 -0700549 mAction = other->mAction;
Michael Wright7b159c92015-05-14 14:48:03 +0100550 mActionButton = other->mActionButton;
Jeff Brown5912f952013-07-01 19:10:31 -0700551 mFlags = other->mFlags;
552 mEdgeFlags = other->mEdgeFlags;
553 mMetaState = other->mMetaState;
554 mButtonState = other->mButtonState;
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800555 mClassification = other->mClassification;
chaviw9eaa22c2020-07-01 16:21:27 -0700556 mTransform = other->mTransform;
Jeff Brown5912f952013-07-01 19:10:31 -0700557 mXPrecision = other->mXPrecision;
558 mYPrecision = other->mYPrecision;
Garfield Tan937bb832019-07-25 17:48:31 -0700559 mRawXCursorPosition = other->mRawXCursorPosition;
560 mRawYCursorPosition = other->mRawYCursorPosition;
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700561 mRawTransform = other->mRawTransform;
Jeff Brown5912f952013-07-01 19:10:31 -0700562 mDownTime = other->mDownTime;
563 mPointerProperties = other->mPointerProperties;
564
565 if (keepHistory) {
566 mSampleEventTimes = other->mSampleEventTimes;
567 mSamplePointerCoords = other->mSamplePointerCoords;
568 } else {
569 mSampleEventTimes.clear();
Siarhei Vishniakou46a27742020-09-09 13:57:28 -0500570 mSampleEventTimes.push_back(other->getEventTime());
Jeff Brown5912f952013-07-01 19:10:31 -0700571 mSamplePointerCoords.clear();
572 size_t pointerCount = other->getPointerCount();
573 size_t historySize = other->getHistorySize();
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800574 mSamplePointerCoords
575 .insert(mSamplePointerCoords.end(),
576 &other->mSamplePointerCoords[historySize * pointerCount],
577 &other->mSamplePointerCoords[historySize * pointerCount + pointerCount]);
Jeff Brown5912f952013-07-01 19:10:31 -0700578 }
579}
580
581void MotionEvent::addSample(
582 int64_t eventTime,
583 const PointerCoords* pointerCoords) {
Siarhei Vishniakou46a27742020-09-09 13:57:28 -0500584 mSampleEventTimes.push_back(eventTime);
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800585 mSamplePointerCoords.insert(mSamplePointerCoords.end(), &pointerCoords[0],
586 &pointerCoords[getPointerCount()]);
Jeff Brown5912f952013-07-01 19:10:31 -0700587}
588
Michael Wright635422b2022-12-02 00:43:56 +0000589std::optional<ui::Rotation> MotionEvent::getSurfaceRotation() const {
Prabir Pradhan092f3a92021-11-25 10:53:27 -0800590 // The surface rotation is the rotation from the window's coordinate space to that of the
591 // display. Since the event's transform takes display space coordinates to window space, the
592 // returned surface rotation is the inverse of the rotation for the surface.
593 switch (mTransform.getOrientation()) {
594 case ui::Transform::ROT_0:
Michael Wright635422b2022-12-02 00:43:56 +0000595 return ui::ROTATION_0;
Prabir Pradhan092f3a92021-11-25 10:53:27 -0800596 case ui::Transform::ROT_90:
Michael Wright635422b2022-12-02 00:43:56 +0000597 return ui::ROTATION_270;
Prabir Pradhan092f3a92021-11-25 10:53:27 -0800598 case ui::Transform::ROT_180:
Michael Wright635422b2022-12-02 00:43:56 +0000599 return ui::ROTATION_180;
Prabir Pradhan092f3a92021-11-25 10:53:27 -0800600 case ui::Transform::ROT_270:
Michael Wright635422b2022-12-02 00:43:56 +0000601 return ui::ROTATION_90;
Prabir Pradhan092f3a92021-11-25 10:53:27 -0800602 default:
Michael Wright635422b2022-12-02 00:43:56 +0000603 return std::nullopt;
Prabir Pradhan092f3a92021-11-25 10:53:27 -0800604 }
605}
606
Garfield Tan00f511d2019-06-12 16:55:40 -0700607float MotionEvent::getXCursorPosition() const {
chaviw9eaa22c2020-07-01 16:21:27 -0700608 vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition());
609 return vals.x;
Garfield Tan00f511d2019-06-12 16:55:40 -0700610}
611
612float MotionEvent::getYCursorPosition() const {
chaviw9eaa22c2020-07-01 16:21:27 -0700613 vec2 vals = mTransform.transform(getRawXCursorPosition(), getRawYCursorPosition());
614 return vals.y;
Garfield Tan00f511d2019-06-12 16:55:40 -0700615}
616
Garfield Tan937bb832019-07-25 17:48:31 -0700617void MotionEvent::setCursorPosition(float x, float y) {
chaviw9eaa22c2020-07-01 16:21:27 -0700618 ui::Transform inverse = mTransform.inverse();
619 vec2 vals = inverse.transform(x, y);
620 mRawXCursorPosition = vals.x;
621 mRawYCursorPosition = vals.y;
Garfield Tan937bb832019-07-25 17:48:31 -0700622}
623
Jeff Brown5912f952013-07-01 19:10:31 -0700624const PointerCoords* MotionEvent::getRawPointerCoords(size_t pointerIndex) const {
Siarhei Vishniakou4ded0b02022-05-26 00:36:48 +0000625 if (CC_UNLIKELY(pointerIndex < 0 || pointerIndex >= getPointerCount())) {
626 LOG(FATAL) << __func__ << ": Invalid pointer index " << pointerIndex << " for " << *this;
627 }
628 const size_t position = getHistorySize() * getPointerCount() + pointerIndex;
629 if (CC_UNLIKELY(position < 0 || position >= mSamplePointerCoords.size())) {
630 LOG(FATAL) << __func__ << ": Invalid array index " << position << " for " << *this;
631 }
632 return &mSamplePointerCoords[position];
Jeff Brown5912f952013-07-01 19:10:31 -0700633}
634
635float MotionEvent::getRawAxisValue(int32_t axis, size_t pointerIndex) const {
Evan Rosky84f07f02021-04-16 10:42:42 -0700636 return getHistoricalRawAxisValue(axis, pointerIndex, getHistorySize());
Jeff Brown5912f952013-07-01 19:10:31 -0700637}
638
639float MotionEvent::getAxisValue(int32_t axis, size_t pointerIndex) const {
chaviw9eaa22c2020-07-01 16:21:27 -0700640 return getHistoricalAxisValue(axis, pointerIndex, getHistorySize());
Jeff Brown5912f952013-07-01 19:10:31 -0700641}
642
643const PointerCoords* MotionEvent::getHistoricalRawPointerCoords(
644 size_t pointerIndex, size_t historicalIndex) const {
Siarhei Vishniakou4ded0b02022-05-26 00:36:48 +0000645 if (CC_UNLIKELY(pointerIndex < 0 || pointerIndex >= getPointerCount())) {
646 LOG(FATAL) << __func__ << ": Invalid pointer index " << pointerIndex << " for " << *this;
647 }
648 if (CC_UNLIKELY(historicalIndex < 0 || historicalIndex > getHistorySize())) {
649 LOG(FATAL) << __func__ << ": Invalid historical index " << historicalIndex << " for "
650 << *this;
651 }
652 const size_t position = historicalIndex * getPointerCount() + pointerIndex;
653 if (CC_UNLIKELY(position < 0 || position >= mSamplePointerCoords.size())) {
654 LOG(FATAL) << __func__ << ": Invalid array index " << position << " for " << *this;
655 }
656 return &mSamplePointerCoords[position];
Jeff Brown5912f952013-07-01 19:10:31 -0700657}
658
659float MotionEvent::getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
Prabir Pradhan6b384612021-05-14 16:56:25 -0700660 size_t historicalIndex) const {
Prabir Pradhan9eb02c02021-10-19 14:02:20 -0700661 const PointerCoords& coords = *getHistoricalRawPointerCoords(pointerIndex, historicalIndex);
662 return calculateTransformedAxisValue(axis, mSource, mRawTransform, coords);
Jeff Brown5912f952013-07-01 19:10:31 -0700663}
664
665float MotionEvent::getHistoricalAxisValue(int32_t axis, size_t pointerIndex,
Prabir Pradhan9f388812021-05-13 16:54:53 -0700666 size_t historicalIndex) const {
Prabir Pradhan9eb02c02021-10-19 14:02:20 -0700667 const PointerCoords& coords = *getHistoricalRawPointerCoords(pointerIndex, historicalIndex);
668 return calculateTransformedAxisValue(axis, mSource, mTransform, coords);
Jeff Brown5912f952013-07-01 19:10:31 -0700669}
670
671ssize_t MotionEvent::findPointerIndex(int32_t pointerId) const {
672 size_t pointerCount = mPointerProperties.size();
673 for (size_t i = 0; i < pointerCount; i++) {
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800674 if (mPointerProperties[i].id == pointerId) {
Jeff Brown5912f952013-07-01 19:10:31 -0700675 return i;
676 }
677 }
678 return -1;
679}
680
681void MotionEvent::offsetLocation(float xOffset, float yOffset) {
chaviw9eaa22c2020-07-01 16:21:27 -0700682 float currXOffset = mTransform.tx();
683 float currYOffset = mTransform.ty();
684 mTransform.set(currXOffset + xOffset, currYOffset + yOffset);
Jeff Brown5912f952013-07-01 19:10:31 -0700685}
686
Robert Carre07e1032018-11-26 12:55:53 -0800687void MotionEvent::scale(float globalScaleFactor) {
chaviw9eaa22c2020-07-01 16:21:27 -0700688 mTransform.set(mTransform.tx() * globalScaleFactor, mTransform.ty() * globalScaleFactor);
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700689 mRawTransform.set(mRawTransform.tx() * globalScaleFactor,
690 mRawTransform.ty() * globalScaleFactor);
Robert Carre07e1032018-11-26 12:55:53 -0800691 mXPrecision *= globalScaleFactor;
692 mYPrecision *= globalScaleFactor;
Jeff Brown5912f952013-07-01 19:10:31 -0700693
694 size_t numSamples = mSamplePointerCoords.size();
695 for (size_t i = 0; i < numSamples; i++) {
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800696 mSamplePointerCoords[i].scale(globalScaleFactor, globalScaleFactor, globalScaleFactor);
Jeff Brown5912f952013-07-01 19:10:31 -0700697 }
698}
699
chaviw9eaa22c2020-07-01 16:21:27 -0700700void MotionEvent::transform(const std::array<float, 9>& matrix) {
Prabir Pradhan6b384612021-05-14 16:56:25 -0700701 // We want to preserve the raw axes values stored in the PointerCoords, so we just update the
702 // transform using the values passed in.
chaviw9eaa22c2020-07-01 16:21:27 -0700703 ui::Transform newTransform;
704 newTransform.set(matrix);
705 mTransform = newTransform * mTransform;
Jeff Brown5912f952013-07-01 19:10:31 -0700706}
707
Evan Roskyd4d4d802021-05-03 20:12:21 -0700708void MotionEvent::applyTransform(const std::array<float, 9>& matrix) {
Prabir Pradhan6b384612021-05-14 16:56:25 -0700709 ui::Transform transform;
710 transform.set(matrix);
Evan Roskyd4d4d802021-05-03 20:12:21 -0700711
712 // Apply the transformation to all samples.
Prabir Pradhan6b384612021-05-14 16:56:25 -0700713 std::for_each(mSamplePointerCoords.begin(), mSamplePointerCoords.end(),
714 [&transform](PointerCoords& c) { c.transform(transform); });
Prabir Pradhan4b19bd02021-06-01 17:34:59 -0700715
716 if (mRawXCursorPosition != AMOTION_EVENT_INVALID_CURSOR_POSITION &&
717 mRawYCursorPosition != AMOTION_EVENT_INVALID_CURSOR_POSITION) {
718 const vec2 cursor = transform.transform(mRawXCursorPosition, mRawYCursorPosition);
719 mRawXCursorPosition = cursor.x;
720 mRawYCursorPosition = cursor.y;
721 }
Evan Roskyd4d4d802021-05-03 20:12:21 -0700722}
723
Brett Chabotfaa986c2020-11-04 17:39:36 -0800724#ifdef __linux__
chaviw9eaa22c2020-07-01 16:21:27 -0700725static status_t readFromParcel(ui::Transform& transform, const Parcel& parcel) {
726 float dsdx, dtdx, tx, dtdy, dsdy, ty;
727 status_t status = parcel.readFloat(&dsdx);
728 status |= parcel.readFloat(&dtdx);
729 status |= parcel.readFloat(&tx);
730 status |= parcel.readFloat(&dtdy);
731 status |= parcel.readFloat(&dsdy);
732 status |= parcel.readFloat(&ty);
733
734 transform.set({dsdx, dtdx, tx, dtdy, dsdy, ty, 0, 0, 1});
735 return status;
736}
737
738static status_t writeToParcel(const ui::Transform& transform, Parcel& parcel) {
739 status_t status = parcel.writeFloat(transform.dsdx());
740 status |= parcel.writeFloat(transform.dtdx());
741 status |= parcel.writeFloat(transform.tx());
742 status |= parcel.writeFloat(transform.dtdy());
743 status |= parcel.writeFloat(transform.dsdy());
744 status |= parcel.writeFloat(transform.ty());
745 return status;
746}
747
Jeff Brown5912f952013-07-01 19:10:31 -0700748status_t MotionEvent::readFromParcel(Parcel* parcel) {
749 size_t pointerCount = parcel->readInt32();
750 size_t sampleCount = parcel->readInt32();
Flanker552a8a52015-09-07 15:28:58 +0800751 if (pointerCount == 0 || pointerCount > MAX_POINTERS ||
752 sampleCount == 0 || sampleCount > MAX_SAMPLES) {
Jeff Brown5912f952013-07-01 19:10:31 -0700753 return BAD_VALUE;
754 }
755
Garfield Tan4cc839f2020-01-24 11:26:14 -0800756 mId = parcel->readInt32();
Jeff Brown5912f952013-07-01 19:10:31 -0700757 mDeviceId = parcel->readInt32();
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600758 mSource = parcel->readUint32();
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800759 mDisplayId = parcel->readInt32();
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600760 std::vector<uint8_t> hmac;
761 status_t result = parcel->readByteVector(&hmac);
762 if (result != OK || hmac.size() != 32) {
763 return BAD_VALUE;
764 }
765 std::move(hmac.begin(), hmac.begin() + hmac.size(), mHmac.begin());
Jeff Brown5912f952013-07-01 19:10:31 -0700766 mAction = parcel->readInt32();
Michael Wright7b159c92015-05-14 14:48:03 +0100767 mActionButton = parcel->readInt32();
Jeff Brown5912f952013-07-01 19:10:31 -0700768 mFlags = parcel->readInt32();
769 mEdgeFlags = parcel->readInt32();
770 mMetaState = parcel->readInt32();
771 mButtonState = parcel->readInt32();
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800772 mClassification = static_cast<MotionClassification>(parcel->readByte());
chaviw9eaa22c2020-07-01 16:21:27 -0700773
774 result = android::readFromParcel(mTransform, *parcel);
775 if (result != OK) {
776 return result;
777 }
Jeff Brown5912f952013-07-01 19:10:31 -0700778 mXPrecision = parcel->readFloat();
779 mYPrecision = parcel->readFloat();
Garfield Tan937bb832019-07-25 17:48:31 -0700780 mRawXCursorPosition = parcel->readFloat();
781 mRawYCursorPosition = parcel->readFloat();
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700782
783 result = android::readFromParcel(mRawTransform, *parcel);
784 if (result != OK) {
785 return result;
786 }
Jeff Brown5912f952013-07-01 19:10:31 -0700787 mDownTime = parcel->readInt64();
788
789 mPointerProperties.clear();
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800790 mPointerProperties.reserve(pointerCount);
Jeff Brown5912f952013-07-01 19:10:31 -0700791 mSampleEventTimes.clear();
Siarhei Vishniakou46a27742020-09-09 13:57:28 -0500792 mSampleEventTimes.reserve(sampleCount);
Jeff Brown5912f952013-07-01 19:10:31 -0700793 mSamplePointerCoords.clear();
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800794 mSamplePointerCoords.reserve(sampleCount * pointerCount);
Jeff Brown5912f952013-07-01 19:10:31 -0700795
796 for (size_t i = 0; i < pointerCount; i++) {
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800797 mPointerProperties.push_back({});
798 PointerProperties& properties = mPointerProperties.back();
Jeff Brown5912f952013-07-01 19:10:31 -0700799 properties.id = parcel->readInt32();
800 properties.toolType = parcel->readInt32();
801 }
802
Dan Austinc94fc452015-09-22 14:22:41 -0700803 while (sampleCount > 0) {
804 sampleCount--;
Siarhei Vishniakou46a27742020-09-09 13:57:28 -0500805 mSampleEventTimes.push_back(parcel->readInt64());
Jeff Brown5912f952013-07-01 19:10:31 -0700806 for (size_t i = 0; i < pointerCount; i++) {
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800807 mSamplePointerCoords.push_back({});
808 status_t status = mSamplePointerCoords.back().readFromParcel(parcel);
Jeff Brown5912f952013-07-01 19:10:31 -0700809 if (status) {
810 return status;
811 }
812 }
813 }
814 return OK;
815}
816
817status_t MotionEvent::writeToParcel(Parcel* parcel) const {
818 size_t pointerCount = mPointerProperties.size();
819 size_t sampleCount = mSampleEventTimes.size();
820
821 parcel->writeInt32(pointerCount);
822 parcel->writeInt32(sampleCount);
823
Garfield Tan4cc839f2020-01-24 11:26:14 -0800824 parcel->writeInt32(mId);
Jeff Brown5912f952013-07-01 19:10:31 -0700825 parcel->writeInt32(mDeviceId);
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600826 parcel->writeUint32(mSource);
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800827 parcel->writeInt32(mDisplayId);
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600828 std::vector<uint8_t> hmac(mHmac.begin(), mHmac.end());
829 parcel->writeByteVector(hmac);
Jeff Brown5912f952013-07-01 19:10:31 -0700830 parcel->writeInt32(mAction);
Michael Wright7b159c92015-05-14 14:48:03 +0100831 parcel->writeInt32(mActionButton);
Jeff Brown5912f952013-07-01 19:10:31 -0700832 parcel->writeInt32(mFlags);
833 parcel->writeInt32(mEdgeFlags);
834 parcel->writeInt32(mMetaState);
835 parcel->writeInt32(mButtonState);
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800836 parcel->writeByte(static_cast<int8_t>(mClassification));
chaviw9eaa22c2020-07-01 16:21:27 -0700837
838 status_t result = android::writeToParcel(mTransform, *parcel);
839 if (result != OK) {
840 return result;
841 }
Jeff Brown5912f952013-07-01 19:10:31 -0700842 parcel->writeFloat(mXPrecision);
843 parcel->writeFloat(mYPrecision);
Garfield Tan937bb832019-07-25 17:48:31 -0700844 parcel->writeFloat(mRawXCursorPosition);
845 parcel->writeFloat(mRawYCursorPosition);
Prabir Pradhanb9b18502021-08-26 12:30:32 -0700846
847 result = android::writeToParcel(mRawTransform, *parcel);
848 if (result != OK) {
849 return result;
850 }
Jeff Brown5912f952013-07-01 19:10:31 -0700851 parcel->writeInt64(mDownTime);
852
853 for (size_t i = 0; i < pointerCount; i++) {
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800854 const PointerProperties& properties = mPointerProperties[i];
Jeff Brown5912f952013-07-01 19:10:31 -0700855 parcel->writeInt32(properties.id);
856 parcel->writeInt32(properties.toolType);
857 }
858
Siarhei Vishniakou6dbd0ce2022-01-13 01:24:14 -0800859 const PointerCoords* pc = mSamplePointerCoords.data();
Jeff Brown5912f952013-07-01 19:10:31 -0700860 for (size_t h = 0; h < sampleCount; h++) {
Siarhei Vishniakou46a27742020-09-09 13:57:28 -0500861 parcel->writeInt64(mSampleEventTimes[h]);
Jeff Brown5912f952013-07-01 19:10:31 -0700862 for (size_t i = 0; i < pointerCount; i++) {
863 status_t status = (pc++)->writeToParcel(parcel);
864 if (status) {
865 return status;
866 }
867 }
868 }
869 return OK;
870}
Brett Chabotfaa986c2020-11-04 17:39:36 -0800871#endif
Jeff Brown5912f952013-07-01 19:10:31 -0700872
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600873bool MotionEvent::isTouchEvent(uint32_t source, int32_t action) {
Prabir Pradhan7e1ee562021-10-26 10:19:49 -0700874 if (isFromSource(source, AINPUT_SOURCE_CLASS_POINTER)) {
Jeff Brown5912f952013-07-01 19:10:31 -0700875 // Specifically excludes HOVER_MOVE and SCROLL.
876 switch (action & AMOTION_EVENT_ACTION_MASK) {
877 case AMOTION_EVENT_ACTION_DOWN:
878 case AMOTION_EVENT_ACTION_MOVE:
879 case AMOTION_EVENT_ACTION_UP:
880 case AMOTION_EVENT_ACTION_POINTER_DOWN:
881 case AMOTION_EVENT_ACTION_POINTER_UP:
882 case AMOTION_EVENT_ACTION_CANCEL:
883 case AMOTION_EVENT_ACTION_OUTSIDE:
884 return true;
885 }
886 }
887 return false;
888}
889
Michael Wright872db4f2014-04-22 15:03:51 -0700890const char* MotionEvent::getLabel(int32_t axis) {
Chris Ye4958d062020-08-20 13:21:10 -0700891 return InputEventLookup::getAxisLabel(axis);
Michael Wright872db4f2014-04-22 15:03:51 -0700892}
893
894int32_t MotionEvent::getAxisFromLabel(const char* label) {
Chris Ye4958d062020-08-20 13:21:10 -0700895 return InputEventLookup::getAxisByLabel(label);
Michael Wright872db4f2014-04-22 15:03:51 -0700896}
897
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -0500898std::string MotionEvent::actionToString(int32_t action) {
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700899 // Convert MotionEvent action to string
900 switch (action & AMOTION_EVENT_ACTION_MASK) {
901 case AMOTION_EVENT_ACTION_DOWN:
902 return "DOWN";
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700903 case AMOTION_EVENT_ACTION_UP:
904 return "UP";
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -0500905 case AMOTION_EVENT_ACTION_MOVE:
906 return "MOVE";
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700907 case AMOTION_EVENT_ACTION_CANCEL:
908 return "CANCEL";
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -0500909 case AMOTION_EVENT_ACTION_OUTSIDE:
910 return "OUTSIDE";
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700911 case AMOTION_EVENT_ACTION_POINTER_DOWN:
Siarhei Vishniakouca205502021-07-16 21:31:58 +0000912 return StringPrintf("POINTER_DOWN(%" PRId32 ")", MotionEvent::getActionIndex(action));
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700913 case AMOTION_EVENT_ACTION_POINTER_UP:
Siarhei Vishniakouca205502021-07-16 21:31:58 +0000914 return StringPrintf("POINTER_UP(%" PRId32 ")", MotionEvent::getActionIndex(action));
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -0500915 case AMOTION_EVENT_ACTION_HOVER_MOVE:
916 return "HOVER_MOVE";
917 case AMOTION_EVENT_ACTION_SCROLL:
918 return "SCROLL";
919 case AMOTION_EVENT_ACTION_HOVER_ENTER:
920 return "HOVER_ENTER";
921 case AMOTION_EVENT_ACTION_HOVER_EXIT:
922 return "HOVER_EXIT";
923 case AMOTION_EVENT_ACTION_BUTTON_PRESS:
924 return "BUTTON_PRESS";
925 case AMOTION_EVENT_ACTION_BUTTON_RELEASE:
926 return "BUTTON_RELEASE";
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700927 }
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -0500928 return android::base::StringPrintf("%" PRId32, action);
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700929}
930
Prabir Pradhan7e1ee562021-10-26 10:19:49 -0700931// Apply the given transformation to the point without checking whether the entire transform
932// should be disregarded altogether for the provided source.
933static inline vec2 calculateTransformedXYUnchecked(uint32_t source, const ui::Transform& transform,
934 const vec2& xy) {
935 return shouldDisregardOffset(source) ? transformWithoutTranslation(transform, xy)
936 : transform.transform(xy);
937}
938
Prabir Pradhanb5cb9572021-09-24 06:35:16 -0700939vec2 MotionEvent::calculateTransformedXY(uint32_t source, const ui::Transform& transform,
940 const vec2& xy) {
Prabir Pradhan7e1ee562021-10-26 10:19:49 -0700941 if (shouldDisregardTransformation(source)) {
942 return xy;
943 }
944 return calculateTransformedXYUnchecked(source, transform, xy);
Prabir Pradhanb5cb9572021-09-24 06:35:16 -0700945}
946
Prabir Pradhan8e6ce222022-02-24 09:08:54 -0800947// Keep in sync with calculateTransformedCoords.
Prabir Pradhan9eb02c02021-10-19 14:02:20 -0700948float MotionEvent::calculateTransformedAxisValue(int32_t axis, uint32_t source,
949 const ui::Transform& transform,
950 const PointerCoords& coords) {
Prabir Pradhan7e1ee562021-10-26 10:19:49 -0700951 if (shouldDisregardTransformation(source)) {
952 return coords.getAxisValue(axis);
953 }
954
Prabir Pradhan9eb02c02021-10-19 14:02:20 -0700955 if (axis == AMOTION_EVENT_AXIS_X || axis == AMOTION_EVENT_AXIS_Y) {
Prabir Pradhan7e1ee562021-10-26 10:19:49 -0700956 const vec2 xy = calculateTransformedXYUnchecked(source, transform, coords.getXYValue());
Prabir Pradhan9eb02c02021-10-19 14:02:20 -0700957 static_assert(AMOTION_EVENT_AXIS_X == 0 && AMOTION_EVENT_AXIS_Y == 1);
958 return xy[axis];
959 }
960
961 if (axis == AMOTION_EVENT_AXIS_RELATIVE_X || axis == AMOTION_EVENT_AXIS_RELATIVE_Y) {
962 const vec2 relativeXy =
963 transformWithoutTranslation(transform,
964 {coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X),
965 coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y)});
966 return axis == AMOTION_EVENT_AXIS_RELATIVE_X ? relativeXy.x : relativeXy.y;
967 }
968
969 if (axis == AMOTION_EVENT_AXIS_ORIENTATION) {
970 return transformAngle(transform, coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION));
971 }
972
973 return coords.getAxisValue(axis);
974}
975
Prabir Pradhan8e6ce222022-02-24 09:08:54 -0800976// Keep in sync with calculateTransformedAxisValue. This is an optimization of
977// calculateTransformedAxisValue for all PointerCoords axes.
978PointerCoords MotionEvent::calculateTransformedCoords(uint32_t source,
979 const ui::Transform& transform,
980 const PointerCoords& coords) {
981 if (shouldDisregardTransformation(source)) {
982 return coords;
983 }
984 PointerCoords out = coords;
985
986 const vec2 xy = calculateTransformedXYUnchecked(source, transform, coords.getXYValue());
987 out.setAxisValue(AMOTION_EVENT_AXIS_X, xy.x);
988 out.setAxisValue(AMOTION_EVENT_AXIS_Y, xy.y);
989
990 const vec2 relativeXy =
991 transformWithoutTranslation(transform,
992 {coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X),
993 coords.getAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y)});
994 out.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_X, relativeXy.x);
995 out.setAxisValue(AMOTION_EVENT_AXIS_RELATIVE_Y, relativeXy.y);
996
997 out.setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION,
998 transformAngle(transform,
999 coords.getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION)));
1000
1001 return out;
1002}
1003
Siarhei Vishniakou4ded0b02022-05-26 00:36:48 +00001004std::ostream& operator<<(std::ostream& out, const MotionEvent& event) {
1005 out << "MotionEvent { action=" << MotionEvent::actionToString(event.getAction());
1006 if (event.getActionButton() != 0) {
1007 out << ", actionButton=" << std::to_string(event.getActionButton());
1008 }
1009 const size_t pointerCount = event.getPointerCount();
hupeng3aa5a51a2022-09-02 16:00:18 +08001010 LOG_ALWAYS_FATAL_IF(pointerCount > MAX_POINTERS, "Too many pointers : pointerCount = %zu",
1011 pointerCount);
Siarhei Vishniakou4ded0b02022-05-26 00:36:48 +00001012 for (size_t i = 0; i < pointerCount; i++) {
1013 out << ", id[" << i << "]=" << event.getPointerId(i);
1014 float x = event.getX(i);
1015 float y = event.getY(i);
1016 if (x != 0 || y != 0) {
1017 out << ", x[" << i << "]=" << x;
1018 out << ", y[" << i << "]=" << y;
1019 }
1020 int toolType = event.getToolType(i);
1021 if (toolType != AMOTION_EVENT_TOOL_TYPE_FINGER) {
1022 out << ", toolType[" << i << "]=" << toolType;
1023 }
1024 }
1025 if (event.getButtonState() != 0) {
1026 out << ", buttonState=" << event.getButtonState();
1027 }
1028 if (event.getClassification() != MotionClassification::NONE) {
1029 out << ", classification=" << motionClassificationToString(event.getClassification());
1030 }
1031 if (event.getMetaState() != 0) {
1032 out << ", metaState=" << event.getMetaState();
1033 }
1034 if (event.getEdgeFlags() != 0) {
1035 out << ", edgeFlags=" << event.getEdgeFlags();
1036 }
1037 if (pointerCount != 1) {
1038 out << ", pointerCount=" << pointerCount;
1039 }
1040 if (event.getHistorySize() != 0) {
1041 out << ", historySize=" << event.getHistorySize();
1042 }
1043 out << ", eventTime=" << event.getEventTime();
1044 out << ", downTime=" << event.getDownTime();
1045 out << ", deviceId=" << event.getDeviceId();
1046 out << ", source=" << inputEventSourceToString(event.getSource());
1047 out << ", displayId=" << event.getDisplayId();
1048 out << ", eventId=" << event.getId();
1049 out << "}";
1050 return out;
1051}
1052
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -08001053// --- FocusEvent ---
1054
Antonio Kantek3cfec7b2021-11-05 18:26:17 -07001055void FocusEvent::initialize(int32_t id, bool hasFocus) {
Garfield Tan4cc839f2020-01-24 11:26:14 -08001056 InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -06001057 ADISPLAY_ID_NONE, INVALID_HMAC);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -08001058 mHasFocus = hasFocus;
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -08001059}
1060
1061void FocusEvent::initialize(const FocusEvent& from) {
1062 InputEvent::initialize(from);
1063 mHasFocus = from.mHasFocus;
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -08001064}
Jeff Brown5912f952013-07-01 19:10:31 -07001065
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -08001066// --- CaptureEvent ---
1067
1068void CaptureEvent::initialize(int32_t id, bool pointerCaptureEnabled) {
1069 InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN,
1070 ADISPLAY_ID_NONE, INVALID_HMAC);
1071 mPointerCaptureEnabled = pointerCaptureEnabled;
1072}
1073
1074void CaptureEvent::initialize(const CaptureEvent& from) {
1075 InputEvent::initialize(from);
1076 mPointerCaptureEnabled = from.mPointerCaptureEnabled;
1077}
1078
arthurhung7632c332020-12-30 16:58:01 +08001079// --- DragEvent ---
1080
1081void DragEvent::initialize(int32_t id, float x, float y, bool isExiting) {
1082 InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN,
1083 ADISPLAY_ID_NONE, INVALID_HMAC);
1084 mIsExiting = isExiting;
1085 mX = x;
1086 mY = y;
1087}
1088
1089void DragEvent::initialize(const DragEvent& from) {
1090 InputEvent::initialize(from);
1091 mIsExiting = from.mIsExiting;
1092 mX = from.mX;
1093 mY = from.mY;
1094}
1095
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -07001096// --- TouchModeEvent ---
1097
1098void TouchModeEvent::initialize(int32_t id, bool isInTouchMode) {
1099 InputEvent::initialize(id, ReservedInputDeviceId::VIRTUAL_KEYBOARD_ID, AINPUT_SOURCE_UNKNOWN,
1100 ADISPLAY_ID_NONE, INVALID_HMAC);
1101 mIsInTouchMode = isInTouchMode;
1102}
1103
1104void TouchModeEvent::initialize(const TouchModeEvent& from) {
1105 InputEvent::initialize(from);
1106 mIsInTouchMode = from.mIsInTouchMode;
1107}
1108
Jeff Brown5912f952013-07-01 19:10:31 -07001109// --- PooledInputEventFactory ---
1110
1111PooledInputEventFactory::PooledInputEventFactory(size_t maxPoolSize) :
1112 mMaxPoolSize(maxPoolSize) {
1113}
1114
1115PooledInputEventFactory::~PooledInputEventFactory() {
Jeff Brown5912f952013-07-01 19:10:31 -07001116}
1117
1118KeyEvent* PooledInputEventFactory::createKeyEvent() {
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -08001119 if (mKeyEventPool.empty()) {
1120 return new KeyEvent();
Jeff Brown5912f952013-07-01 19:10:31 -07001121 }
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -08001122 KeyEvent* event = mKeyEventPool.front().release();
1123 mKeyEventPool.pop();
1124 return event;
Jeff Brown5912f952013-07-01 19:10:31 -07001125}
1126
1127MotionEvent* PooledInputEventFactory::createMotionEvent() {
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -08001128 if (mMotionEventPool.empty()) {
1129 return new MotionEvent();
Jeff Brown5912f952013-07-01 19:10:31 -07001130 }
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -08001131 MotionEvent* event = mMotionEventPool.front().release();
1132 mMotionEventPool.pop();
1133 return event;
Jeff Brown5912f952013-07-01 19:10:31 -07001134}
1135
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -08001136FocusEvent* PooledInputEventFactory::createFocusEvent() {
1137 if (mFocusEventPool.empty()) {
1138 return new FocusEvent();
1139 }
1140 FocusEvent* event = mFocusEventPool.front().release();
1141 mFocusEventPool.pop();
1142 return event;
1143}
1144
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -08001145CaptureEvent* PooledInputEventFactory::createCaptureEvent() {
1146 if (mCaptureEventPool.empty()) {
1147 return new CaptureEvent();
1148 }
1149 CaptureEvent* event = mCaptureEventPool.front().release();
1150 mCaptureEventPool.pop();
1151 return event;
1152}
1153
arthurhung7632c332020-12-30 16:58:01 +08001154DragEvent* PooledInputEventFactory::createDragEvent() {
1155 if (mDragEventPool.empty()) {
1156 return new DragEvent();
1157 }
1158 DragEvent* event = mDragEventPool.front().release();
1159 mDragEventPool.pop();
1160 return event;
1161}
1162
Antonio Kantek7cdf8ef2021-07-13 18:04:53 -07001163TouchModeEvent* PooledInputEventFactory::createTouchModeEvent() {
1164 if (mTouchModeEventPool.empty()) {
1165 return new TouchModeEvent();
1166 }
1167 TouchModeEvent* event = mTouchModeEventPool.front().release();
1168 mTouchModeEventPool.pop();
1169 return event;
1170}
1171
Jeff Brown5912f952013-07-01 19:10:31 -07001172void PooledInputEventFactory::recycle(InputEvent* event) {
1173 switch (event->getType()) {
1174 case AINPUT_EVENT_TYPE_KEY:
1175 if (mKeyEventPool.size() < mMaxPoolSize) {
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -08001176 mKeyEventPool.push(std::unique_ptr<KeyEvent>(static_cast<KeyEvent*>(event)));
Jeff Brown5912f952013-07-01 19:10:31 -07001177 return;
1178 }
1179 break;
1180 case AINPUT_EVENT_TYPE_MOTION:
1181 if (mMotionEventPool.size() < mMaxPoolSize) {
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -08001182 mMotionEventPool.push(std::unique_ptr<MotionEvent>(static_cast<MotionEvent*>(event)));
Jeff Brown5912f952013-07-01 19:10:31 -07001183 return;
1184 }
1185 break;
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -08001186 case AINPUT_EVENT_TYPE_FOCUS:
1187 if (mFocusEventPool.size() < mMaxPoolSize) {
1188 mFocusEventPool.push(std::unique_ptr<FocusEvent>(static_cast<FocusEvent*>(event)));
1189 return;
1190 }
1191 break;
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -08001192 case AINPUT_EVENT_TYPE_CAPTURE:
1193 if (mCaptureEventPool.size() < mMaxPoolSize) {
1194 mCaptureEventPool.push(
1195 std::unique_ptr<CaptureEvent>(static_cast<CaptureEvent*>(event)));
1196 return;
1197 }
1198 break;
arthurhung7632c332020-12-30 16:58:01 +08001199 case AINPUT_EVENT_TYPE_DRAG:
1200 if (mDragEventPool.size() < mMaxPoolSize) {
1201 mDragEventPool.push(std::unique_ptr<DragEvent>(static_cast<DragEvent*>(event)));
1202 return;
1203 }
1204 break;
Antonio Kantekeb4a30c2021-09-28 17:49:49 -07001205 case AINPUT_EVENT_TYPE_TOUCH_MODE:
1206 if (mTouchModeEventPool.size() < mMaxPoolSize) {
1207 mTouchModeEventPool.push(
1208 std::unique_ptr<TouchModeEvent>(static_cast<TouchModeEvent*>(event)));
1209 return;
1210 }
1211 break;
Jeff Brown5912f952013-07-01 19:10:31 -07001212 }
1213 delete event;
1214}
1215
1216} // namespace android