| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * Copyright (C) 2010 The Android Open Source Project | 
|  | 3 | * | 
|  | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | * you may not use this file except in compliance with the License. | 
|  | 6 | * You may obtain a copy of the License at | 
|  | 7 | * | 
|  | 8 | *      http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | * | 
|  | 10 | * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | * See the License for the specific language governing permissions and | 
|  | 14 | * limitations under the License. | 
|  | 15 | */ | 
|  | 16 |  | 
|  | 17 | #ifndef _LIBINPUT_INPUT_H | 
|  | 18 | #define _LIBINPUT_INPUT_H | 
|  | 19 |  | 
| Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 20 | #pragma GCC system_header | 
|  | 21 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 22 | /** | 
|  | 23 | * Native input event structures. | 
|  | 24 | */ | 
|  | 25 |  | 
|  | 26 | #include <android/input.h> | 
| Garfield Tan | ab0ab9c | 2019-07-10 18:58:28 -0700 | [diff] [blame] | 27 | #include <math.h> | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 28 | #include <stdint.h> | 
| chaviw | fd9c1ed | 2020-07-01 10:57:59 -0700 | [diff] [blame] | 29 | #include <ui/Transform.h> | 
| Michael Wright | d0bd391 | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 30 | #include <utils/BitSet.h> | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 31 | #include <utils/KeyedVector.h> | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 32 | #include <utils/RefBase.h> | 
| Michael Wright | d0bd391 | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 33 | #include <utils/Timers.h> | 
|  | 34 | #include <utils/Vector.h> | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 35 | #include <array> | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 36 | #include <limits> | 
| Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 37 | #include <queue> | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 38 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 39 | /* | 
|  | 40 | * Additional private constants not defined in ndk/ui/input.h. | 
|  | 41 | */ | 
|  | 42 | enum { | 
|  | 43 | /* Signifies that the key is being predispatched */ | 
|  | 44 | AKEY_EVENT_FLAG_PREDISPATCH = 0x20000000, | 
|  | 45 |  | 
|  | 46 | /* Private control to determine when an app is tracking a key sequence. */ | 
|  | 47 | AKEY_EVENT_FLAG_START_TRACKING = 0x40000000, | 
|  | 48 |  | 
|  | 49 | /* Key event is inconsistent with previously sent key events. */ | 
|  | 50 | AKEY_EVENT_FLAG_TAINTED = 0x80000000, | 
|  | 51 | }; | 
|  | 52 |  | 
|  | 53 | enum { | 
| Michael Wright | cdcd8f2 | 2016-03-22 16:52:13 -0700 | [diff] [blame] | 54 |  | 
|  | 55 | /** | 
|  | 56 | * This flag indicates that the window that received this motion event is partly | 
|  | 57 | * or wholly obscured by another visible window above it.  This flag is set to true | 
|  | 58 | * even if the event did not directly pass through the obscured area. | 
|  | 59 | * A security sensitive application can check this flag to identify situations in which | 
|  | 60 | * a malicious application may have covered up part of its content for the purpose | 
|  | 61 | * of misleading the user or hijacking touches.  An appropriate response might be | 
|  | 62 | * to drop the suspect touches or to take additional precautions to confirm the user's | 
|  | 63 | * actual intent. | 
|  | 64 | */ | 
|  | 65 | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2, | 
|  | 66 |  | 
| Prabir Pradhan | 141a986 | 2018-11-19 14:35:56 -0800 | [diff] [blame] | 67 | /** | 
|  | 68 | * This flag indicates that the event has been generated by a gesture generator. It | 
|  | 69 | * provides a hint to the GestureDetector to not apply any touch slop. | 
|  | 70 | */ | 
|  | 71 | AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE = 0x8, | 
|  | 72 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 73 | /* Motion event is inconsistent with previously sent motion events. */ | 
|  | 74 | AMOTION_EVENT_FLAG_TAINTED = 0x80000000, | 
|  | 75 | }; | 
|  | 76 |  | 
| Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 77 | /** | 
|  | 78 | * Allowed VerifiedKeyEvent flags. All other flags from KeyEvent do not get verified. | 
|  | 79 | * These values must be kept in sync with VerifiedKeyEvent.java | 
|  | 80 | */ | 
|  | 81 | constexpr int32_t VERIFIED_KEY_EVENT_FLAGS = AKEY_EVENT_FLAG_CANCELED; | 
|  | 82 |  | 
|  | 83 | /** | 
|  | 84 | * Allowed VerifiedMotionEventFlags. All other flags from MotionEvent do not get verified. | 
|  | 85 | * These values must be kept in sync with VerifiedMotionEvent.java | 
|  | 86 | */ | 
|  | 87 | constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS = | 
|  | 88 | AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED; | 
|  | 89 |  | 
| arthurhung | cc7f980 | 2020-04-30 17:55:40 +0800 | [diff] [blame] | 90 | /** | 
|  | 91 | * This flag indicates that the point up event has been canceled. | 
|  | 92 | * Typically this is used for palm event when the user has accidental touches. | 
|  | 93 | * TODO: Adjust flag to public api | 
|  | 94 | */ | 
|  | 95 | constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = 0x20; | 
|  | 96 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 97 | enum { | 
|  | 98 | /* Used when a motion event is not associated with any display. | 
|  | 99 | * Typically used for non-pointer events. */ | 
|  | 100 | ADISPLAY_ID_NONE = -1, | 
|  | 101 |  | 
|  | 102 | /* The default display id. */ | 
|  | 103 | ADISPLAY_ID_DEFAULT = 0, | 
|  | 104 | }; | 
|  | 105 |  | 
|  | 106 | enum { | 
|  | 107 | /* | 
|  | 108 | * Indicates that an input device has switches. | 
|  | 109 | * This input source flag is hidden from the API because switches are only used by the system | 
|  | 110 | * and applications have no way to interact with them. | 
|  | 111 | */ | 
|  | 112 | AINPUT_SOURCE_SWITCH = 0x80000000, | 
|  | 113 | }; | 
|  | 114 |  | 
| Michael Wright | 962a108 | 2013-10-17 17:35:53 -0700 | [diff] [blame] | 115 | enum { | 
|  | 116 | /** | 
|  | 117 | * Constants for LEDs. Hidden from the API since we don't actually expose a way to interact | 
|  | 118 | * with LEDs to developers | 
|  | 119 | * | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 120 | * NOTE: If you add LEDs here, you must also add them to InputEventLabels.h | 
| Michael Wright | 962a108 | 2013-10-17 17:35:53 -0700 | [diff] [blame] | 121 | */ | 
|  | 122 |  | 
|  | 123 | ALED_NUM_LOCK = 0x00, | 
|  | 124 | ALED_CAPS_LOCK = 0x01, | 
|  | 125 | ALED_SCROLL_LOCK = 0x02, | 
|  | 126 | ALED_COMPOSE = 0x03, | 
|  | 127 | ALED_KANA = 0x04, | 
|  | 128 | ALED_SLEEP = 0x05, | 
|  | 129 | ALED_SUSPEND = 0x06, | 
|  | 130 | ALED_MUTE = 0x07, | 
|  | 131 | ALED_MISC = 0x08, | 
|  | 132 | ALED_MAIL = 0x09, | 
|  | 133 | ALED_CHARGING = 0x0a, | 
|  | 134 | ALED_CONTROLLER_1 = 0x10, | 
|  | 135 | ALED_CONTROLLER_2 = 0x11, | 
|  | 136 | ALED_CONTROLLER_3 = 0x12, | 
|  | 137 | ALED_CONTROLLER_4 = 0x13, | 
|  | 138 | }; | 
|  | 139 |  | 
| Michael Wright | 9b04f86 | 2013-10-18 17:53:50 -0700 | [diff] [blame] | 140 | /* Maximum number of controller LEDs we support */ | 
|  | 141 | #define MAX_CONTROLLER_LEDS 4 | 
|  | 142 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 143 | /* | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 144 | * Maximum number of pointers supported per motion event. | 
|  | 145 | * Smallest number of pointers is 1. | 
|  | 146 | * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers | 
|  | 147 | * will occasionally emit 11.  There is not much harm making this constant bigger.) | 
|  | 148 | */ | 
|  | 149 | #define MAX_POINTERS 16 | 
|  | 150 |  | 
|  | 151 | /* | 
| Flanker | 552a8a5 | 2015-09-07 15:28:58 +0800 | [diff] [blame] | 152 | * Maximum number of samples supported per motion event. | 
|  | 153 | */ | 
|  | 154 | #define MAX_SAMPLES UINT16_MAX | 
|  | 155 |  | 
|  | 156 | /* | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 157 | * Maximum pointer id value supported in a motion event. | 
|  | 158 | * Smallest pointer id is 0. | 
|  | 159 | * (This is limited by our use of BitSet32 to track pointer assignments.) | 
|  | 160 | */ | 
|  | 161 | #define MAX_POINTER_ID 31 | 
|  | 162 |  | 
|  | 163 | /* | 
|  | 164 | * Declare a concrete type for the NDK's input event forward declaration. | 
|  | 165 | */ | 
|  | 166 | struct AInputEvent { | 
|  | 167 | virtual ~AInputEvent() { } | 
|  | 168 | }; | 
|  | 169 |  | 
|  | 170 | /* | 
|  | 171 | * Declare a concrete type for the NDK's input device forward declaration. | 
|  | 172 | */ | 
|  | 173 | struct AInputDevice { | 
|  | 174 | virtual ~AInputDevice() { } | 
|  | 175 | }; | 
|  | 176 |  | 
|  | 177 |  | 
|  | 178 | namespace android { | 
|  | 179 |  | 
| Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 180 | #ifdef __linux__ | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 181 | class Parcel; | 
| Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 182 | #endif | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 183 |  | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 184 | const char* inputEventTypeToString(int32_t type); | 
|  | 185 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 186 | /* | 
|  | 187 | * Flags that flow alongside events in the input dispatch system to help with certain | 
|  | 188 | * policy decisions such as waking from device sleep. | 
|  | 189 | * | 
|  | 190 | * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java. | 
|  | 191 | */ | 
|  | 192 | enum { | 
|  | 193 | /* These flags originate in RawEvents and are generally set in the key map. | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 194 | * NOTE: If you want a flag to be able to set in a keylayout file, then you must add it to | 
|  | 195 | * InputEventLabels.h as well. */ | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 196 |  | 
| Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 197 | // Indicates that the event should wake the device. | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 198 | POLICY_FLAG_WAKE = 0x00000001, | 
| Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 199 |  | 
|  | 200 | // Indicates that the key is virtual, such as a capacitive button, and should | 
|  | 201 | // generate haptic feedback.  Virtual keys may be suppressed for some time | 
|  | 202 | // after a recent touch to prevent accidental activation of virtual keys adjacent | 
|  | 203 | // to the touch screen during an edge swipe. | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 204 | POLICY_FLAG_VIRTUAL = 0x00000002, | 
| Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 205 |  | 
|  | 206 | // Indicates that the key is the special function modifier. | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 207 | POLICY_FLAG_FUNCTION = 0x00000004, | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 208 |  | 
| Jeff Brown | c9aa628 | 2015-02-11 19:03:28 -0800 | [diff] [blame] | 209 | // Indicates that the key represents a special gesture that has been detected by | 
|  | 210 | // the touch firmware or driver.  Causes touch events from the same device to be canceled. | 
|  | 211 | POLICY_FLAG_GESTURE = 0x00000008, | 
|  | 212 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 213 | POLICY_FLAG_RAW_MASK = 0x0000ffff, | 
|  | 214 |  | 
|  | 215 | /* These flags are set by the input dispatcher. */ | 
|  | 216 |  | 
|  | 217 | // Indicates that the input event was injected. | 
|  | 218 | POLICY_FLAG_INJECTED = 0x01000000, | 
|  | 219 |  | 
|  | 220 | // Indicates that the input event is from a trusted source such as a directly attached | 
|  | 221 | // input device or an application with system-wide event injection permission. | 
|  | 222 | POLICY_FLAG_TRUSTED = 0x02000000, | 
|  | 223 |  | 
|  | 224 | // Indicates that the input event has passed through an input filter. | 
|  | 225 | POLICY_FLAG_FILTERED = 0x04000000, | 
|  | 226 |  | 
|  | 227 | // Disables automatic key repeating behavior. | 
|  | 228 | POLICY_FLAG_DISABLE_KEY_REPEAT = 0x08000000, | 
|  | 229 |  | 
|  | 230 | /* These flags are set by the input reader policy as it intercepts each event. */ | 
|  | 231 |  | 
| Jeff Brown | db19e46 | 2014-04-08 19:55:38 -0700 | [diff] [blame] | 232 | // Indicates that the device was in an interactive state when the | 
|  | 233 | // event was intercepted. | 
|  | 234 | POLICY_FLAG_INTERACTIVE = 0x20000000, | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 235 |  | 
|  | 236 | // Indicates that the event should be dispatched to applications. | 
|  | 237 | // The input event should still be sent to the InputDispatcher so that it can see all | 
|  | 238 | // input events received include those that it will not deliver. | 
|  | 239 | POLICY_FLAG_PASS_TO_USER = 0x40000000, | 
|  | 240 | }; | 
|  | 241 |  | 
| Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 242 | /** | 
|  | 243 | * Classifications of the current gesture, if available. | 
|  | 244 | * | 
|  | 245 | * The following values must be kept in sync with MotionEvent.java | 
|  | 246 | */ | 
|  | 247 | enum class MotionClassification : uint8_t { | 
|  | 248 | /** | 
|  | 249 | * No classification is available. | 
|  | 250 | */ | 
|  | 251 | NONE = 0, | 
|  | 252 | /** | 
|  | 253 | * Too early to classify the current gesture. Need more events. Look for changes in the | 
|  | 254 | * upcoming motion events. | 
|  | 255 | */ | 
|  | 256 | AMBIGUOUS_GESTURE = 1, | 
|  | 257 | /** | 
|  | 258 | * The current gesture likely represents a user intentionally exerting force on the touchscreen. | 
|  | 259 | */ | 
|  | 260 | DEEP_PRESS = 2, | 
|  | 261 | }; | 
|  | 262 |  | 
| Siarhei Vishniakou | 16a2e30 | 2019-01-14 19:21:45 -0800 | [diff] [blame] | 263 | /** | 
|  | 264 | * String representation of MotionClassification | 
|  | 265 | */ | 
|  | 266 | const char* motionClassificationToString(MotionClassification classification); | 
|  | 267 |  | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 268 | /** | 
| Siarhei Vishniakou | f94ae02 | 2021-02-04 01:23:17 +0000 | [diff] [blame] | 269 | * Portion of FrameMetrics timeline of interest to input code. | 
|  | 270 | */ | 
|  | 271 | enum GraphicsTimeline : size_t { | 
|  | 272 | /** Time when the app sent the buffer to SurfaceFlinger. */ | 
|  | 273 | GPU_COMPLETED_TIME = 0, | 
|  | 274 |  | 
|  | 275 | /** Time when the frame was presented on the display */ | 
|  | 276 | PRESENT_TIME = 1, | 
|  | 277 |  | 
|  | 278 | /** Total size of the 'GraphicsTimeline' array. Must always be last. */ | 
|  | 279 | SIZE = 2 | 
|  | 280 | }; | 
|  | 281 |  | 
|  | 282 | /** | 
| Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 283 | * Generator of unique numbers used to identify input events. | 
|  | 284 | * | 
|  | 285 | * Layout of ID: | 
|  | 286 | *     |--------------------------|---------------------------| | 
|  | 287 | *     |   2 bits for source      | 30 bits for random number | | 
|  | 288 | *     |--------------------------|---------------------------| | 
|  | 289 | */ | 
|  | 290 | class IdGenerator { | 
|  | 291 | private: | 
|  | 292 | static constexpr uint32_t SOURCE_SHIFT = 30; | 
|  | 293 |  | 
|  | 294 | public: | 
|  | 295 | // Used to divide integer space to ensure no conflict among these sources./ | 
|  | 296 | enum class Source : int32_t { | 
| Garfield Tan | 750c7f4 | 2020-05-18 17:41:46 -0700 | [diff] [blame] | 297 | INPUT_READER = static_cast<int32_t>(0x0u << SOURCE_SHIFT), | 
|  | 298 | INPUT_DISPATCHER = static_cast<int32_t>(0x1u << SOURCE_SHIFT), | 
|  | 299 | OTHER = static_cast<int32_t>(0x3u << SOURCE_SHIFT), // E.g. app injected events | 
| Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 300 | }; | 
|  | 301 | IdGenerator(Source source); | 
|  | 302 |  | 
|  | 303 | int32_t nextId() const; | 
|  | 304 |  | 
|  | 305 | // Extract source from given id. | 
|  | 306 | static inline Source getSource(int32_t id) { return static_cast<Source>(SOURCE_MASK & id); } | 
|  | 307 |  | 
|  | 308 | private: | 
|  | 309 | const Source mSource; | 
|  | 310 |  | 
| Garfield Tan | 750c7f4 | 2020-05-18 17:41:46 -0700 | [diff] [blame] | 311 | static constexpr int32_t SOURCE_MASK = static_cast<int32_t>(0x3u << SOURCE_SHIFT); | 
| Garfield Tan | 84b087e | 2020-01-23 10:49:05 -0800 | [diff] [blame] | 312 | }; | 
|  | 313 |  | 
|  | 314 | /** | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 315 | * Invalid value for cursor position. Used for non-mouse events, tests and injected events. Don't | 
|  | 316 | * use it for direct comparison with any other value, because NaN isn't equal to itself according to | 
|  | 317 | * IEEE 754. Use isnan() instead to check if a cursor position is valid. | 
|  | 318 | */ | 
|  | 319 | constexpr float AMOTION_EVENT_INVALID_CURSOR_POSITION = std::numeric_limits<float>::quiet_NaN(); | 
|  | 320 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 321 | /* | 
|  | 322 | * Pointer coordinate data. | 
|  | 323 | */ | 
|  | 324 | struct PointerCoords { | 
| Michael Wright | 8f6710f | 2014-06-09 18:56:43 -0700 | [diff] [blame] | 325 | enum { MAX_AXES = 30 }; // 30 so that sizeof(PointerCoords) == 128 | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 326 |  | 
|  | 327 | // Bitfield of axes that are present in this structure. | 
| Fengwei Yin | 83e0e42 | 2014-05-24 05:32:09 +0800 | [diff] [blame] | 328 | uint64_t bits __attribute__((aligned(8))); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 329 |  | 
|  | 330 | // Values of axes that are stored in this structure packed in order by axis id | 
|  | 331 | // for each axis that is present in the structure according to 'bits'. | 
|  | 332 | float values[MAX_AXES]; | 
|  | 333 |  | 
|  | 334 | inline void clear() { | 
| Michael Wright | d0bd391 | 2014-03-19 12:06:10 -0700 | [diff] [blame] | 335 | BitSet64::clear(bits); | 
|  | 336 | } | 
|  | 337 |  | 
|  | 338 | bool isEmpty() const { | 
|  | 339 | return BitSet64::isEmpty(bits); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 340 | } | 
|  | 341 |  | 
|  | 342 | float getAxisValue(int32_t axis) const; | 
|  | 343 | status_t setAxisValue(int32_t axis, float value); | 
|  | 344 |  | 
| Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 345 | void scale(float globalScale); | 
|  | 346 |  | 
|  | 347 | // Scale the pointer coordinates according to a global scale and a | 
|  | 348 | // window scale. The global scale will be applied to TOUCH/TOOL_MAJOR/MINOR | 
|  | 349 | // axes, however the window scaling will not. | 
|  | 350 | void scale(float globalScale, float windowXScale, float windowYScale); | 
| Jeff Brown | ed4d28d | 2014-02-11 14:28:48 -0800 | [diff] [blame] | 351 | void applyOffset(float xOffset, float yOffset); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 352 |  | 
| chaviw | c01e137 | 2020-07-01 12:37:31 -0700 | [diff] [blame] | 353 | void transform(const ui::Transform& transform); | 
|  | 354 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 355 | inline float getX() const { | 
|  | 356 | return getAxisValue(AMOTION_EVENT_AXIS_X); | 
|  | 357 | } | 
|  | 358 |  | 
|  | 359 | inline float getY() const { | 
|  | 360 | return getAxisValue(AMOTION_EVENT_AXIS_Y); | 
|  | 361 | } | 
|  | 362 |  | 
| Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 363 | #ifdef __linux__ | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 364 | status_t readFromParcel(Parcel* parcel); | 
|  | 365 | status_t writeToParcel(Parcel* parcel) const; | 
| Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 366 | #endif | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 367 |  | 
|  | 368 | bool operator==(const PointerCoords& other) const; | 
|  | 369 | inline bool operator!=(const PointerCoords& other) const { | 
|  | 370 | return !(*this == other); | 
|  | 371 | } | 
|  | 372 |  | 
|  | 373 | void copyFrom(const PointerCoords& other); | 
|  | 374 |  | 
|  | 375 | private: | 
|  | 376 | void tooManyAxes(int axis); | 
|  | 377 | }; | 
|  | 378 |  | 
|  | 379 | /* | 
|  | 380 | * Pointer property data. | 
|  | 381 | */ | 
|  | 382 | struct PointerProperties { | 
|  | 383 | // The id of the pointer. | 
|  | 384 | int32_t id; | 
|  | 385 |  | 
|  | 386 | // The pointer tool type. | 
|  | 387 | int32_t toolType; | 
|  | 388 |  | 
|  | 389 | inline void clear() { | 
|  | 390 | id = -1; | 
|  | 391 | toolType = 0; | 
|  | 392 | } | 
|  | 393 |  | 
|  | 394 | bool operator==(const PointerProperties& other) const; | 
|  | 395 | inline bool operator!=(const PointerProperties& other) const { | 
|  | 396 | return !(*this == other); | 
|  | 397 | } | 
|  | 398 |  | 
|  | 399 | void copyFrom(const PointerProperties& other); | 
|  | 400 | }; | 
|  | 401 |  | 
|  | 402 | /* | 
|  | 403 | * Input events. | 
|  | 404 | */ | 
|  | 405 | class InputEvent : public AInputEvent { | 
|  | 406 | public: | 
|  | 407 | virtual ~InputEvent() { } | 
|  | 408 |  | 
|  | 409 | virtual int32_t getType() const = 0; | 
|  | 410 |  | 
| Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 411 | inline int32_t getId() const { return mId; } | 
|  | 412 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 413 | inline int32_t getDeviceId() const { return mDeviceId; } | 
|  | 414 |  | 
| Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 415 | inline uint32_t getSource() const { return mSource; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 416 |  | 
| Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 417 | inline void setSource(uint32_t source) { mSource = source; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 418 |  | 
| Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 419 | inline int32_t getDisplayId() const { return mDisplayId; } | 
|  | 420 |  | 
|  | 421 | inline void setDisplayId(int32_t displayId) { mDisplayId = displayId; } | 
|  | 422 |  | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 423 | inline std::array<uint8_t, 32> getHmac() const { return mHmac; } | 
| Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 424 |  | 
| Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 425 | static int32_t nextId(); | 
|  | 426 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 427 | protected: | 
| Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 428 | void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 429 | std::array<uint8_t, 32> hmac); | 
| Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 430 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 431 | void initialize(const InputEvent& from); | 
|  | 432 |  | 
| Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 433 | int32_t mId; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 434 | int32_t mDeviceId; | 
| Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 435 | uint32_t mSource; | 
| Siarhei Vishniakou | a62a8dd | 2018-06-08 21:17:33 +0100 | [diff] [blame] | 436 | int32_t mDisplayId; | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 437 | std::array<uint8_t, 32> mHmac; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 438 | }; | 
|  | 439 |  | 
|  | 440 | /* | 
|  | 441 | * Key events. | 
|  | 442 | */ | 
|  | 443 | class KeyEvent : public InputEvent { | 
|  | 444 | public: | 
|  | 445 | virtual ~KeyEvent() { } | 
|  | 446 |  | 
|  | 447 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } | 
|  | 448 |  | 
|  | 449 | inline int32_t getAction() const { return mAction; } | 
|  | 450 |  | 
|  | 451 | inline int32_t getFlags() const { return mFlags; } | 
|  | 452 |  | 
|  | 453 | inline void setFlags(int32_t flags) { mFlags = flags; } | 
|  | 454 |  | 
|  | 455 | inline int32_t getKeyCode() const { return mKeyCode; } | 
|  | 456 |  | 
|  | 457 | inline int32_t getScanCode() const { return mScanCode; } | 
|  | 458 |  | 
|  | 459 | inline int32_t getMetaState() const { return mMetaState; } | 
|  | 460 |  | 
|  | 461 | inline int32_t getRepeatCount() const { return mRepeatCount; } | 
|  | 462 |  | 
|  | 463 | inline nsecs_t getDownTime() const { return mDownTime; } | 
|  | 464 |  | 
|  | 465 | inline nsecs_t getEventTime() const { return mEventTime; } | 
|  | 466 |  | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 467 | static const char* getLabel(int32_t keyCode); | 
|  | 468 | static int32_t getKeyCodeFromLabel(const char* label); | 
| Siarhei Vishniakou | 777a10b | 2018-01-31 16:45:06 -0800 | [diff] [blame] | 469 |  | 
| Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 470 | void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 471 | std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode, | 
|  | 472 | int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime, | 
|  | 473 | nsecs_t eventTime); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 474 | void initialize(const KeyEvent& from); | 
|  | 475 |  | 
| Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 476 | static const char* actionToString(int32_t action); | 
|  | 477 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 478 | protected: | 
|  | 479 | int32_t mAction; | 
|  | 480 | int32_t mFlags; | 
|  | 481 | int32_t mKeyCode; | 
|  | 482 | int32_t mScanCode; | 
|  | 483 | int32_t mMetaState; | 
|  | 484 | int32_t mRepeatCount; | 
|  | 485 | nsecs_t mDownTime; | 
|  | 486 | nsecs_t mEventTime; | 
|  | 487 | }; | 
|  | 488 |  | 
|  | 489 | /* | 
|  | 490 | * Motion events. | 
|  | 491 | */ | 
|  | 492 | class MotionEvent : public InputEvent { | 
|  | 493 | public: | 
|  | 494 | virtual ~MotionEvent() { } | 
|  | 495 |  | 
|  | 496 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } | 
|  | 497 |  | 
|  | 498 | inline int32_t getAction() const { return mAction; } | 
|  | 499 |  | 
|  | 500 | inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; } | 
|  | 501 |  | 
|  | 502 | inline int32_t getActionIndex() const { | 
|  | 503 | return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) | 
|  | 504 | >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT; | 
|  | 505 | } | 
|  | 506 |  | 
|  | 507 | inline void setAction(int32_t action) { mAction = action; } | 
|  | 508 |  | 
|  | 509 | inline int32_t getFlags() const { return mFlags; } | 
|  | 510 |  | 
|  | 511 | inline void setFlags(int32_t flags) { mFlags = flags; } | 
|  | 512 |  | 
|  | 513 | inline int32_t getEdgeFlags() const { return mEdgeFlags; } | 
|  | 514 |  | 
|  | 515 | inline void setEdgeFlags(int32_t edgeFlags) { mEdgeFlags = edgeFlags; } | 
|  | 516 |  | 
|  | 517 | inline int32_t getMetaState() const { return mMetaState; } | 
|  | 518 |  | 
|  | 519 | inline void setMetaState(int32_t metaState) { mMetaState = metaState; } | 
|  | 520 |  | 
|  | 521 | inline int32_t getButtonState() const { return mButtonState; } | 
|  | 522 |  | 
| Michael Wright | 6db5879 | 2016-09-14 19:53:37 +0100 | [diff] [blame] | 523 | inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; } | 
| Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 524 |  | 
| Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 525 | inline MotionClassification getClassification() const { return mClassification; } | 
|  | 526 |  | 
| Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 527 | inline int32_t getActionButton() const { return mActionButton; } | 
|  | 528 |  | 
| Michael Wright | 21957b9 | 2015-06-17 21:06:54 +0100 | [diff] [blame] | 529 | inline void setActionButton(int32_t button) { mActionButton = button; } | 
|  | 530 |  | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 531 | inline float getXOffset() const { return mTransform.tx(); } | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 532 |  | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 533 | inline float getYOffset() const { return mTransform.ty(); } | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 534 |  | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 535 | inline ui::Transform getTransform() const { return mTransform; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 536 |  | 
|  | 537 | inline float getXPrecision() const { return mXPrecision; } | 
|  | 538 |  | 
|  | 539 | inline float getYPrecision() const { return mYPrecision; } | 
|  | 540 |  | 
| Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 541 | inline float getRawXCursorPosition() const { return mRawXCursorPosition; } | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 542 |  | 
|  | 543 | float getXCursorPosition() const; | 
|  | 544 |  | 
| Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 545 | inline float getRawYCursorPosition() const { return mRawYCursorPosition; } | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 546 |  | 
|  | 547 | float getYCursorPosition() const; | 
|  | 548 |  | 
| Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 549 | void setCursorPosition(float x, float y); | 
|  | 550 |  | 
| Garfield Tan | ab0ab9c | 2019-07-10 18:58:28 -0700 | [diff] [blame] | 551 | static inline bool isValidCursorPosition(float x, float y) { return !isnan(x) && !isnan(y); } | 
|  | 552 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 553 | inline nsecs_t getDownTime() const { return mDownTime; } | 
|  | 554 |  | 
|  | 555 | inline void setDownTime(nsecs_t downTime) { mDownTime = downTime; } | 
|  | 556 |  | 
|  | 557 | inline size_t getPointerCount() const { return mPointerProperties.size(); } | 
|  | 558 |  | 
|  | 559 | inline const PointerProperties* getPointerProperties(size_t pointerIndex) const { | 
|  | 560 | return &mPointerProperties[pointerIndex]; | 
|  | 561 | } | 
|  | 562 |  | 
|  | 563 | inline int32_t getPointerId(size_t pointerIndex) const { | 
|  | 564 | return mPointerProperties[pointerIndex].id; | 
|  | 565 | } | 
|  | 566 |  | 
|  | 567 | inline int32_t getToolType(size_t pointerIndex) const { | 
|  | 568 | return mPointerProperties[pointerIndex].toolType; | 
|  | 569 | } | 
|  | 570 |  | 
|  | 571 | inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } | 
|  | 572 |  | 
|  | 573 | const PointerCoords* getRawPointerCoords(size_t pointerIndex) const; | 
|  | 574 |  | 
|  | 575 | float getRawAxisValue(int32_t axis, size_t pointerIndex) const; | 
|  | 576 |  | 
|  | 577 | inline float getRawX(size_t pointerIndex) const { | 
|  | 578 | return getRawAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); | 
|  | 579 | } | 
|  | 580 |  | 
|  | 581 | inline float getRawY(size_t pointerIndex) const { | 
|  | 582 | return getRawAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); | 
|  | 583 | } | 
|  | 584 |  | 
|  | 585 | float getAxisValue(int32_t axis, size_t pointerIndex) const; | 
|  | 586 |  | 
| Siarhei Vishniakou | 69e4d0f | 2020-09-14 19:53:29 -0500 | [diff] [blame] | 587 | /** | 
|  | 588 | * Get the X coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'. | 
|  | 589 | * Identical to calling getHistoricalX(pointerIndex, getHistorySize()). | 
|  | 590 | */ | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 591 | inline float getX(size_t pointerIndex) const { | 
|  | 592 | return getAxisValue(AMOTION_EVENT_AXIS_X, pointerIndex); | 
|  | 593 | } | 
|  | 594 |  | 
| Siarhei Vishniakou | 69e4d0f | 2020-09-14 19:53:29 -0500 | [diff] [blame] | 595 | /** | 
|  | 596 | * Get the Y coordinate of the latest sample in this MotionEvent for pointer 'pointerIndex'. | 
|  | 597 | * Identical to calling getHistoricalX(pointerIndex, getHistorySize()). | 
|  | 598 | */ | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 599 | inline float getY(size_t pointerIndex) const { | 
|  | 600 | return getAxisValue(AMOTION_EVENT_AXIS_Y, pointerIndex); | 
|  | 601 | } | 
|  | 602 |  | 
|  | 603 | inline float getPressure(size_t pointerIndex) const { | 
|  | 604 | return getAxisValue(AMOTION_EVENT_AXIS_PRESSURE, pointerIndex); | 
|  | 605 | } | 
|  | 606 |  | 
|  | 607 | inline float getSize(size_t pointerIndex) const { | 
|  | 608 | return getAxisValue(AMOTION_EVENT_AXIS_SIZE, pointerIndex); | 
|  | 609 | } | 
|  | 610 |  | 
|  | 611 | inline float getTouchMajor(size_t pointerIndex) const { | 
|  | 612 | return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex); | 
|  | 613 | } | 
|  | 614 |  | 
|  | 615 | inline float getTouchMinor(size_t pointerIndex) const { | 
|  | 616 | return getAxisValue(AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex); | 
|  | 617 | } | 
|  | 618 |  | 
|  | 619 | inline float getToolMajor(size_t pointerIndex) const { | 
|  | 620 | return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex); | 
|  | 621 | } | 
|  | 622 |  | 
|  | 623 | inline float getToolMinor(size_t pointerIndex) const { | 
|  | 624 | return getAxisValue(AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex); | 
|  | 625 | } | 
|  | 626 |  | 
|  | 627 | inline float getOrientation(size_t pointerIndex) const { | 
|  | 628 | return getAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex); | 
|  | 629 | } | 
|  | 630 |  | 
|  | 631 | inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; } | 
|  | 632 |  | 
|  | 633 | inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const { | 
|  | 634 | return mSampleEventTimes[historicalIndex]; | 
|  | 635 | } | 
|  | 636 |  | 
|  | 637 | const PointerCoords* getHistoricalRawPointerCoords( | 
|  | 638 | size_t pointerIndex, size_t historicalIndex) const; | 
|  | 639 |  | 
|  | 640 | float getHistoricalRawAxisValue(int32_t axis, size_t pointerIndex, | 
|  | 641 | size_t historicalIndex) const; | 
|  | 642 |  | 
|  | 643 | inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 644 | return getHistoricalRawAxisValue( | 
|  | 645 | AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); | 
|  | 646 | } | 
|  | 647 |  | 
|  | 648 | inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 649 | return getHistoricalRawAxisValue( | 
|  | 650 | AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); | 
|  | 651 | } | 
|  | 652 |  | 
|  | 653 | float getHistoricalAxisValue(int32_t axis, size_t pointerIndex, size_t historicalIndex) const; | 
|  | 654 |  | 
|  | 655 | inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 656 | return getHistoricalAxisValue( | 
|  | 657 | AMOTION_EVENT_AXIS_X, pointerIndex, historicalIndex); | 
|  | 658 | } | 
|  | 659 |  | 
|  | 660 | inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 661 | return getHistoricalAxisValue( | 
|  | 662 | AMOTION_EVENT_AXIS_Y, pointerIndex, historicalIndex); | 
|  | 663 | } | 
|  | 664 |  | 
|  | 665 | inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 666 | return getHistoricalAxisValue( | 
|  | 667 | AMOTION_EVENT_AXIS_PRESSURE, pointerIndex, historicalIndex); | 
|  | 668 | } | 
|  | 669 |  | 
|  | 670 | inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 671 | return getHistoricalAxisValue( | 
|  | 672 | AMOTION_EVENT_AXIS_SIZE, pointerIndex, historicalIndex); | 
|  | 673 | } | 
|  | 674 |  | 
|  | 675 | inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 676 | return getHistoricalAxisValue( | 
|  | 677 | AMOTION_EVENT_AXIS_TOUCH_MAJOR, pointerIndex, historicalIndex); | 
|  | 678 | } | 
|  | 679 |  | 
|  | 680 | inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 681 | return getHistoricalAxisValue( | 
|  | 682 | AMOTION_EVENT_AXIS_TOUCH_MINOR, pointerIndex, historicalIndex); | 
|  | 683 | } | 
|  | 684 |  | 
|  | 685 | inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 686 | return getHistoricalAxisValue( | 
|  | 687 | AMOTION_EVENT_AXIS_TOOL_MAJOR, pointerIndex, historicalIndex); | 
|  | 688 | } | 
|  | 689 |  | 
|  | 690 | inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 691 | return getHistoricalAxisValue( | 
|  | 692 | AMOTION_EVENT_AXIS_TOOL_MINOR, pointerIndex, historicalIndex); | 
|  | 693 | } | 
|  | 694 |  | 
|  | 695 | inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const { | 
|  | 696 | return getHistoricalAxisValue( | 
|  | 697 | AMOTION_EVENT_AXIS_ORIENTATION, pointerIndex, historicalIndex); | 
|  | 698 | } | 
|  | 699 |  | 
|  | 700 | ssize_t findPointerIndex(int32_t pointerId) const; | 
|  | 701 |  | 
| Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 702 | void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId, | 
| Siarhei Vishniakou | 9c858ac | 2020-01-23 14:20:11 -0600 | [diff] [blame] | 703 | std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton, | 
|  | 704 | int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState, | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 705 | MotionClassification classification, const ui::Transform& transform, | 
|  | 706 | float xPrecision, float yPrecision, float rawXCursorPosition, | 
| Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 707 | float rawYCursorPosition, nsecs_t downTime, nsecs_t eventTime, | 
| Garfield Tan | 00f511d | 2019-06-12 16:55:40 -0700 | [diff] [blame] | 708 | size_t pointerCount, const PointerProperties* pointerProperties, | 
|  | 709 | const PointerCoords* pointerCoords); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 710 |  | 
|  | 711 | void copyFrom(const MotionEvent* other, bool keepHistory); | 
|  | 712 |  | 
|  | 713 | void addSample( | 
|  | 714 | nsecs_t eventTime, | 
|  | 715 | const PointerCoords* pointerCoords); | 
|  | 716 |  | 
|  | 717 | void offsetLocation(float xOffset, float yOffset); | 
|  | 718 |  | 
| Robert Carr | e07e103 | 2018-11-26 12:55:53 -0800 | [diff] [blame] | 719 | void scale(float globalScaleFactor); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 720 |  | 
| Jeff Brown | 5a2f68e | 2013-07-15 17:28:19 -0700 | [diff] [blame] | 721 | // Apply 3x3 perspective matrix transformation. | 
|  | 722 | // Matrix is in row-major form and compatible with SkMatrix. | 
| chaviw | 9eaa22c | 2020-07-01 16:21:27 -0700 | [diff] [blame] | 723 | void transform(const std::array<float, 9>& matrix); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 724 |  | 
| Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 725 | #ifdef __linux__ | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 726 | status_t readFromParcel(Parcel* parcel); | 
|  | 727 | status_t writeToParcel(Parcel* parcel) const; | 
| Brett Chabot | faa986c | 2020-11-04 17:39:36 -0800 | [diff] [blame] | 728 | #endif | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 729 |  | 
| Siarhei Vishniakou | 3826d47 | 2020-01-27 10:44:40 -0600 | [diff] [blame] | 730 | static bool isTouchEvent(uint32_t source, int32_t action); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 731 | inline bool isTouchEvent() const { | 
|  | 732 | return isTouchEvent(mSource, mAction); | 
|  | 733 | } | 
|  | 734 |  | 
|  | 735 | // Low-level accessors. | 
|  | 736 | inline const PointerProperties* getPointerProperties() const { | 
|  | 737 | return mPointerProperties.array(); | 
|  | 738 | } | 
| Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 739 | inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.data(); } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 740 | inline const PointerCoords* getSamplePointerCoords() const { | 
|  | 741 | return mSamplePointerCoords.array(); | 
|  | 742 | } | 
|  | 743 |  | 
| Michael Wright | 872db4f | 2014-04-22 15:03:51 -0700 | [diff] [blame] | 744 | static const char* getLabel(int32_t axis); | 
|  | 745 | static int32_t getAxisFromLabel(const char* label); | 
|  | 746 |  | 
| Siarhei Vishniakou | c68fdec | 2020-10-22 14:58:14 -0500 | [diff] [blame] | 747 | static std::string actionToString(int32_t action); | 
| Siarhei Vishniakou | d44dddf | 2020-03-25 16:16:40 -0700 | [diff] [blame] | 748 |  | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 749 | protected: | 
|  | 750 | int32_t mAction; | 
| Michael Wright | 7b159c9 | 2015-05-14 14:48:03 +0100 | [diff] [blame] | 751 | int32_t mActionButton; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 752 | int32_t mFlags; | 
|  | 753 | int32_t mEdgeFlags; | 
|  | 754 | int32_t mMetaState; | 
|  | 755 | int32_t mButtonState; | 
| Siarhei Vishniakou | 49e5922 | 2018-12-28 18:17:15 -0800 | [diff] [blame] | 756 | MotionClassification mClassification; | 
| chaviw | fd9c1ed | 2020-07-01 10:57:59 -0700 | [diff] [blame] | 757 | ui::Transform mTransform; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 758 | float mXPrecision; | 
|  | 759 | float mYPrecision; | 
| Garfield Tan | 937bb83 | 2019-07-25 17:48:31 -0700 | [diff] [blame] | 760 | float mRawXCursorPosition; | 
|  | 761 | float mRawYCursorPosition; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 762 | nsecs_t mDownTime; | 
|  | 763 | Vector<PointerProperties> mPointerProperties; | 
| Siarhei Vishniakou | 46a2774 | 2020-09-09 13:57:28 -0500 | [diff] [blame] | 764 | std::vector<nsecs_t> mSampleEventTimes; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 765 | Vector<PointerCoords> mSamplePointerCoords; | 
|  | 766 | }; | 
|  | 767 |  | 
|  | 768 | /* | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 769 | * Focus events. | 
|  | 770 | */ | 
|  | 771 | class FocusEvent : public InputEvent { | 
|  | 772 | public: | 
|  | 773 | virtual ~FocusEvent() {} | 
|  | 774 |  | 
|  | 775 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_FOCUS; } | 
|  | 776 |  | 
|  | 777 | inline bool getHasFocus() const { return mHasFocus; } | 
|  | 778 |  | 
|  | 779 | inline bool getInTouchMode() const { return mInTouchMode; } | 
|  | 780 |  | 
| Garfield Tan | 4cc839f | 2020-01-24 11:26:14 -0800 | [diff] [blame] | 781 | void initialize(int32_t id, bool hasFocus, bool inTouchMode); | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 782 |  | 
|  | 783 | void initialize(const FocusEvent& from); | 
|  | 784 |  | 
|  | 785 | protected: | 
|  | 786 | bool mHasFocus; | 
|  | 787 | bool mInTouchMode; | 
|  | 788 | }; | 
|  | 789 |  | 
| Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 790 | /* | 
|  | 791 | * Capture events. | 
|  | 792 | */ | 
|  | 793 | class CaptureEvent : public InputEvent { | 
|  | 794 | public: | 
|  | 795 | virtual ~CaptureEvent() {} | 
|  | 796 |  | 
|  | 797 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_CAPTURE; } | 
|  | 798 |  | 
|  | 799 | inline bool getPointerCaptureEnabled() const { return mPointerCaptureEnabled; } | 
|  | 800 |  | 
|  | 801 | void initialize(int32_t id, bool pointerCaptureEnabled); | 
|  | 802 |  | 
|  | 803 | void initialize(const CaptureEvent& from); | 
|  | 804 |  | 
|  | 805 | protected: | 
|  | 806 | bool mPointerCaptureEnabled; | 
|  | 807 | }; | 
|  | 808 |  | 
| arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 809 | /* | 
|  | 810 | * Drag events. | 
|  | 811 | */ | 
|  | 812 | class DragEvent : public InputEvent { | 
|  | 813 | public: | 
|  | 814 | virtual ~DragEvent() {} | 
|  | 815 |  | 
|  | 816 | virtual int32_t getType() const override { return AINPUT_EVENT_TYPE_DRAG; } | 
|  | 817 |  | 
|  | 818 | inline bool isExiting() const { return mIsExiting; } | 
|  | 819 |  | 
|  | 820 | inline float getX() const { return mX; } | 
|  | 821 |  | 
|  | 822 | inline float getY() const { return mY; } | 
|  | 823 |  | 
|  | 824 | void initialize(int32_t id, float x, float y, bool isExiting); | 
|  | 825 |  | 
|  | 826 | void initialize(const DragEvent& from); | 
|  | 827 |  | 
|  | 828 | protected: | 
|  | 829 | bool mIsExiting; | 
|  | 830 | float mX, mY; | 
|  | 831 | }; | 
|  | 832 |  | 
| Siarhei Vishniakou | 54d3e18 | 2020-01-15 17:38:38 -0800 | [diff] [blame] | 833 | /** | 
|  | 834 | * Base class for verified events. | 
|  | 835 | * Do not create a VerifiedInputEvent explicitly. | 
|  | 836 | * Use helper functions to create them from InputEvents. | 
|  | 837 | */ | 
|  | 838 | struct __attribute__((__packed__)) VerifiedInputEvent { | 
|  | 839 | enum class Type : int32_t { | 
|  | 840 | KEY = AINPUT_EVENT_TYPE_KEY, | 
|  | 841 | MOTION = AINPUT_EVENT_TYPE_MOTION, | 
|  | 842 | }; | 
|  | 843 |  | 
|  | 844 | Type type; | 
|  | 845 | int32_t deviceId; | 
|  | 846 | nsecs_t eventTimeNanos; | 
|  | 847 | uint32_t source; | 
|  | 848 | int32_t displayId; | 
|  | 849 | }; | 
|  | 850 |  | 
|  | 851 | /** | 
|  | 852 | * Same as KeyEvent, but only contains the data that can be verified. | 
|  | 853 | * If you update this class, you must also update VerifiedKeyEvent.java | 
|  | 854 | */ | 
|  | 855 | struct __attribute__((__packed__)) VerifiedKeyEvent : public VerifiedInputEvent { | 
|  | 856 | int32_t action; | 
|  | 857 | nsecs_t downTimeNanos; | 
|  | 858 | int32_t flags; | 
|  | 859 | int32_t keyCode; | 
|  | 860 | int32_t scanCode; | 
|  | 861 | int32_t metaState; | 
|  | 862 | int32_t repeatCount; | 
|  | 863 | }; | 
|  | 864 |  | 
|  | 865 | /** | 
|  | 866 | * Same as MotionEvent, but only contains the data that can be verified. | 
|  | 867 | * If you update this class, you must also update VerifiedMotionEvent.java | 
|  | 868 | */ | 
|  | 869 | struct __attribute__((__packed__)) VerifiedMotionEvent : public VerifiedInputEvent { | 
|  | 870 | float rawX; | 
|  | 871 | float rawY; | 
|  | 872 | int32_t actionMasked; | 
|  | 873 | nsecs_t downTimeNanos; | 
|  | 874 | int32_t flags; | 
|  | 875 | int32_t metaState; | 
|  | 876 | int32_t buttonState; | 
|  | 877 | }; | 
|  | 878 |  | 
|  | 879 | VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event); | 
|  | 880 | VerifiedMotionEvent verifiedMotionEventFromMotionEvent(const MotionEvent& event); | 
|  | 881 |  | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 882 | /* | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 883 | * Input event factory. | 
|  | 884 | */ | 
|  | 885 | class InputEventFactoryInterface { | 
|  | 886 | protected: | 
|  | 887 | virtual ~InputEventFactoryInterface() { } | 
|  | 888 |  | 
|  | 889 | public: | 
|  | 890 | InputEventFactoryInterface() { } | 
|  | 891 |  | 
|  | 892 | virtual KeyEvent* createKeyEvent() = 0; | 
|  | 893 | virtual MotionEvent* createMotionEvent() = 0; | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 894 | virtual FocusEvent* createFocusEvent() = 0; | 
| Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 895 | virtual CaptureEvent* createCaptureEvent() = 0; | 
| arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 896 | virtual DragEvent* createDragEvent() = 0; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 897 | }; | 
|  | 898 |  | 
|  | 899 | /* | 
|  | 900 | * A simple input event factory implementation that uses a single preallocated instance | 
|  | 901 | * of each type of input event that are reused for each request. | 
|  | 902 | */ | 
|  | 903 | class PreallocatedInputEventFactory : public InputEventFactoryInterface { | 
|  | 904 | public: | 
|  | 905 | PreallocatedInputEventFactory() { } | 
|  | 906 | virtual ~PreallocatedInputEventFactory() { } | 
|  | 907 |  | 
| Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 908 | virtual KeyEvent* createKeyEvent() override { return &mKeyEvent; } | 
|  | 909 | virtual MotionEvent* createMotionEvent() override { return &mMotionEvent; } | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 910 | virtual FocusEvent* createFocusEvent() override { return &mFocusEvent; } | 
| Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 911 | virtual CaptureEvent* createCaptureEvent() override { return &mCaptureEvent; } | 
| arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 912 | virtual DragEvent* createDragEvent() override { return &mDragEvent; } | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 913 |  | 
|  | 914 | private: | 
|  | 915 | KeyEvent mKeyEvent; | 
|  | 916 | MotionEvent mMotionEvent; | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 917 | FocusEvent mFocusEvent; | 
| Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 918 | CaptureEvent mCaptureEvent; | 
| arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 919 | DragEvent mDragEvent; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 920 | }; | 
|  | 921 |  | 
|  | 922 | /* | 
|  | 923 | * An input event factory implementation that maintains a pool of input events. | 
|  | 924 | */ | 
|  | 925 | class PooledInputEventFactory : public InputEventFactoryInterface { | 
|  | 926 | public: | 
| Chih-Hung Hsieh | f43b02c | 2018-12-20 15:45:56 -0800 | [diff] [blame] | 927 | explicit PooledInputEventFactory(size_t maxPoolSize = 20); | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 928 | virtual ~PooledInputEventFactory(); | 
|  | 929 |  | 
| Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 930 | virtual KeyEvent* createKeyEvent() override; | 
|  | 931 | virtual MotionEvent* createMotionEvent() override; | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 932 | virtual FocusEvent* createFocusEvent() override; | 
| Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 933 | virtual CaptureEvent* createCaptureEvent() override; | 
| arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 934 | virtual DragEvent* createDragEvent() override; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 935 |  | 
|  | 936 | void recycle(InputEvent* event); | 
|  | 937 |  | 
|  | 938 | private: | 
|  | 939 | const size_t mMaxPoolSize; | 
|  | 940 |  | 
| Siarhei Vishniakou | 727a44e | 2019-11-23 12:59:16 -0800 | [diff] [blame] | 941 | std::queue<std::unique_ptr<KeyEvent>> mKeyEventPool; | 
|  | 942 | std::queue<std::unique_ptr<MotionEvent>> mMotionEventPool; | 
| Siarhei Vishniakou | 7feb2ea | 2019-11-25 15:11:23 -0800 | [diff] [blame] | 943 | std::queue<std::unique_ptr<FocusEvent>> mFocusEventPool; | 
| Prabir Pradhan | 3f37b7b | 2020-11-10 16:50:18 -0800 | [diff] [blame] | 944 | std::queue<std::unique_ptr<CaptureEvent>> mCaptureEventPool; | 
| arthurhung | 7632c33 | 2020-12-30 16:58:01 +0800 | [diff] [blame] | 945 | std::queue<std::unique_ptr<DragEvent>> mDragEventPool; | 
| Jeff Brown | 5912f95 | 2013-07-01 19:10:31 -0700 | [diff] [blame] | 946 | }; | 
|  | 947 |  | 
|  | 948 | } // namespace android | 
|  | 949 |  | 
|  | 950 | #endif // _LIBINPUT_INPUT_H |