Home | History | Annotate | Download | only in input
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef _LIBINPUT_INPUT_H
     18 #define _LIBINPUT_INPUT_H
     19 
     20 #pragma GCC system_header
     21 
     22 /**
     23  * Native input event structures.
     24  */
     25 
     26 #include <android/input.h>
     27 #include <utils/BitSet.h>
     28 #include <utils/KeyedVector.h>
     29 #include <utils/RefBase.h>
     30 #include <utils/Timers.h>
     31 #include <utils/Vector.h>
     32 #include <stdint.h>
     33 
     34 /*
     35  * Additional private constants not defined in ndk/ui/input.h.
     36  */
     37 enum {
     38     /* Signifies that the key is being predispatched */
     39     AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000,
     40 
     41     /* Private control to determine when an app is tracking a key sequence. */
     42     AKEY_EVENT_FLAG_START_TRACKING = 0x40000000,
     43 
     44     /* Key event is inconsistent with previously sent key events. */
     45     AKEY_EVENT_FLAG_TAINTED = 0x80000000,
     46 };
     47 
     48 enum {
     49 
     50     /**
     51      * This flag indicates that the window that received this motion event is partly
     52      * or wholly obscured by another visible window above it.  This flag is set to true
     53      * even if the event did not directly pass through the obscured area.
     54      * A security sensitive application can check this flag to identify situations in which
     55      * a malicious application may have covered up part of its content for the purpose
     56      * of misleading the user or hijacking touches.  An appropriate response might be
     57      * to drop the suspect touches or to take additional precautions to confirm the user's
     58      * actual intent.
     59      */
     60     AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2,
     61 
     62     /**
     63      * This flag indicates that the event has been generated by a gesture generator. It
     64      * provides a hint to the GestureDetector to not apply any touch slop.
     65      */
     66     AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = 0x8,
     67 
     68     /* Motion event is inconsistent with previously sent motion events. */
     69     AMOTION_EVENT_FLAG_TAINTED = 0x80000000,
     70 };
     71 
     72 enum {
     73     /* Used when a motion event is not associated with any display.
     74      * Typically used for non-pointer events. */
     75     ADISPLAY_ID_NONE = -1,
     76 
     77     /* The default display id. */
     78     ADISPLAY_ID_DEFAULT = 0,
     79 };
     80 
     81 enum {
     82     /*
     83      * Indicates that an input device has switches.
     84      * This input source flag is hidden from the API because switches are only used by the system
     85      * and applications have no way to interact with them.
     86      */
     87     AINPUT_SOURCE_SWITCH = 0x80000000,
     88 };
     89 
     90 enum {
     91     /**
     92      * Constants for LEDs. Hidden from the API since we don't actually expose a way to interact
     93      * with LEDs to developers
     94      *
     95      * NOTE: If you add LEDs here, you must also add them to InputEventLabels.h
     96      */
     97 
     98     ALED_NUM_LOCK = 0x00,
     99     ALED_CAPS_LOCK = 0x01,
    100     ALED_SCROLL_LOCK = 0x02,
    101     ALED_COMPOSE = 0x03,
    102     ALED_KANA = 0x04,
    103     ALED_SLEEP = 0x05,
    104     ALED_SUSPEND = 0x06,
    105     ALED_MUTE = 0x07,
    106     ALED_MISC = 0x08,
    107     ALED_MAIL = 0x09,
    108     ALED_CHARGING = 0x0a,
    109     ALED_CONTROLLER_1 = 0x10,
    110     ALED_CONTROLLER_2 = 0x11,
    111     ALED_CONTROLLER_3 = 0x12,
    112     ALED_CONTROLLER_4 = 0x13,
    113 };
    114 
    115 /* Maximum number of controller LEDs we support */
    116 #define MAX_CONTROLLER_LEDS 4
    117 
    118 /*
    119  * SystemUiVisibility constants from View.
    120  */
    121 enum {
    122     ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE = 0,
    123     ASYSTEM_UI_VISIBILITY_STATUS_BAR_HIDDEN = 0x00000001,
    124 };
    125 
    126 /*
    127  * Maximum number of pointers supported per motion event.
    128  * Smallest number of pointers is 1.
    129  * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers
    130  * will occasionally emit 11.  There is not much harm making this constant bigger.)
    131  */
    132 #define MAX_POINTERS 16
    133 
    134 /*
    135  * Maximum number of samples supported per motion event.
    136  */
    137 #define MAX_SAMPLES UINT16_MAX
    138 
    139 /*
    140  * Maximum pointer id value supported in a motion event.
    141  * Smallest pointer id is 0.
    142  * (This is limited by our use of BitSet32 to track pointer assignments.)
    143  */
    144 #define MAX_POINTER_ID 31
    145 
    146 /*
    147  * Declare a concrete type for the NDK's input event forward declaration.
    148  */
    149 struct AInputEvent {
    150     virtual ~AInputEvent() { }
    151 };
    152 
    153 /*
    154  * Declare a concrete type for the NDK's input device forward declaration.
    155  */
    156 struct AInputDevice {
    157     virtual ~AInputDevice() { }
    158 };
    159 
    160 
    161 namespace android {
    162 
    163 #ifdef __ANDROID__
    164 class Parcel;
    165 #endif
    166 
    167 /*
    168  * Flags that flow alongside events in the input dispatch system to help with certain
    169  * policy decisions such as waking from device sleep.
    170  *
    171  * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java.
    172  */
    173 enum {
    174     /* These flags originate in RawEvents and are generally set in the key map.
    175      * NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to
    176      * InputEventLabels.h as well. */
    177 
    178     // Indicates that the event should wake the device.
    179     POLICY_FLAG_WAKE = 0x00000001,
    180 
    181     // Indicates that the key is virtual, such as a capacitive button, and should
    182     // generate haptic feedback.  Virtual keys may be suppressed for some time
    183     // after a recent touch to prevent accidental activation of virtual keys adjacent
    184     // to the touch screen during an edge swipe.
    185     POLICY_FLAG_VIRTUAL = 0x00000002,
    186 
    187     // Indicates that the key is the special function modifier.
    188     POLICY_FLAG_FUNCTION = 0x00000004,
    189 
    190     // Indicates that the key represents a special gesture that has been detected by
    191     // the touch firmware or driver.  Causes touch events from the same device to be canceled.
    192     POLICY_FLAG_GESTURE = 0x00000008,
    193 
    194     POLICY_FLAG_RAW_MASK = 0x0000ffff,
    195 
    196     /* These flags are set by the input dispatcher. */
    197 
    198     // Indicates that the input event was injected.
    199     POLICY_FLAG_INJECTED = 0x01000000,
    200 
    201     // Indicates that the input event is from a trusted source such as a directly attached
    202     // input device or an application with system-wide event injection permission.
    203     POLICY_FLAG_TRUSTED = 0x02000000,
    204 
    205     // Indicates that the input event has passed through an input filter.
    206     POLICY_FLAG_FILTERED = 0x04000000,
    207 
    208     // Disables automatic key repeating behavior.
    209     POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000,
    210 
    211     /* These flags are set by the input reader policy as it intercepts each event. */
    212 
    213     // Indicates that the device was in an interactive state when the
    214     // event was intercepted.
    215     POLICY_FLAG_INTERACTIVE = 0x20000000,
    216 
    217     // Indicates that the event should be dispatched to applications.
    218     // The input event should still be sent to the InputDispatcher so that it can see all
    219     // input events received include those that it will not deliver.
    220     POLICY_FLAG_PASS_TO_USER = 0x40000000,
    221 };
    222 
    223 /**
    224  * Classifications of the current gesture, if available.
    225  *
    226  * The following values must be kept in sync with MotionEvent.java
    227  */
    228 enum class MotionClassification : uint8_t {
    229     /**
    230      * No classification is available.
    231      */
    232     NONE = 0,
    233     /**
    234      * Too early to classify the current gesture. Need more events. Look for changes in the
    235      * upcoming motion events.
    236      */
    237     AMBIGUOUS_GESTURE = 1,
    238     /**
    239      * The current gesture likely represents a user intentionally exerting force on the touchscreen.
    240      */
    241     DEEP_PRESS = 2,
    242 };
    243 
    244 /**
    245  * String representation of MotionClassification
    246  */
    247 const char* motionClassificationToString(MotionClassification classification);
    248 
    249 /*
    250  * Pointer coordinate data.
    251  */
    252 struct PointerCoords {
    253     enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128
    254 
    255     // Bitfield of axes that are present in this structure.
    256     uint64_t bits __attribute__((aligned(8)));
    257 
    258     // Values of axes that are stored in this structure packed in order by axis id
    259     // for each axis that is present in the structure according to 'bits'.
    260     float values[MAX_AXES];
    261 
    262     inline void clear() {
    263         BitSet64::clear(bits);
    264     }
    265 
    266     bool isEmpty() const {
    267         return BitSet64::isEmpty(bits);
    268     }
    269 
    270     float getAxisValue(int32_t axis) const;
    271     status_t setAxisValue(int32_t axis, float value);
    272 
    273     void scale(float globalScale);
    274 
    275     // Scale the pointer coordinates according to a global scale and a
    276     // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR
    277     // axes, however the window scaling will not.
    278     void scale(float globalScale, float windowXScale, float windowYScale);
    279     void applyOffset(float xOffset, float yOffset);
    280 
    281     inline float getX() const {
    282         return getAxisValue(AMOTION_EVENT_AXIS_X);
    283     }
    284 
    285     inline float getY() const {
    286         return getAxisValue(AMOTION_EVENT_AXIS_Y);
    287     }
    288 
    289 #ifdef __ANDROID__
    290     status_t readFromParcel(Parcel* parcel);
    291     status_t writeToParcel(Parcel* parcel) const;
    292 #endif
    293 
    294     bool operator==(const PointerCoords& other) const;
    295     inline bool operator!=(const PointerCoords& other) const {
    296         return !(*this == other);
    297     }
    298 
    299     void copyFrom(const PointerCoords& other);
    300 
    301 private:
    302     void tooManyAxes(int axis);
    303 };
    304 
    305 /*
    306  * Pointer property data.
    307  */
    308 struct PointerProperties {
    309     // The id of the pointer.
    310     int32_t id;
    311 
    312     // The pointer tool type.
    313     int32_t toolType;
    314 
    315     inline void clear() {
    316         id = -1;
    317         toolType = 0;
    318     }
    319 
    320     bool operator==(const PointerProperties& other) const;
    321     inline bool operator!=(const PointerProperties& other) const {
    322         return !(*this == other);
    323     }
    324 
    325     void copyFrom(const PointerProperties& other);
    326 };
    327 
    328 /*
    329  * Input events.
    330  */
    331 class InputEvent : public AInputEvent {
    332 public:
    333     virtual ~InputEvent() { }
    334 
    335     virtual int32_t getType() const = 0;
    336 
    337     inline int32_t getDeviceId() const { return mDeviceId; }
    338 
    339     inline int32_t getSource() const { return mSource; }
    340 
    341     inline void setSource(int32_t source) { mSource = source; }
    342 
    343     inline int32_t getDisplayId() const { return mDisplayId; }
    344 
    345     inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; }
    346 
    347 
    348 protected:
    349     void initialize(int32_t deviceId, int32_t source, int32_t displayId);
    350     void initialize(const InputEvent& from);
    351 
    352     int32_t mDeviceId;
    353     int32_t mSource;
    354     int32_t mDisplayId;
    355 };
    356 
    357 /*
    358  * Key events.
    359  */
    360 class KeyEvent : public InputEvent {
    361 public:
    362     virtual ~KeyEvent() { }
    363 
    364     virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; }
    365 
    366     inline int32_t getAction() const { return mAction; }
    367 
    368     inline int32_t getFlags() const { return mFlags; }
    369 
    370     inline void setFlags(int32_t flags) { mFlags = flags; }
    371 
    372     inline int32_t getKeyCode() const { return mKeyCode; }
    373 
    374     inline int32_t getScanCode() const { return mScanCode; }
    375 
    376     inline int32_t getMetaState() const { return mMetaState; }
    377 
    378     inline int32_t getRepeatCount() const { return mRepeatCount; }
    379 
    380     inline nsecs_t getDownTime() const { return mDownTime; }
    381 
    382     inline nsecs_t getEventTime() const { return mEventTime; }
    383 
    384     static const char* getLabel(int32_t keyCode);
    385     static int32_t getKeyCodeFromLabel(const char* label);
    386 
    387     void initialize(
    388             int32_t deviceId,
    389             int32_t source,
    390             int32_t displayId,
    391             int32_t action,
    392             int32_t flags,
    393             int32_t keyCode,
    394             int32_t scanCode,
    395             int32_t metaState,
    396             int32_t repeatCount,
    397             nsecs_t downTime,
    398             nsecs_t eventTime);
    399     void initialize(const KeyEvent& from);
    400 
    401 protected:
    402     int32_t mAction;
    403     int32_t mFlags;
    404     int32_t mKeyCode;
    405     int32_t mScanCode;
    406     int32_t mMetaState;
    407     int32_t mRepeatCount;
    408     nsecs_t mDownTime;
    409     nsecs_t mEventTime;
    410 };
    411 
    412 /*
    413  * Motion events.
    414  */
    415 class MotionEvent : public InputEvent {
    416 public:
    417     virtual ~MotionEvent() { }
    418 
    419     virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; }
    420 
    421     inline int32_t getAction() const { return mAction; }
    422 
    423     inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
    424 
    425     inline int32_t getActionIndex() const {
    426         return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
    427                 >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
    428     }
    429 
    430     inline void setAction(int32_t action) { mAction = action; }
    431 
    432     inline int32_t getFlags() const { return mFlags; }
    433 
    434     inline void setFlags(int32_t flags) { mFlags = flags; }
    435 
    436     inline int32_t getEdgeFlags() const { return mEdgeFlags; }
    437 
    438     inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; }
    439 
    440     inline int32_t getMetaState() const { return mMetaState; }
    441 
    442     inline void setMetaState(int32_t metaState) { mMetaState = metaState; }
    443 
    444     inline int32_t getButtonState() const { return mButtonState; }
    445 
    446     inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; }
    447 
    448     inline MotionClassification getClassification() const { return mClassification; }
    449 
    450     inline int32_t getActionButton() const { return mActionButton; }
    451 
    452     inline void setActionButton(int32_t button) { mActionButton = button; }
    453 
    454     inline float getXOffset() const { return mXOffset; }
    455 
    456     inline float getYOffset() const { return mYOffset; }
    457 
    458     inline float getXPrecision() const { return mXPrecision; }
    459 
    460     inline float getYPrecision() const { return mYPrecision; }
    461 
    462     inline nsecs_t getDownTime() const { return mDownTime; }
    463 
    464     inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; }
    465 
    466     inline size_t getPointerCount() const { return mPointerProperties.size(); }
    467 
    468     inline const PointerProperties* getPointerProperties(size_t pointerIndex) const {
    469         return &mPointerProperties[pointerIndex];
    470     }
    471 
    472     inline int32_t getPointerId(size_t pointerIndex) const {
    473         return mPointerProperties[pointerIndex].id;
    474     }
    475 
    476     inline int32_t getToolType(size_t pointerIndex) const {
    477         return mPointerProperties[pointerIndex].toolType;
    478     }
    479 
    480     inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; }
    481 
    482     const PointerCoords* getRawPointerCoords(size_t pointerIndex) const;
    483 
    484     float getRawAxisValue(int32_t axis, size_t pointerIndex) const;
    485 
    486     inline float getRawX(size_t pointerIndex) const {
    487         return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
    488     }
    489 
    490     inline float getRawY(size_t pointerIndex) const {
    491         return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
    492     }
    493 
    494     float getAxisValue(int32_t axis, size_t pointerIndex) const;
    495 
    496     inline float getX(size_t pointerIndex) const {
    497         return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex);
    498     }
    499 
    500     inline float getY(size_t pointerIndex) const {
    501         return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex);
    502     }
    503 
    504     inline float getPressure(size_t pointerIndex) const {
    505         return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex);
    506     }
    507 
    508     inline float getSize(size_t pointerIndex) const {
    509         return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex);
    510     }
    511 
    512     inline float getTouchMajor(size_t pointerIndex) const {
    513         return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex);
    514     }
    515 
    516     inline float getTouchMinor(size_t pointerIndex) const {
    517         return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex);
    518     }
    519 
    520     inline float getToolMajor(size_t pointerIndex) const {
    521         return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex);
    522     }
    523 
    524     inline float getToolMinor(size_t pointerIndex) const {
    525         return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex);
    526     }
    527 
    528     inline float getOrientation(size_t pointerIndex) const {
    529         return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex);
    530     }
    531 
    532     inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; }
    533 
    534     inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const {
    535         return mSampleEventTimes[historicalIndex];
    536     }
    537 
    538     const PointerCoords* getHistoricalRawPointerCoords(
    539             size_t pointerIndex, size_t historicalIndex) const;
    540 
    541     float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex,
    542             size_t historicalIndex) const;
    543 
    544     inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const {
    545         return getHistoricalRawAxisValue(
    546                 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
    547     }
    548 
    549     inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const {
    550         return getHistoricalRawAxisValue(
    551                 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
    552     }
    553 
    554     float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const;
    555 
    556     inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const {
    557         return getHistoricalAxisValue(
    558                 AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex);
    559     }
    560 
    561     inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const {
    562         return getHistoricalAxisValue(
    563                 AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex);
    564     }
    565 
    566     inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const {
    567         return getHistoricalAxisValue(
    568                 AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex);
    569     }
    570 
    571     inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const {
    572         return getHistoricalAxisValue(
    573                 AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex);
    574     }
    575 
    576     inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const {
    577         return getHistoricalAxisValue(
    578                 AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex);
    579     }
    580 
    581     inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const {
    582         return getHistoricalAxisValue(
    583                 AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex);
    584     }
    585 
    586     inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const {
    587         return getHistoricalAxisValue(
    588                 AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex);
    589     }
    590 
    591     inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const {
    592         return getHistoricalAxisValue(
    593                 AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex);
    594     }
    595 
    596     inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const {
    597         return getHistoricalAxisValue(
    598                 AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex);
    599     }
    600 
    601     ssize_t findPointerIndex(int32_t pointerId) const;
    602 
    603     void initialize(
    604             int32_t deviceId,
    605             int32_t source,
    606             int32_t displayId,
    607             int32_t action,
    608             int32_t actionButton,
    609             int32_t flags,
    610             int32_t edgeFlags,
    611             int32_t metaState,
    612             int32_t buttonState,
    613             MotionClassification classification,
    614             float xOffset,
    615             float yOffset,
    616             float xPrecision,
    617             float yPrecision,
    618             nsecs_t downTime,
    619             nsecs_t eventTime,
    620             size_t pointerCount,
    621             const PointerProperties* pointerProperties,
    622             const PointerCoords* pointerCoords);
    623 
    624     void copyFrom(const MotionEvent* other, bool keepHistory);
    625 
    626     void addSample(
    627             nsecs_t eventTime,
    628             const PointerCoords* pointerCoords);
    629 
    630     void offsetLocation(float xOffset, float yOffset);
    631 
    632     void scale(float globalScaleFactor);
    633 
    634     // Apply 3x3 perspective matrix transformation.
    635     // Matrix is in row-major form and compatible with SkMatrix.
    636     void transform(const float matrix[9]);
    637 
    638 #ifdef __ANDROID__
    639     status_t readFromParcel(Parcel* parcel);
    640     status_t writeToParcel(Parcel* parcel) const;
    641 #endif
    642 
    643     static bool isTouchEvent(int32_t source, int32_t action);
    644     inline bool isTouchEvent() const {
    645         return isTouchEvent(mSource, mAction);
    646     }
    647 
    648     // Low-level accessors.
    649     inline const PointerProperties* getPointerProperties() const {
    650         return mPointerProperties.array();
    651     }
    652     inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); }
    653     inline const PointerCoords* getSamplePointerCoords() const {
    654             return mSamplePointerCoords.array();
    655     }
    656 
    657     static const char* getLabel(int32_t axis);
    658     static int32_t getAxisFromLabel(const char* label);
    659 
    660 protected:
    661     int32_t mAction;
    662     int32_t mActionButton;
    663     int32_t mFlags;
    664     int32_t mEdgeFlags;
    665     int32_t mMetaState;
    666     int32_t mButtonState;
    667     MotionClassification mClassification;
    668     float mXOffset;
    669     float mYOffset;
    670     float mXPrecision;
    671     float mYPrecision;
    672     nsecs_t mDownTime;
    673     Vector<PointerProperties> mPointerProperties;
    674     Vector<nsecs_t> mSampleEventTimes;
    675     Vector<PointerCoords> mSamplePointerCoords;
    676 };
    677 
    678 /*
    679  * Input event factory.
    680  */
    681 class InputEventFactoryInterface {
    682 protected:
    683     virtual ~InputEventFactoryInterface() { }
    684 
    685 public:
    686     InputEventFactoryInterface() { }
    687 
    688     virtual KeyEvent* createKeyEvent() = 0;
    689     virtual MotionEvent* createMotionEvent() = 0;
    690 };
    691 
    692 /*
    693  * A simple input event factory implementation that uses a single preallocated instance
    694  * of each type of input event that are reused for each request.
    695  */
    696 class PreallocatedInputEventFactory : public InputEventFactoryInterface {
    697 public:
    698     PreallocatedInputEventFactory() { }
    699     virtual ~PreallocatedInputEventFactory() { }
    700 
    701     virtual KeyEvent* createKeyEvent() { return & mKeyEvent; }
    702     virtual MotionEvent* createMotionEvent() { return & mMotionEvent; }
    703 
    704 private:
    705     KeyEvent mKeyEvent;
    706     MotionEvent mMotionEvent;
    707 };
    708 
    709 /*
    710  * An input event factory implementation that maintains a pool of input events.
    711  */
    712 class PooledInputEventFactory : public InputEventFactoryInterface {
    713 public:
    714     explicit PooledInputEventFactory(size_t maxPoolSize = 20);
    715     virtual ~PooledInputEventFactory();
    716 
    717     virtual KeyEvent* createKeyEvent();
    718     virtual MotionEvent* createMotionEvent();
    719 
    720     void recycle(InputEvent* event);
    721 
    722 private:
    723     const size_t mMaxPoolSize;
    724 
    725     Vector<KeyEvent*> mKeyEventPool;
    726     Vector<MotionEvent*> mMotionEventPool;
    727 };
    728 
    729 } // namespace android
    730 
    731 #endif // _LIBINPUT_INPUT_H
    732