blob: 15c86ebd853912de8c550fa6cef2e7256b62a304 [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
20/**
21 * Native input event structures.
22 */
23
24#include <android/input.h>
Michael Wrightd0bd3912014-03-19 12:06:10 -070025#include <utils/BitSet.h>
Jeff Brown5912f952013-07-01 19:10:31 -070026#include <utils/KeyedVector.h>
Jeff Brown5912f952013-07-01 19:10:31 -070027#include <utils/RefBase.h>
28#include <utils/String8.h>
Michael Wrightd0bd3912014-03-19 12:06:10 -070029#include <utils/Timers.h>
30#include <utils/Vector.h>
Nick Kralevich834ac202015-10-22 07:09:23 -070031#include <stdint.h>
Jeff Brown5912f952013-07-01 19:10:31 -070032
Jeff Brown5912f952013-07-01 19:10:31 -070033/*
34 * Additional private constants not defined in ndk/ui/input.h.
35 */
36enum {
37 /* Signifies that the key is being predispatched */
38 AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000,
39
40 /* Private control to determine when an app is tracking a key sequence. */
41 AKEY_EVENT_FLAG_START_TRACKING = 0x40000000,
42
43 /* Key event is inconsistent with previously sent key events. */
44 AKEY_EVENT_FLAG_TAINTED = 0x80000000,
45};
46
47enum {
Michael Wrightcdcd8f22016-03-22 16:52:13 -070048
49 /**
50 * This flag indicates that the window that received this motion event is partly
51 * or wholly obscured by another visible window above it. This flag is set to true
52 * even if the event did not directly pass through the obscured area.
53 * A security sensitive application can check this flag to identify situations in which
54 * a malicious application may have covered up part of its content for the purpose
55 * of misleading the user or hijacking touches. An appropriate response might be
56 * to drop the suspect touches or to take additional precautions to confirm the user's
57 * actual intent.
58 */
59 AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2,
60
Jeff Brown5912f952013-07-01 19:10:31 -070061 /* Motion event is inconsistent with previously sent motion events. */
62 AMOTION_EVENT_FLAG_TAINTED = 0x80000000,
63};
64
65enum {
66 /* Used when a motion event is not associated with any display.
67 * Typically used for non-pointer events. */
68 ADISPLAY_ID_NONE = -1,
69
70 /* The default display id. */
71 ADISPLAY_ID_DEFAULT = 0,
72};
73
74enum {
75 /*
76 * Indicates that an input device has switches.
77 * This input source flag is hidden from the API because switches are only used by the system
78 * and applications have no way to interact with them.
79 */
80 AINPUT_SOURCE_SWITCH = 0x80000000,
81};
82
Michael Wright962a1082013-10-17 17:35:53 -070083enum {
84 /**
85 * Constants for LEDs. Hidden from the API since we don't actually expose a way to interact
86 * with LEDs to developers
87 *
Michael Wright872db4f2014-04-22 15:03:51 -070088 * NOTE: If you add LEDs here, you must also add them to InputEventLabels.h
Michael Wright962a1082013-10-17 17:35:53 -070089 */
90
91 ALED_NUM_LOCK = 0x00,
92 ALED_CAPS_LOCK = 0x01,
93 ALED_SCROLL_LOCK = 0x02,
94 ALED_COMPOSE = 0x03,
95 ALED_KANA = 0x04,
96 ALED_SLEEP = 0x05,
97 ALED_SUSPEND = 0x06,
98 ALED_MUTE = 0x07,
99 ALED_MISC = 0x08,
100 ALED_MAIL = 0x09,
101 ALED_CHARGING = 0x0a,
102 ALED_CONTROLLER_1 = 0x10,
103 ALED_CONTROLLER_2 = 0x11,
104 ALED_CONTROLLER_3 = 0x12,
105 ALED_CONTROLLER_4 = 0x13,
106};
107
Michael Wright9b04f862013-10-18 17:53:50 -0700108/* Maximum number of controller LEDs we support */
109#define MAX_CONTROLLER_LEDS 4
110
Jeff Brown5912f952013-07-01 19:10:31 -0700111/*
112 * SystemUiVisibility constants from View.
113 */
114enum {
115 ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE = 0,
116 ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN = 0x00000001,
117};
118
119/*
120 * Maximum number of pointers supported per motion event.
121 * Smallest number of pointers is 1.
122 * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers
123 * will occasionally emit 11. There is not much harm making this constant bigger.)
124 */
125#define MAX_POINTERS 16
126
127/*
Flanker552a8a52015-09-07 15:28:58 +0800128 * Maximum number of samples supported per motion event.
129 */
130#define MAX_SAMPLES UINT16_MAX
131
132/*
Jeff Brown5912f952013-07-01 19:10:31 -0700133 * Maximum pointer id value supported in a motion event.
134 * Smallest pointer id is 0.
135 * (This is limited by our use of BitSet32 to track pointer assignments.)
136 */
137#define MAX_POINTER_ID 31
138
139/*
140 * Declare a concrete type for the NDK's input event forward declaration.
141 */
142struct AInputEvent {
143 virtual ~AInputEvent() { }
144};
145
146/*
147 * Declare a concrete type for the NDK's input device forward declaration.
148 */
149struct AInputDevice {
150 virtual ~AInputDevice() { }
151};
152
153
154namespace android {
155
Elliott Hughes6071da72015-08-12 15:27:47 -0700156#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700157class Parcel;
158#endif
159
160/*
161 * Flags that flow alongside events in the input dispatch system to help with certain
162 * policy decisions such as waking from device sleep.
163 *
164 * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java.
165 */
166enum {
167 /* These flags originate in RawEvents and are generally set in the key map.
Michael Wright872db4f2014-04-22 15:03:51 -0700168 * NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to
169 * InputEventLabels.h as well. */
Jeff Brown5912f952013-07-01 19:10:31 -0700170
Jeff Brownc9aa6282015-02-11 19:03:28 -0800171 // Indicates that the event should wake the device.
Jeff Brown5912f952013-07-01 19:10:31 -0700172 POLICY_FLAG_WAKE = 0x00000001,
Jeff Brownc9aa6282015-02-11 19:03:28 -0800173
174 // Indicates that the key is virtual, such as a capacitive button, and should
175 // generate haptic feedback. Virtual keys may be suppressed for some time
176 // after a recent touch to prevent accidental activation of virtual keys adjacent
177 // to the touch screen during an edge swipe.
Michael Wright872db4f2014-04-22 15:03:51 -0700178 POLICY_FLAG_VIRTUAL = 0x00000002,
Jeff Brownc9aa6282015-02-11 19:03:28 -0800179
180 // Indicates that the key is the special function modifier.
Michael Wright872db4f2014-04-22 15:03:51 -0700181 POLICY_FLAG_FUNCTION = 0x00000004,
Jeff Brown5912f952013-07-01 19:10:31 -0700182
Jeff Brownc9aa6282015-02-11 19:03:28 -0800183 // Indicates that the key represents a special gesture that has been detected by
184 // the touch firmware or driver. Causes touch events from the same device to be canceled.
185 POLICY_FLAG_GESTURE = 0x00000008,
186
Jeff Brown5912f952013-07-01 19:10:31 -0700187 POLICY_FLAG_RAW_MASK = 0x0000ffff,
188
189 /* These flags are set by the input dispatcher. */
190
191 // Indicates that the input event was injected.
192 POLICY_FLAG_INJECTED = 0x01000000,
193
194 // Indicates that the input event is from a trusted source such as a directly attached
195 // input device or an application with system-wide event injection permission.
196 POLICY_FLAG_TRUSTED = 0x02000000,
197
198 // Indicates that the input event has passed through an input filter.
199 POLICY_FLAG_FILTERED = 0x04000000,
200
201 // Disables automatic key repeating behavior.
202 POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000,
203
204 /* These flags are set by the input reader policy as it intercepts each event. */
205
Jeff Browndb19e462014-04-08 19:55:38 -0700206 // Indicates that the device was in an interactive state when the
207 // event was intercepted.
208 POLICY_FLAG_INTERACTIVE = 0x20000000,
Jeff Brown5912f952013-07-01 19:10:31 -0700209
210 // Indicates that the event should be dispatched to applications.
211 // The input event should still be sent to the InputDispatcher so that it can see all
212 // input events received include those that it will not deliver.
213 POLICY_FLAG_PASS_TO_USER = 0x40000000,
214};
215
216/*
217 * Pointer coordinate data.
218 */
219struct PointerCoords {
Michael Wright8f6710f2014-06-09 18:56:43 -0700220 enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128
Jeff Brown5912f952013-07-01 19:10:31 -0700221
222 // Bitfield of axes that are present in this structure.
Fengwei Yin83e0e422014-05-24 05:32:09 +0800223 uint64_t bits __attribute__((aligned(8)));
Jeff Brown5912f952013-07-01 19:10:31 -0700224
225 // Values of axes that are stored in this structure packed in order by axis id
226 // for each axis that is present in the structure according to 'bits'.
227 float values[MAX_AXES];
228
229 inline void clear() {
Michael Wrightd0bd3912014-03-19 12:06:10 -0700230 BitSet64::clear(bits);
231 }
232
233 bool isEmpty() const {
234 return BitSet64::isEmpty(bits);
Jeff Brown5912f952013-07-01 19:10:31 -0700235 }
236
237 float getAxisValue(int32_t axis) const;
238 status_t setAxisValue(int32_t axis, float value);
239
240 void scale(float scale);
Jeff Browned4d28d2014-02-11 14:28:48 -0800241 void applyOffset(float xOffset, float yOffset);
Jeff Brown5912f952013-07-01 19:10:31 -0700242
243 inline float getX() const {
244 return getAxisValue(AMOTION_EVENT_AXIS_X);
245 }
246
247 inline float getY() const {
248 return getAxisValue(AMOTION_EVENT_AXIS_Y);
249 }
250
Elliott Hughes6071da72015-08-12 15:27:47 -0700251#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700252 status_t readFromParcel(Parcel* parcel);
253 status_t writeToParcel(Parcel* parcel) const;
254#endif
255
256 bool operator==(const PointerCoords& other) const;
257 inline bool operator!=(const PointerCoords& other) const {
258 return !(*this == other);
259 }
260
261 void copyFrom(const PointerCoords& other);
262
263private:
264 void tooManyAxes(int axis);
265};
266
267/*
268 * Pointer property data.
269 */
270struct PointerProperties {
271 // The id of the pointer.
272 int32_t id;
273
274 // The pointer tool type.
275 int32_t toolType;
276
277 inline void clear() {
278 id = -1;
279 toolType = 0;
280 }
281
282 bool operator==(const PointerProperties& other) const;
283 inline bool operator!=(const PointerProperties& other) const {
284 return !(*this == other);
285 }
286
287 void copyFrom(const PointerProperties& other);
288};
289
290/*
291 * Input events.
292 */
293class InputEvent : public AInputEvent {
294public:
295 virtual ~InputEvent() { }
296
297 virtual int32_t getType() const = 0;
298
299 inline int32_t getDeviceId() const { return mDeviceId; }
300
301 inline int32_t getSource() const { return mSource; }
302
303 inline void setSource(int32_t source) { mSource = source; }
304
305protected:
306 void initialize(int32_t deviceId, int32_t source);
307 void initialize(const InputEvent& from);
308
309 int32_t mDeviceId;
310 int32_t mSource;
311};
312
313/*
314 * Key events.
315 */
316class KeyEvent : public InputEvent {
317public:
318 virtual ~KeyEvent() { }
319
320 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
321
322 inline int32_t getAction() const { return mAction; }
323
324 inline int32_t getFlags() const { return mFlags; }
325
326 inline void setFlags(int32_t flags) { mFlags = flags; }
327
328 inline int32_t getKeyCode() const { return mKeyCode; }
329
330 inline int32_t getScanCode() const { return mScanCode; }
331
332 inline int32_t getMetaState() const { return mMetaState; }
333
334 inline int32_t getRepeatCount() const { return mRepeatCount; }
335
336 inline nsecs_t getDownTime() const { return mDownTime; }
337
338 inline nsecs_t getEventTime() const { return mEventTime; }
339
Michael Wright872db4f2014-04-22 15:03:51 -0700340 static const char* getLabel(int32_t keyCode);
341 static int32_t getKeyCodeFromLabel(const char* label);
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800342
Jeff Brown5912f952013-07-01 19:10:31 -0700343 void initialize(
344 int32_t deviceId,
345 int32_t source,
346 int32_t action,
347 int32_t flags,
348 int32_t keyCode,
349 int32_t scanCode,
350 int32_t metaState,
351 int32_t repeatCount,
352 nsecs_t downTime,
353 nsecs_t eventTime);
354 void initialize(const KeyEvent& from);
355
356protected:
357 int32_t mAction;
358 int32_t mFlags;
359 int32_t mKeyCode;
360 int32_t mScanCode;
361 int32_t mMetaState;
362 int32_t mRepeatCount;
363 nsecs_t mDownTime;
364 nsecs_t mEventTime;
365};
366
367/*
368 * Motion events.
369 */
370class MotionEvent : public InputEvent {
371public:
372 virtual ~MotionEvent() { }
373
374 virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
375
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800376 inline int32_t getDisplayId() const { return mDisplayId; }
377
378 inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }
379
Jeff Brown5912f952013-07-01 19:10:31 -0700380 inline int32_t getAction() const { return mAction; }
381
382 inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
383
384 inline int32_t getActionIndex() const {
385 return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
386 >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
387 }
388
389 inline void setAction(int32_t action) { mAction = action; }
390
391 inline int32_t getFlags() const { return mFlags; }
392
393 inline void setFlags(int32_t flags) { mFlags = flags; }
394
395 inline int32_t getEdgeFlags() const { return mEdgeFlags; }
396
397 inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; }
398
399 inline int32_t getMetaState() const { return mMetaState; }
400
401 inline void setMetaState(int32_t metaState) { mMetaState = metaState; }
402
403 inline int32_t getButtonState() const { return mButtonState; }
404
Michael Wright6db58792016-09-14 19:53:37 +0100405 inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; }
Michael Wright7b159c92015-05-14 14:48:03 +0100406
407 inline int32_t getActionButton() const { return mActionButton; }
408
Michael Wright21957b92015-06-17 21:06:54 +0100409 inline void setActionButton(int32_t button) { mActionButton = button; }
410
Jeff Brown5912f952013-07-01 19:10:31 -0700411 inline float getXOffset() const { return mXOffset; }
412
413 inline float getYOffset() const { return mYOffset; }
414
415 inline float getXPrecision() const { return mXPrecision; }
416
417 inline float getYPrecision() const { return mYPrecision; }
418
419 inline nsecs_t getDownTime() const { return mDownTime; }
420
421 inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; }
422
423 inline size_t getPointerCount() const { return mPointerProperties.size(); }
424
425 inline const PointerProperties* getPointerProperties(size_t pointerIndex) const {
426 return &mPointerProperties[pointerIndex];
427 }
428
429 inline int32_t getPointerId(size_t pointerIndex) const {
430 return mPointerProperties[pointerIndex].id;
431 }
432
433 inline int32_t getToolType(size_t pointerIndex) const {
434 return mPointerProperties[pointerIndex].toolType;
435 }
436
437 inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }
438
439 const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;
440
441 float getRawAxisValue(int32_t axis, size_t pointerIndex) const;
442
443 inline float getRawX(size_t pointerIndex) const {
444 return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
445 }
446
447 inline float getRawY(size_t pointerIndex) const {
448 return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
449 }
450
451 float getAxisValue(int32_t axis, size_t pointerIndex) const;
452
453 inline float getX(size_t pointerIndex) const {
454 return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
455 }
456
457 inline float getY(size_t pointerIndex) const {
458 return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
459 }
460
461 inline float getPressure(size_t pointerIndex) const {
462 return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex);
463 }
464
465 inline float getSize(size_t pointerIndex) const {
466 return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex);
467 }
468
469 inline float getTouchMajor(size_t pointerIndex) const {
470 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex);
471 }
472
473 inline float getTouchMinor(size_t pointerIndex) const {
474 return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex);
475 }
476
477 inline float getToolMajor(size_t pointerIndex) const {
478 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex);
479 }
480
481 inline float getToolMinor(size_t pointerIndex) const {
482 return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex);
483 }
484
485 inline float getOrientation(size_t pointerIndex) const {
486 return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex);
487 }
488
489 inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
490
491 inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const {
492 return mSampleEventTimes[historicalIndex];
493 }
494
495 const PointerCoords* getHistoricalRawPointerCoords(
496 size_t pointerIndex, size_t historicalIndex) const;
497
498 float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
499 size_t historicalIndex) const;
500
501 inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const {
502 return getHistoricalRawAxisValue(
503 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
504 }
505
506 inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const {
507 return getHistoricalRawAxisValue(
508 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
509 }
510
511 float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const;
512
513 inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const {
514 return getHistoricalAxisValue(
515 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
516 }
517
518 inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const {
519 return getHistoricalAxisValue(
520 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
521 }
522
523 inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const {
524 return getHistoricalAxisValue(
525 AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex);
526 }
527
528 inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const {
529 return getHistoricalAxisValue(
530 AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex);
531 }
532
533 inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
534 return getHistoricalAxisValue(
535 AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex);
536 }
537
538 inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
539 return getHistoricalAxisValue(
540 AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex);
541 }
542
543 inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
544 return getHistoricalAxisValue(
545 AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex);
546 }
547
548 inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
549 return getHistoricalAxisValue(
550 AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex);
551 }
552
553 inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
554 return getHistoricalAxisValue(
555 AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex);
556 }
557
558 ssize_t findPointerIndex(int32_t pointerId) const;
559
560 void initialize(
561 int32_t deviceId,
562 int32_t source,
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800563 int32_t displayId,
Jeff Brown5912f952013-07-01 19:10:31 -0700564 int32_t action,
Michael Wright7b159c92015-05-14 14:48:03 +0100565 int32_t actionButton,
Jeff Brown5912f952013-07-01 19:10:31 -0700566 int32_t flags,
567 int32_t edgeFlags,
568 int32_t metaState,
569 int32_t buttonState,
570 float xOffset,
571 float yOffset,
572 float xPrecision,
573 float yPrecision,
574 nsecs_t downTime,
575 nsecs_t eventTime,
576 size_t pointerCount,
577 const PointerProperties* pointerProperties,
578 const PointerCoords* pointerCoords);
579
580 void copyFrom(const MotionEvent* other, bool keepHistory);
581
582 void addSample(
583 nsecs_t eventTime,
584 const PointerCoords* pointerCoords);
585
586 void offsetLocation(float xOffset, float yOffset);
587
588 void scale(float scaleFactor);
589
Jeff Brown5a2f68e2013-07-15 17:28:19 -0700590 // Apply 3x3 perspective matrix transformation.
591 // Matrix is in row-major form and compatible with SkMatrix.
592 void transform(const float matrix[9]);
Jeff Brown5912f952013-07-01 19:10:31 -0700593
Elliott Hughes6071da72015-08-12 15:27:47 -0700594#ifdef __ANDROID__
Jeff Brown5912f952013-07-01 19:10:31 -0700595 status_t readFromParcel(Parcel* parcel);
596 status_t writeToParcel(Parcel* parcel) const;
597#endif
598
599 static bool isTouchEvent(int32_t source, int32_t action);
600 inline bool isTouchEvent() const {
601 return isTouchEvent(mSource, mAction);
602 }
603
604 // Low-level accessors.
605 inline const PointerProperties* getPointerProperties() const {
606 return mPointerProperties.array();
607 }
608 inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); }
609 inline const PointerCoords* getSamplePointerCoords() const {
610 return mSamplePointerCoords.array();
611 }
612
Michael Wright872db4f2014-04-22 15:03:51 -0700613 static const char* getLabel(int32_t axis);
614 static int32_t getAxisFromLabel(const char* label);
615
Jeff Brown5912f952013-07-01 19:10:31 -0700616protected:
Siarhei Vishniakou777a10b2018-01-31 16:45:06 -0800617 int32_t mDisplayId;
Jeff Brown5912f952013-07-01 19:10:31 -0700618 int32_t mAction;
Michael Wright7b159c92015-05-14 14:48:03 +0100619 int32_t mActionButton;
Jeff Brown5912f952013-07-01 19:10:31 -0700620 int32_t mFlags;
621 int32_t mEdgeFlags;
622 int32_t mMetaState;
623 int32_t mButtonState;
624 float mXOffset;
625 float mYOffset;
626 float mXPrecision;
627 float mYPrecision;
628 nsecs_t mDownTime;
629 Vector<PointerProperties> mPointerProperties;
630 Vector<nsecs_t> mSampleEventTimes;
631 Vector<PointerCoords> mSamplePointerCoords;
632};
633
634/*
635 * Input event factory.
636 */
637class InputEventFactoryInterface {
638protected:
639 virtual ~InputEventFactoryInterface() { }
640
641public:
642 InputEventFactoryInterface() { }
643
644 virtual KeyEvent* createKeyEvent() = 0;
645 virtual MotionEvent* createMotionEvent() = 0;
646};
647
648/*
649 * A simple input event factory implementation that uses a single preallocated instance
650 * of each type of input event that are reused for each request.
651 */
652class PreallocatedInputEventFactory : public InputEventFactoryInterface {
653public:
654 PreallocatedInputEventFactory() { }
655 virtual ~PreallocatedInputEventFactory() { }
656
657 virtual KeyEvent* createKeyEvent() { return & mKeyEvent; }
658 virtual MotionEvent* createMotionEvent() { return & mMotionEvent; }
659
660private:
661 KeyEvent mKeyEvent;
662 MotionEvent mMotionEvent;
663};
664
665/*
666 * An input event factory implementation that maintains a pool of input events.
667 */
668class PooledInputEventFactory : public InputEventFactoryInterface {
669public:
670 PooledInputEventFactory(size_t maxPoolSize = 20);
671 virtual ~PooledInputEventFactory();
672
673 virtual KeyEvent* createKeyEvent();
674 virtual MotionEvent* createMotionEvent();
675
676 void recycle(InputEvent* event);
677
678private:
679 const size_t mMaxPoolSize;
680
681 Vector<KeyEvent*> mKeyEventPool;
682 Vector<MotionEvent*> mMotionEventPool;
683};
684
685} // namespace android
686
687#endif // _LIBINPUT_INPUT_H