blob: e8678d27c3b76802c456cb4b2d8a72cbca0aa7bb [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#ifndef _LIBINPUT_INPUT_H
18#define _LIBINPUT_INPUT_H
19
Robert Carr2c358bf2018-08-08 15:58:15 -070020#pragma GCC system_header
21
Jeff Brown5912f952013-07-01 19:10:31 -070022/**
23 * Native input event structures.
24 */
25
26#include <android/input.h>
Siarhei Vishniakou509724f2021-06-16 04:09:35 +000027#ifdef __linux__
Siarhei Vishniakou5d552c42021-05-21 05:02:22 +000028#include <android/os/IInputConstants.h>
Siarhei Vishniakou509724f2021-06-16 04:09:35 +000029#endif
Garfield Tanab0ab9c2019-07-10 18:58:28 -070030#include <math.h>
Garfield Tan00f511d2019-06-12 16:55:40 -070031#include <stdint.h>
chaviwfd9c1ed2020-07-01 10:57:59 -070032#include <ui/Transform.h>
Michael Wrightd0bd3912014-03-19 12:06:10 -070033#include <utils/BitSet.h>
Jeff Brown5912f952013-07-01 19:10:31 -070034#include <utils/KeyedVector.h>
Jeff Brown5912f952013-07-01 19:10:31 -070035#include <utils/RefBase.h>
Michael Wrightd0bd3912014-03-19 12:06:10 -070036#include <utils/Timers.h>
37#include <utils/Vector.h>
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -060038#include <array>
Garfield Tan00f511d2019-06-12 16:55:40 -070039#include <limits>
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -080040#include <queue>
Jeff Brown5912f952013-07-01 19:10:31 -070041
Jeff Brown5912f952013-07-01 19:10:31 -070042/*
43 * Additional private constants not defined in ndk/ui/input.h.
44 */
45enum {
46 /* Signifies that the key is being predispatched */
47 AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000,
48
49 /* Private control to determine when an app is tracking a key sequence. */
50 AKEY_EVENT_FLAG_START_TRACKING = 0x40000000,
51
52 /* Key event is inconsistent with previously sent key events. */
53 AKEY_EVENT_FLAG_TAINTED = 0x80000000,
54};
55
56enum {
Michael Wrightcdcd8f22016-03-22 16:52:13 -070057
58 /**
59 * This flag indicates that the window that received this motion event is partly
60 * or wholly obscured by another visible window above it. This flag is set to true
61 * even if the event did not directly pass through the obscured area.
62 * A security sensitive application can check this flag to identify situations in which
63 * a malicious application may have covered up part of its content for the purpose
64 * of misleading the user or hijacking touches. An appropriate response might be
65 * to drop the suspect touches or to take additional precautions to confirm the user's
66 * actual intent.
67 */
68 AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2,
69
Prabir Pradhan141a9862018-11-19 14:35:56 -080070 /**
71 * This flag indicates that the event has been generated by a gesture generator. It
72 * provides a hint to the GestureDetector to not apply any touch slop.
73 */
74 AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = 0x8,
75
Prabir Pradhan47cf0a02021-03-11 20:30:57 -080076 /**
77 * This flag indicates that the event will not cause a focus change if it is directed to an
78 * unfocused window, even if it an ACTION_DOWN. This is typically used with pointer
79 * gestures to allow the user to direct gestures to an unfocused window without bringing it
80 * into focus.
81 */
82 AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE = 0x40,
83
Jeff Brown5912f952013-07-01 19:10:31 -070084 /* Motion event is inconsistent with previously sent motion events. */
85 AMOTION_EVENT_FLAG_TAINTED = 0x80000000,
86};
87
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -080088/**
89 * Allowed VerifiedKeyEvent flags. All other flags from KeyEvent do not get verified.
90 * These values must be kept in sync with VerifiedKeyEvent.java
91 */
92constexpr int32_t VERIFIED_KEY_EVENT_FLAGS = AKEY_EVENT_FLAG_CANCELED;
93
94/**
95 * Allowed VerifiedMotionEventFlags. All other flags from MotionEvent do not get verified.
96 * These values must be kept in sync with VerifiedMotionEvent.java
97 */
98constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS =
99 AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED;
100
arthurhungcc7f9802020-04-30 17:55:40 +0800101/**
102 * This flag indicates that the point up event has been canceled.
103 * Typically this is used for palm event when the user has accidental touches.
104 * TODO: Adjust flag to public api
105 */
106constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = 0x20;
107
Jeff Brown5912f952013-07-01 19:10:31 -0700108enum {
109 /* Used when a motion event is not associated with any display.
110 * Typically used for non-pointer events. */
111 ADISPLAY_ID_NONE = -1,
112
113 /* The default display id. */
114 ADISPLAY_ID_DEFAULT = 0,
115};
116
117enum {
118 /*
119 * Indicates that an input device has switches.
120 * This input source flag is hidden from the API because switches are only used by the system
121 * and applications have no way to interact with them.
122 */
123 AINPUT_SOURCE_SWITCH = 0x80000000,
124};
125
Michael Wright962a1082013-10-17 17:35:53 -0700126enum {
127 /**
128 * Constants for LEDs. Hidden from the API since we don't actually expose a way to interact
129 * with LEDs to developers
130 *
Michael Wright872db4f2014-04-22 15:03:51 -0700131 * NOTE: If you add LEDs here, you must also add them to InputEventLabels.h
Michael Wright962a1082013-10-17 17:35:53 -0700132 */
133
134 ALED_NUM_LOCK = 0x00,
135 ALED_CAPS_LOCK = 0x01,
136 ALED_SCROLL_LOCK = 0x02,
137 ALED_COMPOSE = 0x03,
138 ALED_KANA = 0x04,
139 ALED_SLEEP = 0x05,
140 ALED_SUSPEND = 0x06,
141 ALED_MUTE = 0x07,
142 ALED_MISC = 0x08,
143 ALED_MAIL = 0x09,
144 ALED_CHARGING = 0x0a,
145 ALED_CONTROLLER_1 = 0x10,
146 ALED_CONTROLLER_2 = 0x11,
147 ALED_CONTROLLER_3 = 0x12,
148 ALED_CONTROLLER_4 = 0x13,
149};
150
Michael Wright9b04f862013-10-18 17:53:50 -0700151/* Maximum number of controller LEDs we support */
152#define MAX_CONTROLLER_LEDS 4
153
Jeff Brown5912f952013-07-01 19:10:31 -0700154/*
Jeff Brown5912f952013-07-01 19:10:31 -0700155 * Maximum number of pointers supported per motion event.
156 * Smallest number of pointers is 1.
157 * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers
158 * will occasionally emit 11. There is not much harm making this constant bigger.)
159 */
160#define MAX_POINTERS 16
161
162/*
Flanker552a8a52015-09-07 15:28:58 +0800163 * Maximum number of samples supported per motion event.
164 */
165#define MAX_SAMPLES UINT16_MAX
166
167/*
Jeff Brown5912f952013-07-01 19:10:31 -0700168 * Maximum pointer id value supported in a motion event.
169 * Smallest pointer id is 0.
170 * (This is limited by our use of BitSet32 to track pointer assignments.)
171 */
172#define MAX_POINTER_ID 31
173
174/*
175 * Declare a concrete type for the NDK's input event forward declaration.
176 */
177struct AInputEvent {
178 virtual ~AInputEvent() { }
179};
180
181/*
182 * Declare a concrete type for the NDK's input device forward declaration.
183 */
184struct AInputDevice {
185 virtual ~AInputDevice() { }
186};
187
188
189namespace android {
190
Brett Chabotfaa986c2020-11-04 17:39:36 -0800191#ifdef __linux__
Jeff Brown5912f952013-07-01 19:10:31 -0700192class Parcel;
Brett Chabotfaa986c2020-11-04 17:39:36 -0800193#endif
Jeff Brown5912f952013-07-01 19:10:31 -0700194
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800195const char* inputEventTypeToString(int32_t type);
196
Jeff Brown5912f952013-07-01 19:10:31 -0700197/*
198 * Flags that flow alongside events in the input dispatch system to help with certain
199 * policy decisions such as waking from device sleep.
200 *
201 * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java.
202 */
203enum {
204 /* These flags originate in RawEvents and are generally set in the key map.
Michael Wright872db4f2014-04-22 15:03:51 -0700205 * NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to
206 * InputEventLabels.h as well. */
Jeff Brown5912f952013-07-01 19:10:31 -0700207
Jeff Brownc9aa6282015-02-11 19:03:28 -0800208 // Indicates that the event should wake the device.
Jeff Brown5912f952013-07-01 19:10:31 -0700209 POLICY_FLAG_WAKE = 0x00000001,
Jeff Brownc9aa6282015-02-11 19:03:28 -0800210
211 // Indicates that the key is virtual, such as a capacitive button, and should
212 // generate haptic feedback. Virtual keys may be suppressed for some time
213 // after a recent touch to prevent accidental activation of virtual keys adjacent
214 // to the touch screen during an edge swipe.
Michael Wright872db4f2014-04-22 15:03:51 -0700215 POLICY_FLAG_VIRTUAL = 0x00000002,
Jeff Brownc9aa6282015-02-11 19:03:28 -0800216
217 // Indicates that the key is the special function modifier.
Michael Wright872db4f2014-04-22 15:03:51 -0700218 POLICY_FLAG_FUNCTION = 0x00000004,
Jeff Brown5912f952013-07-01 19:10:31 -0700219
Jeff Brownc9aa6282015-02-11 19:03:28 -0800220 // Indicates that the key represents a special gesture that has been detected by
221 // the touch firmware or driver. Causes touch events from the same device to be canceled.
222 POLICY_FLAG_GESTURE = 0x00000008,
223
Jeff Brown5912f952013-07-01 19:10:31 -0700224 POLICY_FLAG_RAW_MASK = 0x0000ffff,
Siarhei Vishniakou509724f2021-06-16 04:09:35 +0000225#ifdef __linux__
Siarhei Vishniakou5d552c42021-05-21 05:02:22 +0000226 POLICY_FLAG_INPUTFILTER_TRUSTED = android::os::IInputConstants::POLICY_FLAG_INPUTFILTER_TRUSTED,
227
228 POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY =
229 android::os::IInputConstants::POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY,
Siarhei Vishniakou509724f2021-06-16 04:09:35 +0000230#else
231 POLICY_FLAG_INPUTFILTER_TRUSTED = 0x10000,
Siarhei Vishniakou5d552c42021-05-21 05:02:22 +0000232
Siarhei Vishniakou509724f2021-06-16 04:09:35 +0000233 POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY = 0x20000,
234#endif
Jeff Brown5912f952013-07-01 19:10:31 -0700235 /* These flags are set by the input dispatcher. */
236
237 // Indicates that the input event was injected.
238 POLICY_FLAG_INJECTED = 0x01000000,
239
240 // Indicates that the input event is from a trusted source such as a directly attached
241 // input device or an application with system-wide event injection permission.
242 POLICY_FLAG_TRUSTED = 0x02000000,
243
244 // Indicates that the input event has passed through an input filter.
245 POLICY_FLAG_FILTERED = 0x04000000,
246
247 // Disables automatic key repeating behavior.
248 POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000,
249
250 /* These flags are set by the input reader policy as it intercepts each event. */
251
Jeff Browndb19e462014-04-08 19:55:38 -0700252 // Indicates that the device was in an interactive state when the
253 // event was intercepted.
254 POLICY_FLAG_INTERACTIVE = 0x20000000,
Jeff Brown5912f952013-07-01 19:10:31 -0700255
256 // Indicates that the event should be dispatched to applications.
257 // The input event should still be sent to the InputDispatcher so that it can see all
258 // input events received include those that it will not deliver.
259 POLICY_FLAG_PASS_TO_USER = 0x40000000,
260};
261
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800262/**
263 * Classifications of the current gesture, if available.
264 *
265 * The following values must be kept in sync with MotionEvent.java
266 */
267enum class MotionClassification : uint8_t {
268 /**
269 * No classification is available.
270 */
271 NONE = 0,
272 /**
273 * Too early to classify the current gesture. Need more events. Look for changes in the
274 * upcoming motion events.
275 */
276 AMBIGUOUS_GESTURE = 1,
277 /**
278 * The current gesture likely represents a user intentionally exerting force on the touchscreen.
279 */
280 DEEP_PRESS = 2,
281};
282
Siarhei Vishniakou16a2e302019-01-14 19:21:45 -0800283/**
284 * String representation of MotionClassification
285 */
286const char* motionClassificationToString(MotionClassification classification);
287
Garfield Tan00f511d2019-06-12 16:55:40 -0700288/**
Siarhei Vishniakouf94ae022021-02-04 01:23:17 +0000289 * Portion of FrameMetrics timeline of interest to input code.
290 */
291enum GraphicsTimeline : size_t {
292 /** Time when the app sent the buffer to SurfaceFlinger. */
293 GPU_COMPLETED_TIME = 0,
294
295 /** Time when the frame was presented on the display */
296 PRESENT_TIME = 1,
297
298 /** Total size of the 'GraphicsTimeline' array. Must always be last. */
299 SIZE = 2
300};
301
302/**
Garfield Tan84b087e2020-01-23 10:49:05 -0800303 * Generator of unique numbers used to identify input events.
304 *
305 * Layout of ID:
306 * |--------------------------|---------------------------|
307 * | 2 bits for source | 30 bits for random number |
308 * |--------------------------|---------------------------|
309 */
310class IdGenerator {
311private:
312 static constexpr uint32_t SOURCE_SHIFT = 30;
313
314public:
315 // Used to divide integer space to ensure no conflict among these sources./
316 enum class Source : int32_t {
Garfield Tan750c7f42020-05-18 17:41:46 -0700317 INPUT_READER = static_cast<int32_t>(0x0u << SOURCE_SHIFT),
318 INPUT_DISPATCHER = static_cast<int32_t>(0x1u << SOURCE_SHIFT),
319 OTHER = static_cast<int32_t>(0x3u << SOURCE_SHIFT), // E.g. app injected events
Garfield Tan84b087e2020-01-23 10:49:05 -0800320 };
321 IdGenerator(Source source);
322
323 int32_t nextId() const;
324
325 // Extract source from given id.
326 static inline Source getSource(int32_t id) { return static_cast<Source>(SOURCE_MASK & id); }
327
328private:
329 const Source mSource;
330
Garfield Tan750c7f42020-05-18 17:41:46 -0700331 static constexpr int32_t SOURCE_MASK = static_cast<int32_t>(0x3u << SOURCE_SHIFT);
Garfield Tan84b087e2020-01-23 10:49:05 -0800332};
333
334/**
Garfield Tan00f511d2019-06-12 16:55:40 -0700335 * Invalid value for cursor position. Used for non-mouse events, tests and injected events. Don't
336 * use it for direct comparison with any other value, because NaN isn't equal to itself according to
337 * IEEE 754. Use isnan() instead to check if a cursor position is valid.
338 */
339constexpr float AMOTION_EVENT_INVALID_CURSOR_POSITION = std::numeric_limits<float>::quiet_NaN();
340
Evan Rosky84f07f02021-04-16 10:42:42 -0700341/**
342 * Invalid value for display size. Used when display size isn't available for an event or doesn't
343 * matter. This is just a constant 0 so that it has no effect if unused.
344 */
345constexpr int32_t AMOTION_EVENT_INVALID_DISPLAY_SIZE = 0;
346
Jeff Brown5912f952013-07-01 19:10:31 -0700347/*
348 * Pointer coordinate data.
349 */
350struct PointerCoords {
Michael Wright8f6710f2014-06-09 18:56:43 -0700351 enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128
Jeff Brown5912f952013-07-01 19:10:31 -0700352
353 // Bitfield of axes that are present in this structure.
Fengwei Yin83e0e422014-05-24 05:32:09 +0800354 uint64_t bits __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -0700355
356 // Values of axes that are stored in this structure packed in order by axis id
357 // for each axis that is present in the structure according to 'bits'.
358 float values[MAX_AXES];
359
360 inline void clear() {
Michael Wrightd0bd3912014-03-19 12:06:10 -0700361 BitSet64::clear(bits);
362 }
363
364 bool isEmpty() const {
365 return BitSet64::isEmpty(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700366 }
367
368 float getAxisValue(int32_t axis) const;
369 status_t setAxisValue(int32_t axis, float value);
370
Robert Carre07e1032018-11-26 12:55:53 -0800371 void scale(float globalScale);
372
373 // Scale the pointer coordinates according to a global scale and a
374 // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR
375 // axes, however the window scaling will not.
376 void scale(float globalScale, float windowXScale, float windowYScale);
Jeff Browned4d28d2014-02-11 14:28:48 -0800377 void applyOffset(float xOffset, float yOffset);
Jeff Brown5912f952013-07-01 19:10:31 -0700378
chaviwc01e1372020-07-01 12:37:31 -0700379 void transform(const ui::Transform& transform);
380
Jeff Brown5912f952013-07-01 19:10:31 -0700381 inline float getX() const {
382 return getAxisValue(AMOTION_EVENT_AXIS_X);
383 }
384
385 inline float getY() const {
386 return getAxisValue(AMOTION_EVENT_AXIS_Y);
387 }
388
Evan Rosky84f07f02021-04-16 10:42:42 -0700389 vec2 getXYValue() const { return vec2(getX(), getY()); }
390
Brett Chabotfaa986c2020-11-04 17:39:36 -0800391#ifdef __linux__
Jeff Brown5912f952013-07-01 19:10:31 -0700392 status_t readFromParcel(Parcel* parcel);
393 status_t writeToParcel(Parcel* parcel) const;
Brett Chabotfaa986c2020-11-04 17:39:36 -0800394#endif
Jeff Brown5912f952013-07-01 19:10:31 -0700395
396 bool operator==(const PointerCoords& other) const;
397 inline bool operator!=(const PointerCoords& other) const {
398 return !(*this == other);
399 }
400
401 void copyFrom(const PointerCoords& other);
402
403private:
404 void tooManyAxes(int axis);
405};
406
407/*
408 * Pointer property data.
409 */
410struct PointerProperties {
411 // The id of the pointer.
412 int32_t id;
413
414 // The pointer tool type.
415 int32_t toolType;
416
417 inline void clear() {
418 id = -1;
419 toolType = 0;
420 }
421
422 bool operator==(const PointerProperties& other) const;
423 inline bool operator!=(const PointerProperties& other) const {
424 return !(*this == other);
425 }
426
427 void copyFrom(const PointerProperties& other);
428};
429
430/*
431 * Input events.
432 */
433class InputEvent : public AInputEvent {
434public:
435 virtual ~InputEvent() { }
436
437 virtual int32_t getType() const = 0;
438
Garfield Tan4cc839f2020-01-24 11:26:14 -0800439 inline int32_t getId() const { return mId; }
440
Jeff Brown5912f952013-07-01 19:10:31 -0700441 inline int32_t getDeviceId() const { return mDeviceId; }
442
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600443 inline uint32_t getSource() const { return mSource; }
Jeff Brown5912f952013-07-01 19:10:31 -0700444
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600445 inline void setSource(uint32_t source) { mSource = source; }
Jeff Brown5912f952013-07-01 19:10:31 -0700446
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100447 inline int32_t getDisplayId() const { return mDisplayId; }
448
449 inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }
450
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600451 inline std::array<uint8_t, 32> getHmac() const { return mHmac; }
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100452
Garfield Tan4cc839f2020-01-24 11:26:14 -0800453 static int32_t nextId();
454
Jeff Brown5912f952013-07-01 19:10:31 -0700455protected:
Garfield Tan4cc839f2020-01-24 11:26:14 -0800456 void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600457 std::array<uint8_t, 32> hmac);
Garfield Tan4cc839f2020-01-24 11:26:14 -0800458
Jeff Brown5912f952013-07-01 19:10:31 -0700459 void initialize(const InputEvent& from);
460
Garfield Tan4cc839f2020-01-24 11:26:14 -0800461 int32_t mId;
Jeff Brown5912f952013-07-01 19:10:31 -0700462 int32_t mDeviceId;
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600463 uint32_t mSource;
Siarhei Vishniakoua62a8dd2018-06-08 21:17:33 +0100464 int32_t mDisplayId;
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600465 std::array<uint8_t, 32> mHmac;
Jeff Brown5912f952013-07-01 19:10:31 -0700466};
467
468/*
469 * Key events.
470 */
471class KeyEvent : public InputEvent {
472public:
473 virtual ~KeyEvent() { }
474
475 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
476
477 inline int32_t getAction() const { return mAction; }
478
479 inline int32_t getFlags() const { return mFlags; }
480
481 inline void setFlags(int32_t flags) { mFlags = flags; }
482
483 inline int32_t getKeyCode() const { return mKeyCode; }
484
485 inline int32_t getScanCode() const { return mScanCode; }
486
487 inline int32_t getMetaState() const { return mMetaState; }
488
489 inline int32_t getRepeatCount() const { return mRepeatCount; }
490
491 inline nsecs_t getDownTime() const { return mDownTime; }
492
493 inline nsecs_t getEventTime() const { return mEventTime; }
494
Michael Wright872db4f2014-04-22 15:03:51 -0700495 static const char* getLabel(int32_t keyCode);
496 static int32_t getKeyCodeFromLabel(const char* label);
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800497
Garfield Tan4cc839f2020-01-24 11:26:14 -0800498 void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600499 std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode,
500 int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime,
501 nsecs_t eventTime);
Jeff Brown5912f952013-07-01 19:10:31 -0700502 void initialize(const KeyEvent& from);
503
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700504 static const char* actionToString(int32_t action);
505
Jeff Brown5912f952013-07-01 19:10:31 -0700506protected:
507 int32_t mAction;
508 int32_t mFlags;
509 int32_t mKeyCode;
510 int32_t mScanCode;
511 int32_t mMetaState;
512 int32_t mRepeatCount;
513 nsecs_t mDownTime;
514 nsecs_t mEventTime;
515};
516
517/*
518 * Motion events.
519 */
520class MotionEvent : public InputEvent {
521public:
522 virtual ~MotionEvent() { }
523
524 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
525
526 inline int32_t getAction() const { return mAction; }
527
528 inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
529
530 inline int32_t getActionIndex() const {
531 return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
532 >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
533 }
534
535 inline void setAction(int32_t action) { mAction = action; }
536
537 inline int32_t getFlags() const { return mFlags; }
538
539 inline void setFlags(int32_t flags) { mFlags = flags; }
540
541 inline int32_t getEdgeFlags() const { return mEdgeFlags; }
542
543 inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; }
544
545 inline int32_t getMetaState() const { return mMetaState; }
546
547 inline void setMetaState(int32_t metaState) { mMetaState = metaState; }
548
549 inline int32_t getButtonState() const { return mButtonState; }
550
Michael Wright6db58792016-09-14 19:53:37 +0100551 inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; }
Michael Wright7b159c92015-05-14 14:48:03 +0100552
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800553 inline MotionClassification getClassification() const { return mClassification; }
554
Michael Wright7b159c92015-05-14 14:48:03 +0100555 inline int32_t getActionButton() const { return mActionButton; }
556
Michael Wright21957b92015-06-17 21:06:54 +0100557 inline void setActionButton(int32_t button) { mActionButton = button; }
558
chaviw9eaa22c2020-07-01 16:21:27 -0700559 inline float getXOffset() const { return mTransform.tx(); }
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600560
chaviw9eaa22c2020-07-01 16:21:27 -0700561 inline float getYOffset() const { return mTransform.ty(); }
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600562
chaviw9eaa22c2020-07-01 16:21:27 -0700563 inline ui::Transform getTransform() const { return mTransform; }
Jeff Brown5912f952013-07-01 19:10:31 -0700564
565 inline float getXPrecision() const { return mXPrecision; }
566
567 inline float getYPrecision() const { return mYPrecision; }
568
Garfield Tan937bb832019-07-25 17:48:31 -0700569 inline float getRawXCursorPosition() const { return mRawXCursorPosition; }
Garfield Tan00f511d2019-06-12 16:55:40 -0700570
571 float getXCursorPosition() const;
572
Garfield Tan937bb832019-07-25 17:48:31 -0700573 inline float getRawYCursorPosition() const { return mRawYCursorPosition; }
Garfield Tan00f511d2019-06-12 16:55:40 -0700574
575 float getYCursorPosition() const;
576
Garfield Tan937bb832019-07-25 17:48:31 -0700577 void setCursorPosition(float x, float y);
578
Evan Rosky84f07f02021-04-16 10:42:42 -0700579 int2 getDisplaySize() const { return {mDisplayWidth, mDisplayHeight}; }
580
Garfield Tanab0ab9c2019-07-10 18:58:28 -0700581 static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); }
582
Jeff Brown5912f952013-07-01 19:10:31 -0700583 inline nsecs_t getDownTime() const { return mDownTime; }
584
585 inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; }
586
587 inline size_t getPointerCount() const { return mPointerProperties.size(); }
588
589 inline const PointerProperties* getPointerProperties(size_t pointerIndex) const {
590 return &mPointerProperties[pointerIndex];
591 }
592
593 inline int32_t getPointerId(size_t pointerIndex) const {
594 return mPointerProperties[pointerIndex].id;
595 }
596
597 inline int32_t getToolType(size_t pointerIndex) const {
598 return mPointerProperties[pointerIndex].toolType;
599 }
600
601 inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }
602
Evan Rosky84f07f02021-04-16 10:42:42 -0700603 /**
604 * The actual raw pointer coords: whatever comes from the input device without any external
605 * transforms applied.
606 */
Jeff Brown5912f952013-07-01 19:10:31 -0700607 const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;
608
Evan Rosky84f07f02021-04-16 10:42:42 -0700609 /**
610 * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw"
611 * transform because many apps (incorrectly) assumed that raw == oriented-screen-space.
612 * "compat raw" is raw coordinates with screen rotation applied.
613 */
Jeff Brown5912f952013-07-01 19:10:31 -0700614 float getRawAxisValue(int32_t axis, size_t pointerIndex) const;
615
616 inline float getRawX(size_t pointerIndex) const {
617 return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
618 }
619
620 inline float getRawY(size_t pointerIndex) const {
621 return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
622 }
623
624 float getAxisValue(int32_t axis, size_t pointerIndex) const;
625
Siarhei Vishniakou69e4d0f2020-09-14 19:53:29 -0500626 /**
627 * Get the X coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'.
628 * Identical to calling getHistoricalX(pointerIndex, getHistorySize()).
629 */
Jeff Brown5912f952013-07-01 19:10:31 -0700630 inline float getX(size_t pointerIndex) const {
631 return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
632 }
633
Siarhei Vishniakou69e4d0f2020-09-14 19:53:29 -0500634 /**
635 * Get the Y coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'.
636 * Identical to calling getHistoricalX(pointerIndex, getHistorySize()).
637 */
Jeff Brown5912f952013-07-01 19:10:31 -0700638 inline float getY(size_t pointerIndex) const {
639 return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
640 }
641
642 inline float getPressure(size_t pointerIndex) const {
643 return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex);
644 }
645
646 inline float getSize(size_t pointerIndex) const {
647 return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex);
648 }
649
650 inline float getTouchMajor(size_t pointerIndex) const {
651 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex);
652 }
653
654 inline float getTouchMinor(size_t pointerIndex) const {
655 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex);
656 }
657
658 inline float getToolMajor(size_t pointerIndex) const {
659 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex);
660 }
661
662 inline float getToolMinor(size_t pointerIndex) const {
663 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex);
664 }
665
666 inline float getOrientation(size_t pointerIndex) const {
667 return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex);
668 }
669
670 inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
671
672 inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const {
673 return mSampleEventTimes[historicalIndex];
674 }
675
Evan Rosky84f07f02021-04-16 10:42:42 -0700676 /**
677 * The actual raw pointer coords: whatever comes from the input device without any external
678 * transforms applied.
679 */
Jeff Brown5912f952013-07-01 19:10:31 -0700680 const PointerCoords* getHistoricalRawPointerCoords(
681 size_t pointerIndex, size_t historicalIndex) const;
682
Evan Rosky84f07f02021-04-16 10:42:42 -0700683 /**
684 * This is the raw axis value. However, for X/Y axes, this currently applies a "compat-raw"
685 * transform because many apps (incorrectly) assumed that raw == oriented-screen-space.
686 * "compat raw" is raw coordinates with screen rotation applied.
687 */
Jeff Brown5912f952013-07-01 19:10:31 -0700688 float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
689 size_t historicalIndex) const;
690
691 inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const {
692 return getHistoricalRawAxisValue(
693 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
694 }
695
696 inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const {
697 return getHistoricalRawAxisValue(
698 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
699 }
700
701 float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const;
702
703 inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const {
704 return getHistoricalAxisValue(
705 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
706 }
707
708 inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const {
709 return getHistoricalAxisValue(
710 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
711 }
712
713 inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const {
714 return getHistoricalAxisValue(
715 AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex);
716 }
717
718 inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const {
719 return getHistoricalAxisValue(
720 AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex);
721 }
722
723 inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
724 return getHistoricalAxisValue(
725 AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex);
726 }
727
728 inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
729 return getHistoricalAxisValue(
730 AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex);
731 }
732
733 inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
734 return getHistoricalAxisValue(
735 AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex);
736 }
737
738 inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
739 return getHistoricalAxisValue(
740 AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex);
741 }
742
743 inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
744 return getHistoricalAxisValue(
745 AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex);
746 }
747
748 ssize_t findPointerIndex(int32_t pointerId) const;
749
Garfield Tan4cc839f2020-01-24 11:26:14 -0800750 void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
Siarhei Vishniakou9c858ac2020-01-23 14:20:11 -0600751 std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton,
752 int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState,
chaviw9eaa22c2020-07-01 16:21:27 -0700753 MotionClassification classification, const ui::Transform& transform,
754 float xPrecision, float yPrecision, float rawXCursorPosition,
Evan Rosky84f07f02021-04-16 10:42:42 -0700755 float rawYCursorPosition, int32_t displayWidth, int32_t displayHeight,
756 nsecs_t downTime, nsecs_t eventTime, size_t pointerCount,
757 const PointerProperties* pointerProperties, const PointerCoords* pointerCoords);
Jeff Brown5912f952013-07-01 19:10:31 -0700758
759 void copyFrom(const MotionEvent* other, bool keepHistory);
760
761 void addSample(
762 nsecs_t eventTime,
763 const PointerCoords* pointerCoords);
764
765 void offsetLocation(float xOffset, float yOffset);
766
Robert Carre07e1032018-11-26 12:55:53 -0800767 void scale(float globalScaleFactor);
Jeff Brown5912f952013-07-01 19:10:31 -0700768
Evan Roskyd4d4d802021-05-03 20:12:21 -0700769 // Set 3x3 perspective matrix transformation.
Jeff Brown5a2f68e2013-07-15 17:28:19 -0700770 // Matrix is in row-major form and compatible with SkMatrix.
chaviw9eaa22c2020-07-01 16:21:27 -0700771 void transform(const std::array<float, 9>& matrix);
Jeff Brown5912f952013-07-01 19:10:31 -0700772
Evan Roskyd4d4d802021-05-03 20:12:21 -0700773 // Apply 3x3 perspective matrix transformation only to content (do not modify mTransform).
774 // Matrix is in row-major form and compatible with SkMatrix.
775 void applyTransform(const std::array<float, 9>& matrix);
776
Brett Chabotfaa986c2020-11-04 17:39:36 -0800777#ifdef __linux__
Jeff Brown5912f952013-07-01 19:10:31 -0700778 status_t readFromParcel(Parcel* parcel);
779 status_t writeToParcel(Parcel* parcel) const;
Brett Chabotfaa986c2020-11-04 17:39:36 -0800780#endif
Jeff Brown5912f952013-07-01 19:10:31 -0700781
Siarhei Vishniakou3826d472020-01-27 10:44:40 -0600782 static bool isTouchEvent(uint32_t source, int32_t action);
Jeff Brown5912f952013-07-01 19:10:31 -0700783 inline bool isTouchEvent() const {
784 return isTouchEvent(mSource, mAction);
785 }
786
787 // Low-level accessors.
788 inline const PointerProperties* getPointerProperties() const {
789 return mPointerProperties.array();
790 }
Siarhei Vishniakou46a27742020-09-09 13:57:28 -0500791 inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.data(); }
Jeff Brown5912f952013-07-01 19:10:31 -0700792 inline const PointerCoords* getSamplePointerCoords() const {
793 return mSamplePointerCoords.array();
794 }
795
Michael Wright872db4f2014-04-22 15:03:51 -0700796 static const char* getLabel(int32_t axis);
797 static int32_t getAxisFromLabel(const char* label);
798
Siarhei Vishniakouc68fdec2020-10-22 14:58:14 -0500799 static std::string actionToString(int32_t action);
Siarhei Vishniakoud44dddf2020-03-25 16:16:40 -0700800
Jeff Brown5912f952013-07-01 19:10:31 -0700801protected:
802 int32_t mAction;
Michael Wright7b159c92015-05-14 14:48:03 +0100803 int32_t mActionButton;
Jeff Brown5912f952013-07-01 19:10:31 -0700804 int32_t mFlags;
805 int32_t mEdgeFlags;
806 int32_t mMetaState;
807 int32_t mButtonState;
Siarhei Vishniakou49e59222018-12-28 18:17:15 -0800808 MotionClassification mClassification;
chaviwfd9c1ed2020-07-01 10:57:59 -0700809 ui::Transform mTransform;
Jeff Brown5912f952013-07-01 19:10:31 -0700810 float mXPrecision;
811 float mYPrecision;
Garfield Tan937bb832019-07-25 17:48:31 -0700812 float mRawXCursorPosition;
813 float mRawYCursorPosition;
Evan Rosky84f07f02021-04-16 10:42:42 -0700814 int32_t mDisplayWidth;
815 int32_t mDisplayHeight;
Jeff Brown5912f952013-07-01 19:10:31 -0700816 nsecs_t mDownTime;
817 Vector<PointerProperties> mPointerProperties;
Siarhei Vishniakou46a27742020-09-09 13:57:28 -0500818 std::vector<nsecs_t> mSampleEventTimes;
Jeff Brown5912f952013-07-01 19:10:31 -0700819 Vector<PointerCoords> mSamplePointerCoords;
820};
821
822/*
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800823 * Focus events.
824 */
825class FocusEvent : public InputEvent {
826public:
827 virtual ~FocusEvent() {}
828
829 virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_FOCUS; }
830
831 inline bool getHasFocus() const { return mHasFocus; }
832
833 inline bool getInTouchMode() const { return mInTouchMode; }
834
Garfield Tan4cc839f2020-01-24 11:26:14 -0800835 void initialize(int32_t id, bool hasFocus, bool inTouchMode);
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800836
837 void initialize(const FocusEvent& from);
838
839protected:
840 bool mHasFocus;
841 bool mInTouchMode;
842};
843
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800844/*
845 * Capture events.
846 */
847class CaptureEvent : public InputEvent {
848public:
849 virtual ~CaptureEvent() {}
850
851 virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_CAPTURE; }
852
853 inline bool getPointerCaptureEnabled() const { return mPointerCaptureEnabled; }
854
855 void initialize(int32_t id, bool pointerCaptureEnabled);
856
857 void initialize(const CaptureEvent& from);
858
859protected:
860 bool mPointerCaptureEnabled;
861};
862
arthurhung7632c332020-12-30 16:58:01 +0800863/*
864 * Drag events.
865 */
866class DragEvent : public InputEvent {
867public:
868 virtual ~DragEvent() {}
869
870 virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_DRAG; }
871
872 inline bool isExiting() const { return mIsExiting; }
873
874 inline float getX() const { return mX; }
875
876 inline float getY() const { return mY; }
877
878 void initialize(int32_t id, float x, float y, bool isExiting);
879
880 void initialize(const DragEvent& from);
881
882protected:
883 bool mIsExiting;
884 float mX, mY;
885};
886
Siarhei Vishniakou54d3e182020-01-15 17:38:38 -0800887/**
888 * Base class for verified events.
889 * Do not create a VerifiedInputEvent explicitly.
890 * Use helper functions to create them from InputEvents.
891 */
892struct __attribute__((__packed__)) VerifiedInputEvent {
893 enum class Type : int32_t {
894 KEY = AINPUT_EVENT_TYPE_KEY,
895 MOTION = AINPUT_EVENT_TYPE_MOTION,
896 };
897
898 Type type;
899 int32_t deviceId;
900 nsecs_t eventTimeNanos;
901 uint32_t source;
902 int32_t displayId;
903};
904
905/**
906 * Same as KeyEvent, but only contains the data that can be verified.
907 * If you update this class, you must also update VerifiedKeyEvent.java
908 */
909struct __attribute__((__packed__)) VerifiedKeyEvent : public VerifiedInputEvent {
910 int32_t action;
911 nsecs_t downTimeNanos;
912 int32_t flags;
913 int32_t keyCode;
914 int32_t scanCode;
915 int32_t metaState;
916 int32_t repeatCount;
917};
918
919/**
920 * Same as MotionEvent, but only contains the data that can be verified.
921 * If you update this class, you must also update VerifiedMotionEvent.java
922 */
923struct __attribute__((__packed__)) VerifiedMotionEvent : public VerifiedInputEvent {
924 float rawX;
925 float rawY;
926 int32_t actionMasked;
927 nsecs_t downTimeNanos;
928 int32_t flags;
929 int32_t metaState;
930 int32_t buttonState;
931};
932
933VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event);
934VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event);
935
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800936/*
Jeff Brown5912f952013-07-01 19:10:31 -0700937 * Input event factory.
938 */
939class InputEventFactoryInterface {
940protected:
941 virtual ~InputEventFactoryInterface() { }
942
943public:
944 InputEventFactoryInterface() { }
945
946 virtual KeyEvent* createKeyEvent() = 0;
947 virtual MotionEvent* createMotionEvent() = 0;
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800948 virtual FocusEvent* createFocusEvent() = 0;
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800949 virtual CaptureEvent* createCaptureEvent() = 0;
arthurhung7632c332020-12-30 16:58:01 +0800950 virtual DragEvent* createDragEvent() = 0;
Jeff Brown5912f952013-07-01 19:10:31 -0700951};
952
953/*
954 * A simple input event factory implementation that uses a single preallocated instance
955 * of each type of input event that are reused for each request.
956 */
957class PreallocatedInputEventFactory : public InputEventFactoryInterface {
958public:
959 PreallocatedInputEventFactory() { }
960 virtual ~PreallocatedInputEventFactory() { }
961
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -0800962 virtual KeyEvent* createKeyEvent() override { return &mKeyEvent; }
963 virtual MotionEvent* createMotionEvent() override { return &mMotionEvent; }
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800964 virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; }
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800965 virtual CaptureEvent* createCaptureEvent() override { return &mCaptureEvent; }
arthurhung7632c332020-12-30 16:58:01 +0800966 virtual DragEvent* createDragEvent() override { return &mDragEvent; }
Jeff Brown5912f952013-07-01 19:10:31 -0700967
968private:
969 KeyEvent mKeyEvent;
970 MotionEvent mMotionEvent;
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800971 FocusEvent mFocusEvent;
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800972 CaptureEvent mCaptureEvent;
arthurhung7632c332020-12-30 16:58:01 +0800973 DragEvent mDragEvent;
Jeff Brown5912f952013-07-01 19:10:31 -0700974};
975
976/*
977 * An input event factory implementation that maintains a pool of input events.
978 */
979class PooledInputEventFactory : public InputEventFactoryInterface {
980public:
Chih-Hung Hsiehf43b02c2018-12-20 15:45:56 -0800981 explicit PooledInputEventFactory(size_t maxPoolSize = 20);
Jeff Brown5912f952013-07-01 19:10:31 -0700982 virtual ~PooledInputEventFactory();
983
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -0800984 virtual KeyEvent* createKeyEvent() override;
985 virtual MotionEvent* createMotionEvent() override;
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800986 virtual FocusEvent* createFocusEvent() override;
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800987 virtual CaptureEvent* createCaptureEvent() override;
arthurhung7632c332020-12-30 16:58:01 +0800988 virtual DragEvent* createDragEvent() override;
Jeff Brown5912f952013-07-01 19:10:31 -0700989
990 void recycle(InputEvent* event);
991
992private:
993 const size_t mMaxPoolSize;
994
Siarhei Vishniakou727a44e2019-11-23 12:59:16 -0800995 std::queue<std::unique_ptr<KeyEvent>> mKeyEventPool;
996 std::queue<std::unique_ptr<MotionEvent>> mMotionEventPool;
Siarhei Vishniakou7feb2ea2019-11-25 15:11:23 -0800997 std::queue<std::unique_ptr<FocusEvent>> mFocusEventPool;
Prabir Pradhan3f37b7b2020-11-10 16:50:18 -0800998 std::queue<std::unique_ptr<CaptureEvent>> mCaptureEventPool;
arthurhung7632c332020-12-30 16:58:01 +0800999 std::queue<std::unique_ptr<DragEvent>> mDragEventPool;
Jeff Brown5912f952013-07-01 19:10:31 -07001000};
1001
1002} // namespace android
1003
1004#endif // _LIBINPUT_INPUT_H