Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005 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 | // |
| 18 | #ifndef _RUNTIME_EVENT_HUB_H |
| 19 | #define _RUNTIME_EVENT_HUB_H |
| 20 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 21 | #include <vector> |
| 22 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 23 | #include <input/Input.h> |
| 24 | #include <input/InputDevice.h> |
| 25 | #include <input/Keyboard.h> |
| 26 | #include <input/KeyLayoutMap.h> |
| 27 | #include <input/KeyCharacterMap.h> |
| 28 | #include <input/VirtualKeyMap.h> |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 29 | #include <utils/Mutex.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 30 | #include <utils/Log.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 31 | #include <utils/List.h> |
| 32 | #include <utils/Errors.h> |
| 33 | #include <utils/PropertyMap.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 34 | #include <utils/KeyedVector.h> |
| 35 | #include <utils/BitSet.h> |
| 36 | |
| 37 | #include <linux/input.h> |
| 38 | #include <sys/epoll.h> |
| 39 | |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 40 | #include "TouchVideoDevice.h" |
| 41 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 42 | /* Convenience constants. */ |
| 43 | |
| 44 | #define BTN_FIRST 0x100 // first button code |
| 45 | #define BTN_LAST 0x15f // last button code |
| 46 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 47 | namespace android { |
| 48 | |
| 49 | enum { |
| 50 | // Device id of a special "virtual" keyboard that is always present. |
| 51 | VIRTUAL_KEYBOARD_ID = -1, |
| 52 | // Device id of the "built-in" keyboard if there is one. |
| 53 | BUILT_IN_KEYBOARD_ID = 0, |
| 54 | }; |
| 55 | |
| 56 | /* |
| 57 | * A raw event as retrieved from the EventHub. |
| 58 | */ |
| 59 | struct RawEvent { |
| 60 | nsecs_t when; |
| 61 | int32_t deviceId; |
| 62 | int32_t type; |
| 63 | int32_t code; |
| 64 | int32_t value; |
| 65 | }; |
| 66 | |
| 67 | /* Describes an absolute axis. */ |
| 68 | struct RawAbsoluteAxisInfo { |
| 69 | bool valid; // true if the information is valid, false otherwise |
| 70 | |
| 71 | int32_t minValue; // minimum value |
| 72 | int32_t maxValue; // maximum value |
| 73 | int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8 |
| 74 | int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise |
| 75 | int32_t resolution; // resolution in units per mm or radians per mm |
| 76 | |
| 77 | inline void clear() { |
| 78 | valid = false; |
| 79 | minValue = 0; |
| 80 | maxValue = 0; |
| 81 | flat = 0; |
| 82 | fuzz = 0; |
| 83 | resolution = 0; |
| 84 | } |
| 85 | }; |
| 86 | |
| 87 | /* |
| 88 | * Input device classes. |
| 89 | */ |
| 90 | enum { |
| 91 | /* The input device is a keyboard or has buttons. */ |
| 92 | INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, |
| 93 | |
| 94 | /* The input device is an alpha-numeric keyboard (not just a dial pad). */ |
| 95 | INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, |
| 96 | |
| 97 | /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ |
| 98 | INPUT_DEVICE_CLASS_TOUCH = 0x00000004, |
| 99 | |
| 100 | /* The input device is a cursor device such as a trackball or mouse. */ |
| 101 | INPUT_DEVICE_CLASS_CURSOR = 0x00000008, |
| 102 | |
| 103 | /* The input device is a multi-touch touchscreen. */ |
| 104 | INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010, |
| 105 | |
| 106 | /* The input device is a directional pad (implies keyboard, has DPAD keys). */ |
| 107 | INPUT_DEVICE_CLASS_DPAD = 0x00000020, |
| 108 | |
| 109 | /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ |
| 110 | INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040, |
| 111 | |
| 112 | /* The input device has switches. */ |
| 113 | INPUT_DEVICE_CLASS_SWITCH = 0x00000080, |
| 114 | |
| 115 | /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ |
| 116 | INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100, |
| 117 | |
| 118 | /* The input device has a vibrator (supports FF_RUMBLE). */ |
| 119 | INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200, |
| 120 | |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 121 | /* The input device has a microphone. */ |
| 122 | INPUT_DEVICE_CLASS_MIC = 0x00000400, |
| 123 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 124 | /* The input device is an external stylus (has data we want to fuse with touch data). */ |
| 125 | INPUT_DEVICE_CLASS_EXTERNAL_STYLUS = 0x00000800, |
| 126 | |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 127 | /* The input device has a rotary encoder */ |
| 128 | INPUT_DEVICE_CLASS_ROTARY_ENCODER = 0x00001000, |
| 129 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 130 | /* The input device is virtual (not a real device, not part of UI configuration). */ |
| 131 | INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000, |
| 132 | |
| 133 | /* The input device is external (not built-in). */ |
| 134 | INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000, |
| 135 | }; |
| 136 | |
| 137 | /* |
| 138 | * Gets the class that owns an axis, in cases where multiple classes might claim |
| 139 | * the same axis for different purposes. |
| 140 | */ |
| 141 | extern uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses); |
| 142 | |
| 143 | /* |
| 144 | * Grand Central Station for events. |
| 145 | * |
| 146 | * The event hub aggregates input events received across all known input |
| 147 | * devices on the system, including devices that may be emulated by the simulator |
| 148 | * environment. In addition, the event hub generates fake input events to indicate |
| 149 | * when devices are added or removed. |
| 150 | * |
| 151 | * The event hub provides a stream of input events (via the getEvent function). |
| 152 | * It also supports querying the current actual state of input devices such as identifying |
| 153 | * which keys are currently down. Finally, the event hub keeps track of the capabilities of |
| 154 | * individual input devices, such as their class and the set of key codes that they support. |
| 155 | */ |
| 156 | class EventHubInterface : public virtual RefBase { |
| 157 | protected: |
| 158 | EventHubInterface() { } |
| 159 | virtual ~EventHubInterface() { } |
| 160 | |
| 161 | public: |
| 162 | // Synthetic raw event type codes produced when devices are added or removed. |
| 163 | enum { |
| 164 | // Sent when a device is added. |
| 165 | DEVICE_ADDED = 0x10000000, |
| 166 | // Sent when a device is removed. |
| 167 | DEVICE_REMOVED = 0x20000000, |
| 168 | // Sent when all added/removed devices from the most recent scan have been reported. |
| 169 | // This event is always sent at least once. |
| 170 | FINISHED_DEVICE_SCAN = 0x30000000, |
| 171 | |
| 172 | FIRST_SYNTHETIC_EVENT = DEVICE_ADDED, |
| 173 | }; |
| 174 | |
| 175 | virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0; |
| 176 | |
| 177 | virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0; |
| 178 | |
| 179 | virtual int32_t getDeviceControllerNumber(int32_t deviceId) const = 0; |
| 180 | |
| 181 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0; |
| 182 | |
| 183 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 184 | RawAbsoluteAxisInfo* outAxisInfo) const = 0; |
| 185 | |
| 186 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0; |
| 187 | |
| 188 | virtual bool hasInputProperty(int32_t deviceId, int property) const = 0; |
| 189 | |
Dmitry Torokhov | 0faaa0b | 2015-09-24 13:13:55 -0700 | [diff] [blame] | 190 | virtual status_t mapKey(int32_t deviceId, |
| 191 | int32_t scanCode, int32_t usageCode, int32_t metaState, |
| 192 | int32_t* outKeycode, int32_t *outMetaState, uint32_t* outFlags) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 193 | |
| 194 | virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, |
| 195 | AxisInfo* outAxisInfo) const = 0; |
| 196 | |
| 197 | // Sets devices that are excluded from opening. |
| 198 | // This can be used to ignore input devices for sensors. |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 199 | virtual void setExcludedDevices(const std::vector<std::string>& devices) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 200 | |
| 201 | /* |
| 202 | * Wait for events to become available and returns them. |
| 203 | * After returning, the EventHub holds onto a wake lock until the next call to getEvent. |
| 204 | * This ensures that the device will not go to sleep while the event is being processed. |
| 205 | * If the device needs to remain awake longer than that, then the caller is responsible |
| 206 | * for taking care of it (say, by poking the power manager user activity timer). |
| 207 | * |
| 208 | * The timeout is advisory only. If the device is asleep, it will not wake just to |
| 209 | * service the timeout. |
| 210 | * |
| 211 | * Returns the number of events obtained, or 0 if the timeout expired. |
| 212 | */ |
| 213 | virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0; |
Siarhei Vishniakou | add8929 | 2018-12-13 19:23:36 -0800 | [diff] [blame^] | 214 | virtual std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 215 | |
| 216 | /* |
| 217 | * Query current input state. |
| 218 | */ |
| 219 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0; |
| 220 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0; |
| 221 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0; |
| 222 | virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
| 223 | int32_t* outValue) const = 0; |
| 224 | |
| 225 | /* |
| 226 | * Examine key input devices for specific framework keycode support |
| 227 | */ |
| 228 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, |
| 229 | uint8_t* outFlags) const = 0; |
| 230 | |
| 231 | virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0; |
| 232 | |
| 233 | /* LED related functions expect Android LED constants, not scan codes or HID usages */ |
| 234 | virtual bool hasLed(int32_t deviceId, int32_t led) const = 0; |
| 235 | virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0; |
| 236 | |
| 237 | virtual void getVirtualKeyDefinitions(int32_t deviceId, |
| 238 | Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; |
| 239 | |
| 240 | virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0; |
| 241 | virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) = 0; |
| 242 | |
| 243 | /* Control the vibrator. */ |
| 244 | virtual void vibrate(int32_t deviceId, nsecs_t duration) = 0; |
| 245 | virtual void cancelVibrate(int32_t deviceId) = 0; |
| 246 | |
| 247 | /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */ |
| 248 | virtual void requestReopenDevices() = 0; |
| 249 | |
| 250 | /* Wakes up getEvents() if it is blocked on a read. */ |
| 251 | virtual void wake() = 0; |
| 252 | |
| 253 | /* Dump EventHub state to a string. */ |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 254 | virtual void dump(std::string& dump) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 255 | |
| 256 | /* Called by the heatbeat to ensures that the reader has not deadlocked. */ |
| 257 | virtual void monitor() = 0; |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 258 | |
| 259 | /* Return true if the device is enabled. */ |
| 260 | virtual bool isDeviceEnabled(int32_t deviceId) = 0; |
| 261 | |
| 262 | /* Enable an input device */ |
| 263 | virtual status_t enableDevice(int32_t deviceId) = 0; |
| 264 | |
| 265 | /* Disable an input device. Closes file descriptor to that device. */ |
| 266 | virtual status_t disableDevice(int32_t deviceId) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | class EventHub : public EventHubInterface |
| 270 | { |
| 271 | public: |
| 272 | EventHub(); |
| 273 | |
| 274 | virtual uint32_t getDeviceClasses(int32_t deviceId) const; |
| 275 | |
| 276 | virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const; |
| 277 | |
| 278 | virtual int32_t getDeviceControllerNumber(int32_t deviceId) const; |
| 279 | |
| 280 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const; |
| 281 | |
| 282 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 283 | RawAbsoluteAxisInfo* outAxisInfo) const; |
| 284 | |
| 285 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const; |
| 286 | |
| 287 | virtual bool hasInputProperty(int32_t deviceId, int property) const; |
| 288 | |
Dmitry Torokhov | 0faaa0b | 2015-09-24 13:13:55 -0700 | [diff] [blame] | 289 | virtual status_t mapKey(int32_t deviceId, |
| 290 | int32_t scanCode, int32_t usageCode, int32_t metaState, |
| 291 | int32_t* outKeycode, int32_t *outMetaState, uint32_t* outFlags) const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 292 | |
| 293 | virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, |
| 294 | AxisInfo* outAxisInfo) const; |
| 295 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 296 | virtual void setExcludedDevices(const std::vector<std::string>& devices); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 297 | |
| 298 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const; |
| 299 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const; |
| 300 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const; |
| 301 | virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const; |
| 302 | |
| 303 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, |
| 304 | const int32_t* keyCodes, uint8_t* outFlags) const; |
| 305 | |
| 306 | virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize); |
Siarhei Vishniakou | add8929 | 2018-12-13 19:23:36 -0800 | [diff] [blame^] | 307 | virtual std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 308 | |
| 309 | virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const; |
| 310 | virtual bool hasLed(int32_t deviceId, int32_t led) const; |
| 311 | virtual void setLedState(int32_t deviceId, int32_t led, bool on); |
| 312 | |
| 313 | virtual void getVirtualKeyDefinitions(int32_t deviceId, |
| 314 | Vector<VirtualKeyDefinition>& outVirtualKeys) const; |
| 315 | |
| 316 | virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const; |
| 317 | virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map); |
| 318 | |
| 319 | virtual void vibrate(int32_t deviceId, nsecs_t duration); |
| 320 | virtual void cancelVibrate(int32_t deviceId); |
| 321 | |
| 322 | virtual void requestReopenDevices(); |
| 323 | |
| 324 | virtual void wake(); |
| 325 | |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 326 | virtual void dump(std::string& dump); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 327 | virtual void monitor(); |
| 328 | |
| 329 | protected: |
| 330 | virtual ~EventHub(); |
| 331 | |
| 332 | private: |
| 333 | struct Device { |
| 334 | Device* next; |
| 335 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 336 | int fd; // may be -1 if device is closed |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 337 | const int32_t id; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 338 | const std::string path; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 339 | const InputDeviceIdentifier identifier; |
| 340 | |
Siarhei Vishniakou | ec7854a | 2018-12-14 16:52:34 -0800 | [diff] [blame] | 341 | std::unique_ptr<TouchVideoDevice> videoDevice; |
| 342 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 343 | uint32_t classes; |
| 344 | |
| 345 | uint8_t keyBitmask[(KEY_MAX + 1) / 8]; |
| 346 | uint8_t absBitmask[(ABS_MAX + 1) / 8]; |
| 347 | uint8_t relBitmask[(REL_MAX + 1) / 8]; |
| 348 | uint8_t swBitmask[(SW_MAX + 1) / 8]; |
| 349 | uint8_t ledBitmask[(LED_MAX + 1) / 8]; |
| 350 | uint8_t ffBitmask[(FF_MAX + 1) / 8]; |
| 351 | uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8]; |
| 352 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 353 | std::string configurationFile; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 354 | PropertyMap* configuration; |
| 355 | VirtualKeyMap* virtualKeyMap; |
| 356 | KeyMap keyMap; |
| 357 | |
| 358 | sp<KeyCharacterMap> overlayKeyMap; |
| 359 | sp<KeyCharacterMap> combinedKeyMap; |
| 360 | |
| 361 | bool ffEffectPlaying; |
| 362 | int16_t ffEffectId; // initially -1 |
| 363 | |
| 364 | int32_t controllerNumber; |
| 365 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 366 | Device(int fd, int32_t id, const std::string& path, |
| 367 | const InputDeviceIdentifier& identifier); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 368 | ~Device(); |
| 369 | |
| 370 | void close(); |
| 371 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 372 | bool enabled; // initially true |
| 373 | status_t enable(); |
| 374 | status_t disable(); |
| 375 | bool hasValidFd(); |
| 376 | const bool isVirtual; // set if fd < 0 is passed to constructor |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 377 | |
| 378 | const sp<KeyCharacterMap>& getKeyCharacterMap() const { |
Yi Kong | 9b14ac6 | 2018-07-17 13:48:38 -0700 | [diff] [blame] | 379 | if (combinedKeyMap != nullptr) { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 380 | return combinedKeyMap; |
| 381 | } |
| 382 | return keyMap.keyCharacterMap; |
| 383 | } |
| 384 | }; |
| 385 | |
Siarhei Vishniakou | 1259868 | 2018-11-02 17:19:19 -0700 | [diff] [blame] | 386 | status_t openDeviceLocked(const char* devicePath); |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 387 | void openVideoDeviceLocked(const std::string& devicePath); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 388 | void createVirtualKeyboardLocked(); |
| 389 | void addDeviceLocked(Device* device); |
| 390 | void assignDescriptorLocked(InputDeviceIdentifier& identifier); |
| 391 | |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 392 | void closeDeviceByPathLocked(const char *devicePath); |
| 393 | void closeVideoDeviceByPathLocked(const std::string& devicePath); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 394 | void closeDeviceLocked(Device* device); |
| 395 | void closeAllDevicesLocked(); |
| 396 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 397 | void configureFd(Device* device); |
| 398 | |
| 399 | bool isDeviceEnabled(int32_t deviceId); |
| 400 | status_t enableDevice(int32_t deviceId); |
| 401 | status_t disableDevice(int32_t deviceId); |
Siarhei Vishniakou | 2592031 | 2018-12-12 15:24:44 -0800 | [diff] [blame] | 402 | status_t registerFdForEpoll(int fd); |
| 403 | status_t unregisterFdFromEpoll(int fd); |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 404 | status_t registerDeviceForEpollLocked(Device* device); |
Siarhei Vishniakou | 1259868 | 2018-11-02 17:19:19 -0700 | [diff] [blame] | 405 | void registerVideoDeviceForEpollLocked(const TouchVideoDevice& videoDevice); |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 406 | status_t unregisterDeviceFromEpollLocked(Device* device); |
Siarhei Vishniakou | 1259868 | 2018-11-02 17:19:19 -0700 | [diff] [blame] | 407 | void unregisterVideoDeviceFromEpollLocked(const TouchVideoDevice& videoDevice); |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 408 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 409 | status_t scanDirLocked(const char *dirname); |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 410 | status_t scanVideoDirLocked(const std::string& dirname); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 411 | void scanDevicesLocked(); |
| 412 | status_t readNotifyLocked(); |
| 413 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 414 | Device* getDeviceByDescriptorLocked(const std::string& descriptor) const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 415 | Device* getDeviceLocked(int32_t deviceId) const; |
| 416 | Device* getDeviceByPathLocked(const char* devicePath) const; |
Siarhei Vishniakou | 1259868 | 2018-11-02 17:19:19 -0700 | [diff] [blame] | 417 | /** |
| 418 | * Look through all available fd's (both for input devices and for video devices), |
| 419 | * and return the device pointer. |
| 420 | */ |
Siarhei Vishniakou | 4bc561c | 2018-11-02 17:41:58 -0700 | [diff] [blame] | 421 | Device* getDeviceByFdLocked(int fd) const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 422 | |
| 423 | bool hasKeycodeLocked(Device* device, int keycode) const; |
| 424 | |
| 425 | void loadConfigurationLocked(Device* device); |
| 426 | status_t loadVirtualKeyMapLocked(Device* device); |
| 427 | status_t loadKeyMapLocked(Device* device); |
| 428 | |
| 429 | bool isExternalDeviceLocked(Device* device); |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 430 | bool deviceHasMicLocked(Device* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 431 | |
| 432 | int32_t getNextControllerNumberLocked(Device* device); |
| 433 | void releaseControllerNumberLocked(Device* device); |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 434 | void setLedForControllerLocked(Device* device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 435 | |
| 436 | status_t mapLed(Device* device, int32_t led, int32_t* outScanCode) const; |
| 437 | void setLedStateLocked(Device* device, int32_t led, bool on); |
| 438 | |
| 439 | // Protect all internal state. |
| 440 | mutable Mutex mLock; |
| 441 | |
| 442 | // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none. |
| 443 | // EventHub remaps the built-in keyboard to id 0 externally as required by the API. |
| 444 | enum { |
| 445 | // Must not conflict with any other assigned device ids, including |
| 446 | // the virtual keyboard id (-1). |
| 447 | NO_BUILT_IN_KEYBOARD = -2, |
| 448 | }; |
| 449 | int32_t mBuiltInKeyboardId; |
| 450 | |
| 451 | int32_t mNextDeviceId; |
| 452 | |
| 453 | BitSet32 mControllerNumbers; |
| 454 | |
| 455 | KeyedVector<int32_t, Device*> mDevices; |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 456 | /** |
| 457 | * Video devices that report touchscreen heatmap, but have not (yet) been paired |
| 458 | * with a specific input device. Video device discovery is independent from input device |
| 459 | * discovery, so the two types of devices could be found in any order. |
| 460 | * Ideally, video devices in this queue do not have an open fd, or at least aren't |
| 461 | * actively streaming. |
| 462 | */ |
| 463 | std::vector<std::unique_ptr<TouchVideoDevice>> mUnattachedVideoDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 464 | |
| 465 | Device *mOpeningDevices; |
| 466 | Device *mClosingDevices; |
| 467 | |
| 468 | bool mNeedToSendFinishedDeviceScan; |
| 469 | bool mNeedToReopenDevices; |
| 470 | bool mNeedToScanDevices; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 471 | std::vector<std::string> mExcludedDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 472 | |
| 473 | int mEpollFd; |
| 474 | int mINotifyFd; |
| 475 | int mWakeReadPipeFd; |
| 476 | int mWakeWritePipeFd; |
| 477 | |
Siarhei Vishniakou | 951f362 | 2018-12-12 19:45:42 -0800 | [diff] [blame] | 478 | int mInputWd; |
| 479 | int mVideoWd; |
| 480 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 481 | // Maximum number of signalled FDs to handle at a time. |
| 482 | static const int EPOLL_MAX_EVENTS = 16; |
| 483 | |
| 484 | // The array of pending epoll events and the index of the next event to be handled. |
| 485 | struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS]; |
| 486 | size_t mPendingEventCount; |
| 487 | size_t mPendingEventIndex; |
| 488 | bool mPendingINotify; |
| 489 | |
| 490 | bool mUsingEpollWakeup; |
| 491 | }; |
| 492 | |
| 493 | }; // namespace android |
| 494 | |
| 495 | #endif // _RUNTIME_EVENT_HUB_H |