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