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 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 17 | #ifndef _RUNTIME_EVENT_HUB_H |
| 18 | #define _RUNTIME_EVENT_HUB_H |
| 19 | |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 20 | #include <bitset> |
| 21 | #include <climits> |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 22 | #include <unordered_map> |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 25 | #include <input/Flags.h> |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 26 | #include <filesystem> |
| 27 | |
| 28 | #include <batteryservice/BatteryService.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 29 | #include <input/Input.h> |
| 30 | #include <input/InputDevice.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 31 | #include <input/KeyCharacterMap.h> |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 32 | #include <input/KeyLayoutMap.h> |
| 33 | #include <input/Keyboard.h> |
Siarhei Vishniakou | 32f36ae | 2020-09-02 20:17:10 -0700 | [diff] [blame] | 34 | #include <input/PropertyMap.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 35 | #include <input/VirtualKeyMap.h> |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 36 | #include <linux/input.h> |
| 37 | #include <sys/epoll.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 38 | #include <utils/BitSet.h> |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 39 | #include <utils/Errors.h> |
| 40 | #include <utils/KeyedVector.h> |
| 41 | #include <utils/List.h> |
| 42 | #include <utils/Log.h> |
| 43 | #include <utils/Mutex.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 44 | |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 45 | #include "TouchVideoDevice.h" |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 46 | #include "VibrationElement.h" |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 47 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 48 | namespace android { |
| 49 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 50 | /* |
| 51 | * A raw event as retrieved from the EventHub. |
| 52 | */ |
| 53 | struct RawEvent { |
| 54 | nsecs_t when; |
| 55 | int32_t deviceId; |
| 56 | int32_t type; |
| 57 | int32_t code; |
| 58 | int32_t value; |
| 59 | }; |
| 60 | |
| 61 | /* Describes an absolute axis. */ |
| 62 | struct RawAbsoluteAxisInfo { |
| 63 | bool valid; // true if the information is valid, false otherwise |
| 64 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 65 | int32_t minValue; // minimum value |
| 66 | int32_t maxValue; // maximum value |
| 67 | int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8 |
| 68 | int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 69 | int32_t resolution; // resolution in units per mm or radians per mm |
| 70 | |
| 71 | inline void clear() { |
| 72 | valid = false; |
| 73 | minValue = 0; |
| 74 | maxValue = 0; |
| 75 | flat = 0; |
| 76 | fuzz = 0; |
| 77 | resolution = 0; |
| 78 | } |
| 79 | }; |
| 80 | |
| 81 | /* |
| 82 | * Input device classes. |
| 83 | */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 84 | enum class InputDeviceClass : uint32_t { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 85 | /* The input device is a keyboard or has buttons. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 86 | KEYBOARD = 0x00000001, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 87 | |
| 88 | /* The input device is an alpha-numeric keyboard (not just a dial pad). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 89 | ALPHAKEY = 0x00000002, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 90 | |
| 91 | /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 92 | TOUCH = 0x00000004, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 93 | |
| 94 | /* The input device is a cursor device such as a trackball or mouse. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 95 | CURSOR = 0x00000008, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 96 | |
| 97 | /* The input device is a multi-touch touchscreen. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 98 | TOUCH_MT = 0x00000010, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 99 | |
| 100 | /* The input device is a directional pad (implies keyboard, has DPAD keys). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 101 | DPAD = 0x00000020, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 102 | |
| 103 | /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 104 | GAMEPAD = 0x00000040, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 105 | |
| 106 | /* The input device has switches. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 107 | SWITCH = 0x00000080, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 108 | |
| 109 | /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 110 | JOYSTICK = 0x00000100, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 111 | |
| 112 | /* The input device has a vibrator (supports FF_RUMBLE). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 113 | VIBRATOR = 0x00000200, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 114 | |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 115 | /* The input device has a microphone. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 116 | MIC = 0x00000400, |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 117 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 118 | /* The input device is an external stylus (has data we want to fuse with touch data). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 119 | EXTERNAL_STYLUS = 0x00000800, |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 120 | |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 121 | /* The input device has a rotary encoder */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 122 | ROTARY_ENCODER = 0x00001000, |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 123 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 124 | /* The input device has a sensor like accelerometer, gyro, etc */ |
| 125 | SENSOR = 0x00002000, |
| 126 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 127 | /* The input device has a battery */ |
| 128 | BATTERY = 0x00004000, |
| 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). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 131 | VIRTUAL = 0x40000000, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 132 | |
| 133 | /* The input device is external (not built-in). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 134 | EXTERNAL = 0x80000000, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 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 | */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 141 | extern Flags<InputDeviceClass> getAbsAxisUsage(int32_t axis, Flags<InputDeviceClass> deviceClasses); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 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 | */ |
Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 156 | class EventHubInterface { |
| 157 | public: |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 158 | EventHubInterface() {} |
| 159 | virtual ~EventHubInterface() {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 160 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 161 | // Synthetic raw event type codes produced when devices are added or removed. |
| 162 | enum { |
| 163 | // Sent when a device is added. |
| 164 | DEVICE_ADDED = 0x10000000, |
| 165 | // Sent when a device is removed. |
| 166 | DEVICE_REMOVED = 0x20000000, |
| 167 | // Sent when all added/removed devices from the most recent scan have been reported. |
| 168 | // This event is always sent at least once. |
| 169 | FINISHED_DEVICE_SCAN = 0x30000000, |
| 170 | |
| 171 | FIRST_SYNTHETIC_EVENT = DEVICE_ADDED, |
| 172 | }; |
| 173 | |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 174 | virtual Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 175 | |
| 176 | virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0; |
| 177 | |
| 178 | virtual int32_t getDeviceControllerNumber(int32_t deviceId) const = 0; |
| 179 | |
| 180 | virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0; |
| 181 | |
| 182 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 183 | RawAbsoluteAxisInfo* outAxisInfo) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 184 | |
| 185 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0; |
| 186 | |
| 187 | virtual bool hasInputProperty(int32_t deviceId, int property) const = 0; |
| 188 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 189 | virtual bool hasMscEvent(int32_t deviceId, int mscEvent) const = 0; |
| 190 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 191 | virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
| 192 | int32_t metaState, int32_t* outKeycode, int32_t* outMetaState, |
| 193 | uint32_t* outFlags) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 194 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 195 | virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 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; |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 215 | virtual base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(int32_t deviceId, |
| 216 | int32_t absCode) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 217 | |
| 218 | /* |
| 219 | * Query current input state. |
| 220 | */ |
| 221 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0; |
| 222 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0; |
| 223 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0; |
| 224 | virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 225 | int32_t* outValue) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 226 | |
| 227 | /* |
| 228 | * Examine key input devices for specific framework keycode support |
| 229 | */ |
| 230 | virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 231 | uint8_t* outFlags) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 232 | |
| 233 | virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0; |
| 234 | |
| 235 | /* LED related functions expect Android LED constants, not scan codes or HID usages */ |
| 236 | virtual bool hasLed(int32_t deviceId, int32_t led) const = 0; |
| 237 | virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0; |
| 238 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 239 | virtual void getVirtualKeyDefinitions( |
| 240 | int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 241 | |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 242 | virtual const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0; |
| 243 | virtual bool setKeyboardLayoutOverlay(int32_t deviceId, |
| 244 | std::shared_ptr<KeyCharacterMap> map) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 245 | |
| 246 | /* Control the vibrator. */ |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 247 | virtual void vibrate(int32_t deviceId, const VibrationElement& effect) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 248 | virtual void cancelVibrate(int32_t deviceId) = 0; |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 249 | virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 250 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 251 | /* Query battery level. */ |
| 252 | virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId) const = 0; |
| 253 | |
| 254 | /* Query battery status. */ |
| 255 | virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId) const = 0; |
| 256 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 257 | /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */ |
| 258 | virtual void requestReopenDevices() = 0; |
| 259 | |
| 260 | /* Wakes up getEvents() if it is blocked on a read. */ |
| 261 | virtual void wake() = 0; |
| 262 | |
| 263 | /* Dump EventHub state to a string. */ |
Siarhei Vishniakou | f93fcf4 | 2017-11-22 16:00:14 -0800 | [diff] [blame] | 264 | virtual void dump(std::string& dump) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 265 | |
| 266 | /* Called by the heatbeat to ensures that the reader has not deadlocked. */ |
| 267 | virtual void monitor() = 0; |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 268 | |
| 269 | /* Return true if the device is enabled. */ |
| 270 | virtual bool isDeviceEnabled(int32_t deviceId) = 0; |
| 271 | |
| 272 | /* Enable an input device */ |
| 273 | virtual status_t enableDevice(int32_t deviceId) = 0; |
| 274 | |
| 275 | /* Disable an input device. Closes file descriptor to that device. */ |
| 276 | virtual status_t disableDevice(int32_t deviceId) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 277 | }; |
| 278 | |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 279 | template <std::size_t BITS> |
| 280 | class BitArray { |
| 281 | /* Array element type and vector of element type. */ |
| 282 | using Element = std::uint32_t; |
| 283 | /* Number of bits in each BitArray element. */ |
| 284 | static constexpr size_t WIDTH = sizeof(Element) * CHAR_BIT; |
| 285 | /* Number of elements to represent a bit array of the specified size of bits. */ |
| 286 | static constexpr size_t COUNT = (BITS + WIDTH - 1) / WIDTH; |
| 287 | |
| 288 | public: |
| 289 | /* BUFFER type declaration for BitArray */ |
| 290 | using Buffer = std::array<Element, COUNT>; |
| 291 | /* To tell if a bit is set in array, it selects an element from the array, and test |
| 292 | * if the relevant bit set. |
| 293 | * Note the parameter "bit" is an index to the bit, 0 <= bit < BITS. |
| 294 | */ |
| 295 | inline bool test(size_t bit) const { |
| 296 | return (bit < BITS) ? mData[bit / WIDTH].test(bit % WIDTH) : false; |
| 297 | } |
| 298 | /* Returns total number of bytes needed for the array */ |
| 299 | inline size_t bytes() { return (BITS + CHAR_BIT - 1) / CHAR_BIT; } |
| 300 | /* Returns true if array contains any non-zero bit from the range defined by start and end |
| 301 | * bit index [startIndex, endIndex). |
| 302 | */ |
| 303 | bool any(size_t startIndex, size_t endIndex) { |
| 304 | if (startIndex >= endIndex || startIndex > BITS || endIndex > BITS + 1) { |
| 305 | ALOGE("Invalid start/end index. start = %zu, end = %zu, total bits = %zu", startIndex, |
| 306 | endIndex, BITS); |
| 307 | return false; |
| 308 | } |
| 309 | size_t se = startIndex / WIDTH; // Start of element |
| 310 | size_t ee = endIndex / WIDTH; // End of element |
| 311 | size_t si = startIndex % WIDTH; // Start index in start element |
| 312 | size_t ei = endIndex % WIDTH; // End index in end element |
| 313 | // Need to check first unaligned bitset for any non zero bit |
| 314 | if (si > 0) { |
| 315 | size_t nBits = se == ee ? ei - si : WIDTH - si; |
| 316 | // Generate the mask of interested bit range |
| 317 | Element mask = ((1 << nBits) - 1) << si; |
| 318 | if (mData[se++].to_ulong() & mask) { |
| 319 | return true; |
| 320 | } |
| 321 | } |
| 322 | // Check whole bitset for any bit set |
| 323 | for (; se < ee; se++) { |
| 324 | if (mData[se].any()) { |
| 325 | return true; |
| 326 | } |
| 327 | } |
| 328 | // Need to check last unaligned bitset for any non zero bit |
| 329 | if (ei > 0 && se <= ee) { |
| 330 | // Generate the mask of interested bit range |
| 331 | Element mask = (1 << ei) - 1; |
| 332 | if (mData[se].to_ulong() & mask) { |
| 333 | return true; |
| 334 | } |
| 335 | } |
| 336 | return false; |
| 337 | } |
| 338 | /* Load bit array values from buffer */ |
| 339 | void loadFromBuffer(const Buffer& buffer) { |
| 340 | for (size_t i = 0; i < COUNT; i++) { |
| 341 | mData[i] = std::bitset<WIDTH>(buffer[i]); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | private: |
| 346 | std::array<std::bitset<WIDTH>, COUNT> mData; |
| 347 | }; |
| 348 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 349 | class EventHub : public EventHubInterface { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 350 | public: |
| 351 | EventHub(); |
| 352 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 353 | Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 354 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 355 | InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 356 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 357 | int32_t getDeviceControllerNumber(int32_t deviceId) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 358 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 359 | void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 360 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 361 | status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 362 | RawAbsoluteAxisInfo* outAxisInfo) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 363 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 364 | bool hasRelativeAxis(int32_t deviceId, int axis) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 365 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 366 | bool hasInputProperty(int32_t deviceId, int property) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 367 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 368 | bool hasMscEvent(int32_t deviceId, int mscEvent) const override final; |
| 369 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 370 | status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t metaState, |
| 371 | int32_t* outKeycode, int32_t* outMetaState, |
| 372 | uint32_t* outFlags) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 373 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 374 | status_t mapAxis(int32_t deviceId, int32_t scanCode, |
| 375 | AxisInfo* outAxisInfo) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 376 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 377 | base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor( |
| 378 | int32_t deviceId, int32_t absCode) override final; |
| 379 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 380 | void setExcludedDevices(const std::vector<std::string>& devices) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 381 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 382 | int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override final; |
| 383 | int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override final; |
| 384 | int32_t getSwitchState(int32_t deviceId, int32_t sw) const override final; |
| 385 | status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
| 386 | int32_t* outValue) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 387 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 388 | bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes, |
| 389 | uint8_t* outFlags) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 390 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 391 | size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) override final; |
| 392 | std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 393 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 394 | bool hasScanCode(int32_t deviceId, int32_t scanCode) const override final; |
| 395 | bool hasLed(int32_t deviceId, int32_t led) const override final; |
| 396 | void setLedState(int32_t deviceId, int32_t led, bool on) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 397 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 398 | void getVirtualKeyDefinitions( |
| 399 | int32_t deviceId, |
| 400 | std::vector<VirtualKeyDefinition>& outVirtualKeys) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 401 | |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 402 | const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap( |
| 403 | int32_t deviceId) const override final; |
| 404 | bool setKeyboardLayoutOverlay(int32_t deviceId, |
| 405 | std::shared_ptr<KeyCharacterMap> map) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 406 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 407 | void vibrate(int32_t deviceId, const VibrationElement& effect) override final; |
| 408 | void cancelVibrate(int32_t deviceId) override final; |
Chris Ye | 8714371 | 2020-11-10 05:05:58 +0000 | [diff] [blame] | 409 | std::vector<int32_t> getVibratorIds(int32_t deviceId) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 410 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 411 | void requestReopenDevices() override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 412 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 413 | void wake() override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 414 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 415 | void dump(std::string& dump) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 416 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 417 | void monitor() override final; |
| 418 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 419 | std::optional<int32_t> getBatteryCapacity(int32_t deviceId) const override final; |
| 420 | |
| 421 | std::optional<int32_t> getBatteryStatus(int32_t deviceId) const override final; |
| 422 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 423 | bool isDeviceEnabled(int32_t deviceId) override final; |
| 424 | |
| 425 | status_t enableDevice(int32_t deviceId) override final; |
| 426 | |
| 427 | status_t disableDevice(int32_t deviceId) override final; |
| 428 | |
| 429 | ~EventHub() override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 430 | |
| 431 | private: |
| 432 | struct Device { |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 433 | int fd; // may be -1 if device is closed |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 434 | const int32_t id; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 435 | const std::string path; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 436 | const InputDeviceIdentifier identifier; |
| 437 | |
Siarhei Vishniakou | ec7854a | 2018-12-14 16:52:34 -0800 | [diff] [blame] | 438 | std::unique_ptr<TouchVideoDevice> videoDevice; |
| 439 | |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 440 | Flags<InputDeviceClass> classes; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 441 | |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 442 | BitArray<KEY_MAX> keyBitmask; |
| 443 | BitArray<KEY_MAX> keyState; |
| 444 | BitArray<ABS_MAX> absBitmask; |
| 445 | BitArray<REL_MAX> relBitmask; |
| 446 | BitArray<SW_MAX> swBitmask; |
| 447 | BitArray<SW_MAX> swState; |
| 448 | BitArray<LED_MAX> ledBitmask; |
| 449 | BitArray<FF_MAX> ffBitmask; |
| 450 | BitArray<INPUT_PROP_MAX> propBitmask; |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 451 | BitArray<MSC_MAX> mscBitmask; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 452 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 453 | std::string configurationFile; |
Siarhei Vishniakou | d549b25 | 2020-08-11 11:25:26 -0500 | [diff] [blame] | 454 | std::unique_ptr<PropertyMap> configuration; |
Siarhei Vishniakou | 3e78dec | 2019-02-20 16:21:46 -0600 | [diff] [blame] | 455 | std::unique_ptr<VirtualKeyMap> virtualKeyMap; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 456 | KeyMap keyMap; |
| 457 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 458 | bool ffEffectPlaying; |
| 459 | int16_t ffEffectId; // initially -1 |
| 460 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 461 | // The paths are invalid when .empty() returns true |
| 462 | std::filesystem::path sysfsRootPath; |
| 463 | std::filesystem::path sysfsBatteryPath; |
| 464 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 465 | int32_t controllerNumber; |
| 466 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 467 | Device(int fd, int32_t id, const std::string& path, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 468 | const InputDeviceIdentifier& identifier); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 469 | ~Device(); |
| 470 | |
| 471 | void close(); |
| 472 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 473 | bool enabled; // initially true |
| 474 | status_t enable(); |
| 475 | status_t disable(); |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 476 | bool hasValidFd() const; |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 477 | const bool isVirtual; // set if fd < 0 is passed to constructor |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 478 | |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 479 | const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const; |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 480 | |
| 481 | template <std::size_t N> |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 482 | status_t readDeviceBitMask(unsigned long ioctlCode, BitArray<N>& bitArray); |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 483 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 484 | void configureFd(); |
| 485 | bool hasKeycodeLocked(int keycode) const; |
| 486 | void loadConfigurationLocked(); |
| 487 | bool loadVirtualKeyMapLocked(); |
| 488 | status_t loadKeyMapLocked(); |
| 489 | bool isExternalDeviceLocked(); |
| 490 | bool deviceHasMicLocked(); |
| 491 | void setLedForControllerLocked(); |
| 492 | status_t mapLed(int32_t led, int32_t* outScanCode) const; |
| 493 | void setLedStateLocked(int32_t led, bool on); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 494 | }; |
| 495 | |
Chris Ye | 8594e19 | 2020-07-14 10:34:06 -0700 | [diff] [blame] | 496 | status_t openDeviceLocked(const std::string& devicePath); |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 497 | void openVideoDeviceLocked(const std::string& devicePath); |
Siarhei Vishniakou | f49608d | 2020-08-20 19:18:21 -0500 | [diff] [blame] | 498 | /** |
| 499 | * Try to associate a video device with an input device. If the association succeeds, |
| 500 | * the videoDevice is moved into the input device. 'videoDevice' will become null if this |
| 501 | * happens. |
| 502 | * Return true if the association succeeds. |
| 503 | * Return false otherwise. |
| 504 | */ |
| 505 | bool tryAddVideoDevice(Device& device, std::unique_ptr<TouchVideoDevice>& videoDevice); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 506 | void createVirtualKeyboardLocked(); |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 507 | void addDeviceLocked(std::unique_ptr<Device> device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 508 | void assignDescriptorLocked(InputDeviceIdentifier& identifier); |
| 509 | |
Chris Ye | 8594e19 | 2020-07-14 10:34:06 -0700 | [diff] [blame] | 510 | void closeDeviceByPathLocked(const std::string& devicePath); |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 511 | void closeVideoDeviceByPathLocked(const std::string& devicePath); |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 512 | void closeDeviceLocked(Device& device); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 513 | void closeAllDevicesLocked(); |
| 514 | |
Siarhei Vishniakou | 2592031 | 2018-12-12 15:24:44 -0800 | [diff] [blame] | 515 | status_t registerFdForEpoll(int fd); |
| 516 | status_t unregisterFdFromEpoll(int fd); |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 517 | status_t registerDeviceForEpollLocked(Device& device); |
Siarhei Vishniakou | 1259868 | 2018-11-02 17:19:19 -0700 | [diff] [blame] | 518 | void registerVideoDeviceForEpollLocked(const TouchVideoDevice& videoDevice); |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 519 | status_t unregisterDeviceFromEpollLocked(Device& device); |
Siarhei Vishniakou | 1259868 | 2018-11-02 17:19:19 -0700 | [diff] [blame] | 520 | void unregisterVideoDeviceFromEpollLocked(const TouchVideoDevice& videoDevice); |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 521 | |
Chris Ye | 8594e19 | 2020-07-14 10:34:06 -0700 | [diff] [blame] | 522 | status_t scanDirLocked(const std::string& dirname); |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 523 | status_t scanVideoDirLocked(const std::string& dirname); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 524 | void scanDevicesLocked(); |
| 525 | status_t readNotifyLocked(); |
| 526 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 527 | Device* getDeviceByDescriptorLocked(const std::string& descriptor) const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 528 | Device* getDeviceLocked(int32_t deviceId) const; |
Chris Ye | 8594e19 | 2020-07-14 10:34:06 -0700 | [diff] [blame] | 529 | Device* getDeviceByPathLocked(const std::string& devicePath) const; |
Siarhei Vishniakou | 1259868 | 2018-11-02 17:19:19 -0700 | [diff] [blame] | 530 | /** |
| 531 | * Look through all available fd's (both for input devices and for video devices), |
| 532 | * and return the device pointer. |
| 533 | */ |
Siarhei Vishniakou | 4bc561c | 2018-11-02 17:41:58 -0700 | [diff] [blame] | 534 | Device* getDeviceByFdLocked(int fd) const; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 535 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 536 | int32_t getNextControllerNumberLocked(const std::string& name); |
| 537 | void releaseControllerNumberLocked(int32_t num); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 538 | |
| 539 | // Protect all internal state. |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 540 | mutable std::mutex mLock; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 541 | |
| 542 | // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none. |
| 543 | // EventHub remaps the built-in keyboard to id 0 externally as required by the API. |
| 544 | enum { |
| 545 | // Must not conflict with any other assigned device ids, including |
| 546 | // the virtual keyboard id (-1). |
| 547 | NO_BUILT_IN_KEYBOARD = -2, |
| 548 | }; |
| 549 | int32_t mBuiltInKeyboardId; |
| 550 | |
| 551 | int32_t mNextDeviceId; |
| 552 | |
| 553 | BitSet32 mControllerNumbers; |
| 554 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 555 | std::unordered_map<int32_t, std::unique_ptr<Device>> mDevices; |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 556 | /** |
| 557 | * Video devices that report touchscreen heatmap, but have not (yet) been paired |
| 558 | * with a specific input device. Video device discovery is independent from input device |
| 559 | * discovery, so the two types of devices could be found in any order. |
| 560 | * Ideally, video devices in this queue do not have an open fd, or at least aren't |
| 561 | * actively streaming. |
| 562 | */ |
| 563 | std::vector<std::unique_ptr<TouchVideoDevice>> mUnattachedVideoDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 564 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 565 | std::vector<std::unique_ptr<Device>> mOpeningDevices; |
| 566 | std::vector<std::unique_ptr<Device>> mClosingDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 567 | |
| 568 | bool mNeedToSendFinishedDeviceScan; |
| 569 | bool mNeedToReopenDevices; |
| 570 | bool mNeedToScanDevices; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 571 | std::vector<std::string> mExcludedDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 572 | |
| 573 | int mEpollFd; |
| 574 | int mINotifyFd; |
| 575 | int mWakeReadPipeFd; |
| 576 | int mWakeWritePipeFd; |
| 577 | |
Siarhei Vishniakou | 951f362 | 2018-12-12 19:45:42 -0800 | [diff] [blame] | 578 | int mInputWd; |
| 579 | int mVideoWd; |
| 580 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 581 | // Maximum number of signalled FDs to handle at a time. |
| 582 | static const int EPOLL_MAX_EVENTS = 16; |
| 583 | |
| 584 | // The array of pending epoll events and the index of the next event to be handled. |
| 585 | struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS]; |
| 586 | size_t mPendingEventCount; |
| 587 | size_t mPendingEventIndex; |
| 588 | bool mPendingINotify; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 589 | }; |
| 590 | |
| 591 | }; // namespace android |
| 592 | |
| 593 | #endif // _RUNTIME_EVENT_HUB_H |