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 | |
Prabir Pradhan | 4810866 | 2022-09-09 21:22:04 +0000 | [diff] [blame] | 17 | #pragma once |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 18 | |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 19 | #include <bitset> |
| 20 | #include <climits> |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 21 | #include <filesystem> |
Harry Cutts | ea73eaa | 2023-01-16 17:55:46 +0000 | [diff] [blame] | 22 | #include <ostream> |
| 23 | #include <string> |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 24 | #include <unordered_map> |
Prabir Pradhan | 5189478 | 2022-08-23 16:29:10 +0000 | [diff] [blame] | 25 | #include <utility> |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 26 | #include <vector> |
| 27 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 28 | #include <batteryservice/BatteryService.h> |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 29 | #include <ftl/flags.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 30 | #include <input/Input.h> |
| 31 | #include <input/InputDevice.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 32 | #include <input/KeyCharacterMap.h> |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 33 | #include <input/KeyLayoutMap.h> |
| 34 | #include <input/Keyboard.h> |
Siarhei Vishniakou | 32f36ae | 2020-09-02 20:17:10 -0700 | [diff] [blame] | 35 | #include <input/PropertyMap.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 36 | #include <input/VirtualKeyMap.h> |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 37 | #include <linux/input.h> |
| 38 | #include <sys/epoll.h> |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 39 | #include <utils/BitSet.h> |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 40 | #include <utils/Errors.h> |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 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 | |
Prabir Pradhan | 952e65b | 2022-06-23 17:49:55 +0000 | [diff] [blame] | 48 | struct inotify_event; |
| 49 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 50 | namespace android { |
| 51 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 52 | /* Number of colors : {red, green, blue} */ |
| 53 | static constexpr size_t COLOR_NUM = 3; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 54 | /* |
| 55 | * A raw event as retrieved from the EventHub. |
| 56 | */ |
| 57 | struct RawEvent { |
Siarhei Vishniakou | 58ba3d1 | 2021-02-11 01:31:07 +0000 | [diff] [blame] | 58 | // Time when the event happened |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 59 | nsecs_t when; |
Siarhei Vishniakou | 58ba3d1 | 2021-02-11 01:31:07 +0000 | [diff] [blame] | 60 | // Time when the event was read by EventHub. Only populated for input events. |
| 61 | // For other events (device added/removed/etc), this value is undefined and should not be read. |
| 62 | nsecs_t readTime; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 63 | int32_t deviceId; |
| 64 | int32_t type; |
| 65 | int32_t code; |
| 66 | int32_t value; |
| 67 | }; |
| 68 | |
| 69 | /* Describes an absolute axis. */ |
| 70 | struct RawAbsoluteAxisInfo { |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 71 | bool valid{false}; // true if the information is valid, false otherwise |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 72 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 73 | int32_t minValue{}; // minimum value |
| 74 | int32_t maxValue{}; // maximum value |
| 75 | int32_t flat{}; // center flat position, eg. flat == 8 means center is between -8 and 8 |
| 76 | int32_t fuzz{}; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise |
| 77 | int32_t resolution{}; // resolution in units per mm or radians per mm |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 78 | |
Prabir Pradhan | d6ccedb | 2022-09-27 21:04:06 +0000 | [diff] [blame] | 79 | inline void clear() { *this = RawAbsoluteAxisInfo(); } |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
Harry Cutts | ea73eaa | 2023-01-16 17:55:46 +0000 | [diff] [blame] | 82 | std::ostream& operator<<(std::ostream& out, const RawAbsoluteAxisInfo& info); |
| 83 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 84 | /* |
| 85 | * Input device classes. |
| 86 | */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 87 | enum class InputDeviceClass : uint32_t { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 88 | /* The input device is a keyboard or has buttons. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 89 | KEYBOARD = 0x00000001, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 90 | |
| 91 | /* 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] | 92 | ALPHAKEY = 0x00000002, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 93 | |
| 94 | /* 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] | 95 | TOUCH = 0x00000004, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 96 | |
| 97 | /* 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] | 98 | CURSOR = 0x00000008, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 99 | |
Harry Cutts | 79cc9fa | 2022-10-28 15:32:39 +0000 | [diff] [blame] | 100 | /* The input device is a multi-touch touchscreen or touchpad. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 101 | TOUCH_MT = 0x00000010, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 102 | |
| 103 | /* The input device is a directional pad (implies keyboard, has DPAD keys). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 104 | DPAD = 0x00000020, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 105 | |
| 106 | /* The input device is a gamepad (implies keyboard, has BUTTON keys). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 107 | GAMEPAD = 0x00000040, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 108 | |
| 109 | /* The input device has switches. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 110 | SWITCH = 0x00000080, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 111 | |
| 112 | /* The input device is a joystick (implies gamepad, has joystick absolute axes). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 113 | JOYSTICK = 0x00000100, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 114 | |
| 115 | /* The input device has a vibrator (supports FF_RUMBLE). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 116 | VIBRATOR = 0x00000200, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 117 | |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 118 | /* The input device has a microphone. */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 119 | MIC = 0x00000400, |
Tim Kilbourn | 063ff53 | 2015-04-08 10:26:18 -0700 | [diff] [blame] | 120 | |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 121 | /* 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] | 122 | EXTERNAL_STYLUS = 0x00000800, |
Michael Wright | 842500e | 2015-03-13 17:32:02 -0700 | [diff] [blame] | 123 | |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 124 | /* The input device has a rotary encoder */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 125 | ROTARY_ENCODER = 0x00001000, |
Prashant Malani | 1941ff5 | 2015-08-11 18:29:28 -0700 | [diff] [blame] | 126 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 127 | /* The input device has a sensor like accelerometer, gyro, etc */ |
| 128 | SENSOR = 0x00002000, |
| 129 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 130 | /* The input device has a battery */ |
| 131 | BATTERY = 0x00004000, |
| 132 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 133 | /* The input device has sysfs controllable lights */ |
| 134 | LIGHT = 0x00008000, |
| 135 | |
Harry Cutts | 79cc9fa | 2022-10-28 15:32:39 +0000 | [diff] [blame] | 136 | /* The input device is a touchpad, requiring an on-screen cursor. */ |
| 137 | TOUCHPAD = 0x00010000, |
| 138 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 139 | /* 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] | 140 | VIRTUAL = 0x40000000, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 141 | |
| 142 | /* The input device is external (not built-in). */ |
Chris Ye | 1b0c734 | 2020-07-28 21:57:03 -0700 | [diff] [blame] | 143 | EXTERNAL = 0x80000000, |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 144 | }; |
| 145 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 146 | enum class SysfsClass : uint32_t { |
| 147 | POWER_SUPPLY = 0, |
| 148 | LEDS = 1, |
Dominik Laskowski | 7578845 | 2021-02-09 18:51:25 -0800 | [diff] [blame] | 149 | |
| 150 | ftl_last = LEDS |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | enum class LightColor : uint32_t { |
| 154 | RED = 0, |
| 155 | GREEN = 1, |
| 156 | BLUE = 2, |
| 157 | }; |
| 158 | |
| 159 | enum class InputLightClass : uint32_t { |
| 160 | /* The input light has brightness node. */ |
| 161 | BRIGHTNESS = 0x00000001, |
| 162 | /* The input light has red name. */ |
| 163 | RED = 0x00000002, |
| 164 | /* The input light has green name. */ |
| 165 | GREEN = 0x00000004, |
| 166 | /* The input light has blue name. */ |
| 167 | BLUE = 0x00000008, |
| 168 | /* The input light has global name. */ |
| 169 | GLOBAL = 0x00000010, |
| 170 | /* The input light has multi index node. */ |
| 171 | MULTI_INDEX = 0x00000020, |
| 172 | /* The input light has multi intensity node. */ |
| 173 | MULTI_INTENSITY = 0x00000040, |
| 174 | /* The input light has max brightness node. */ |
| 175 | MAX_BRIGHTNESS = 0x00000080, |
Vaibhav Devmurari | 82b37d6 | 2022-09-12 13:36:48 +0000 | [diff] [blame] | 176 | /* The input light has kbd_backlight name */ |
| 177 | KEYBOARD_BACKLIGHT = 0x00000100, |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 178 | }; |
| 179 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 180 | enum class InputBatteryClass : uint32_t { |
| 181 | /* The input device battery has capacity node. */ |
| 182 | CAPACITY = 0x00000001, |
| 183 | /* The input device battery has capacity_level node. */ |
| 184 | CAPACITY_LEVEL = 0x00000002, |
| 185 | /* The input device battery has status node. */ |
| 186 | STATUS = 0x00000004, |
| 187 | }; |
| 188 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 189 | /* Describes a raw light. */ |
| 190 | struct RawLightInfo { |
| 191 | int32_t id; |
| 192 | std::string name; |
| 193 | std::optional<int32_t> maxBrightness; |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 194 | ftl::Flags<InputLightClass> flags; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 195 | std::array<int32_t, COLOR_NUM> rgbIndex; |
| 196 | std::filesystem::path path; |
Prabir Pradhan | edeec3b | 2022-08-26 22:33:55 +0000 | [diff] [blame] | 197 | |
| 198 | bool operator==(const RawLightInfo&) const = default; |
| 199 | bool operator!=(const RawLightInfo&) const = default; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 200 | }; |
| 201 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 202 | /* Describes a raw battery. */ |
| 203 | struct RawBatteryInfo { |
| 204 | int32_t id; |
| 205 | std::string name; |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 206 | ftl::Flags<InputBatteryClass> flags; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 207 | std::filesystem::path path; |
Prabir Pradhan | edeec3b | 2022-08-26 22:33:55 +0000 | [diff] [blame] | 208 | |
| 209 | bool operator==(const RawBatteryInfo&) const = default; |
| 210 | bool operator!=(const RawBatteryInfo&) const = default; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 211 | }; |
| 212 | |
Vaibhav Devmurari | 7fb4113 | 2023-01-02 13:30:26 +0000 | [diff] [blame] | 213 | /* Layout information associated with the device */ |
| 214 | struct RawLayoutInfo { |
| 215 | std::string languageTag; |
| 216 | std::string layoutType; |
| 217 | |
| 218 | bool operator==(const RawLayoutInfo&) const = default; |
| 219 | bool operator!=(const RawLayoutInfo&) const = default; |
| 220 | }; |
| 221 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 222 | /* |
| 223 | * Gets the class that owns an axis, in cases where multiple classes might claim |
| 224 | * the same axis for different purposes. |
| 225 | */ |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 226 | extern ftl::Flags<InputDeviceClass> getAbsAxisUsage(int32_t axis, |
| 227 | ftl::Flags<InputDeviceClass> deviceClasses); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 228 | |
| 229 | /* |
| 230 | * Grand Central Station for events. |
| 231 | * |
| 232 | * The event hub aggregates input events received across all known input |
| 233 | * devices on the system, including devices that may be emulated by the simulator |
| 234 | * environment. In addition, the event hub generates fake input events to indicate |
| 235 | * when devices are added or removed. |
| 236 | * |
| 237 | * The event hub provides a stream of input events (via the getEvent function). |
| 238 | * It also supports querying the current actual state of input devices such as identifying |
| 239 | * which keys are currently down. Finally, the event hub keeps track of the capabilities of |
| 240 | * individual input devices, such as their class and the set of key codes that they support. |
| 241 | */ |
Siarhei Vishniakou | 3bc7e09 | 2019-07-24 17:43:30 -0700 | [diff] [blame] | 242 | class EventHubInterface { |
| 243 | public: |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 244 | EventHubInterface() {} |
| 245 | virtual ~EventHubInterface() {} |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 246 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 247 | // Synthetic raw event type codes produced when devices are added or removed. |
| 248 | enum { |
| 249 | // Sent when a device is added. |
| 250 | DEVICE_ADDED = 0x10000000, |
| 251 | // Sent when a device is removed. |
| 252 | DEVICE_REMOVED = 0x20000000, |
| 253 | // Sent when all added/removed devices from the most recent scan have been reported. |
| 254 | // This event is always sent at least once. |
| 255 | FINISHED_DEVICE_SCAN = 0x30000000, |
| 256 | |
| 257 | FIRST_SYNTHETIC_EVENT = DEVICE_ADDED, |
| 258 | }; |
| 259 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 260 | virtual ftl::Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 261 | |
| 262 | virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0; |
| 263 | |
| 264 | virtual int32_t getDeviceControllerNumber(int32_t deviceId) const = 0; |
| 265 | |
Harry Cutts | c34f758 | 2023-03-07 16:23:30 +0000 | [diff] [blame] | 266 | /** |
| 267 | * Get the PropertyMap for the provided EventHub device, if available. |
| 268 | * This acquires the device lock, so a copy is returned rather than the raw pointer |
| 269 | * to the device's PropertyMap. A std::nullopt may be returned if the device could |
| 270 | * not be found, or if it doesn't have any configuration. |
| 271 | */ |
| 272 | virtual std::optional<PropertyMap> getConfiguration(int32_t deviceId) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 273 | |
| 274 | virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 275 | RawAbsoluteAxisInfo* outAxisInfo) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 276 | |
| 277 | virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0; |
| 278 | |
| 279 | virtual bool hasInputProperty(int32_t deviceId, int property) const = 0; |
| 280 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 281 | virtual bool hasMscEvent(int32_t deviceId, int mscEvent) const = 0; |
| 282 | |
Vaibhav Devmurari | cbba14c | 2022-10-10 16:54:49 +0000 | [diff] [blame] | 283 | virtual void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, |
| 284 | int32_t toKeyCode) const = 0; |
| 285 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 286 | virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, |
| 287 | int32_t metaState, int32_t* outKeycode, int32_t* outMetaState, |
| 288 | uint32_t* outFlags) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 289 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 290 | 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] | 291 | |
| 292 | // Sets devices that are excluded from opening. |
| 293 | // This can be used to ignore input devices for sensors. |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 294 | virtual void setExcludedDevices(const std::vector<std::string>& devices) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 295 | |
| 296 | /* |
| 297 | * Wait for events to become available and returns them. |
| 298 | * After returning, the EventHub holds onto a wake lock until the next call to getEvent. |
| 299 | * This ensures that the device will not go to sleep while the event is being processed. |
| 300 | * If the device needs to remain awake longer than that, then the caller is responsible |
| 301 | * for taking care of it (say, by poking the power manager user activity timer). |
| 302 | * |
| 303 | * The timeout is advisory only. If the device is asleep, it will not wake just to |
| 304 | * service the timeout. |
| 305 | * |
| 306 | * Returns the number of events obtained, or 0 if the timeout expired. |
| 307 | */ |
Siarhei Vishniakou | 7b3ea0b | 2022-09-16 14:23:20 -0700 | [diff] [blame] | 308 | virtual std::vector<RawEvent> getEvents(int timeoutMillis) = 0; |
Siarhei Vishniakou | add8929 | 2018-12-13 19:23:36 -0800 | [diff] [blame] | 309 | virtual std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) = 0; |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 310 | virtual base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor( |
| 311 | int32_t deviceId, int32_t absCode) const = 0; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 312 | // Raw batteries are sysfs power_supply nodes we found from the EventHub device sysfs node, |
| 313 | // containing the raw info of the sysfs node structure. |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 314 | virtual std::vector<int32_t> getRawBatteryIds(int32_t deviceId) const = 0; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 315 | virtual std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId, |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 316 | int32_t BatteryId) const = 0; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 317 | |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 318 | // Raw lights are sysfs led light nodes we found from the EventHub device sysfs node, |
| 319 | // containing the raw info of the sysfs node structure. |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 320 | virtual std::vector<int32_t> getRawLightIds(int32_t deviceId) const = 0; |
| 321 | virtual std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId, |
| 322 | int32_t lightId) const = 0; |
| 323 | virtual std::optional<int32_t> getLightBrightness(int32_t deviceId, int32_t lightId) const = 0; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 324 | virtual void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) = 0; |
| 325 | virtual std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities( |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 326 | int32_t deviceId, int32_t lightId) const = 0; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 327 | virtual void setLightIntensities(int32_t deviceId, int32_t lightId, |
| 328 | std::unordered_map<LightColor, int32_t> intensities) = 0; |
Vaibhav Devmurari | 7fb4113 | 2023-01-02 13:30:26 +0000 | [diff] [blame] | 329 | /* Query Layout info associated with the input device. */ |
| 330 | virtual std::optional<RawLayoutInfo> getRawLayoutInfo(int32_t deviceId) const = 0; |
Vaibhav Devmurari | dd82b8e | 2022-08-16 15:34:01 +0000 | [diff] [blame] | 331 | /* Query current input state. */ |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 332 | virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0; |
| 333 | virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0; |
| 334 | virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0; |
| 335 | virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 336 | int32_t* outValue) const = 0; |
Philip Junker | 4af3b3d | 2021-12-14 10:36:55 +0100 | [diff] [blame] | 337 | virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 338 | |
| 339 | /* |
| 340 | * Examine key input devices for specific framework keycode support |
| 341 | */ |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 342 | virtual bool markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes, |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 343 | uint8_t* outFlags) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 344 | |
| 345 | virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0; |
Arthur Hung | cb40a00 | 2021-08-03 14:31:01 +0000 | [diff] [blame] | 346 | virtual bool hasKeyCode(int32_t deviceId, int32_t keyCode) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 347 | |
| 348 | /* LED related functions expect Android LED constants, not scan codes or HID usages */ |
| 349 | virtual bool hasLed(int32_t deviceId, int32_t led) const = 0; |
| 350 | virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0; |
| 351 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 352 | virtual void getVirtualKeyDefinitions( |
| 353 | int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 354 | |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 355 | virtual const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0; |
| 356 | virtual bool setKeyboardLayoutOverlay(int32_t deviceId, |
| 357 | std::shared_ptr<KeyCharacterMap> map) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 358 | |
| 359 | /* Control the vibrator. */ |
Nathaniel R. Lewis | cacd69a | 2019-08-12 22:07:00 +0000 | [diff] [blame] | 360 | virtual void vibrate(int32_t deviceId, const VibrationElement& effect) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 361 | virtual void cancelVibrate(int32_t deviceId) = 0; |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 362 | virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 363 | |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 364 | /* Query battery level. */ |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 365 | virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId, |
| 366 | int32_t batteryId) const = 0; |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 367 | |
| 368 | /* Query battery status. */ |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 369 | virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId, int32_t batteryId) const = 0; |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 370 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 371 | /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */ |
| 372 | virtual void requestReopenDevices() = 0; |
| 373 | |
| 374 | /* Wakes up getEvents() if it is blocked on a read. */ |
| 375 | virtual void wake() = 0; |
| 376 | |
| 377 | /* Dump EventHub state to a string. */ |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 378 | virtual void dump(std::string& dump) const = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 379 | |
| 380 | /* Called by the heatbeat to ensures that the reader has not deadlocked. */ |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 381 | virtual void monitor() const = 0; |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 382 | |
| 383 | /* Return true if the device is enabled. */ |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 384 | virtual bool isDeviceEnabled(int32_t deviceId) const = 0; |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 385 | |
| 386 | /* Enable an input device */ |
| 387 | virtual status_t enableDevice(int32_t deviceId) = 0; |
| 388 | |
| 389 | /* Disable an input device. Closes file descriptor to that device. */ |
| 390 | virtual status_t disableDevice(int32_t deviceId) = 0; |
Vaibhav Devmurari | 5fc7d85 | 2023-03-17 18:43:33 +0000 | [diff] [blame] | 391 | |
| 392 | /* Sysfs node changed. Reopen the Eventhub device if any new Peripheral like Light, Battery, |
| 393 | * etc. is detected. */ |
| 394 | virtual void sysfsNodeChanged(const std::string& sysfsNodePath) = 0; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 395 | }; |
| 396 | |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 397 | template <std::size_t BITS> |
| 398 | class BitArray { |
| 399 | /* Array element type and vector of element type. */ |
| 400 | using Element = std::uint32_t; |
| 401 | /* Number of bits in each BitArray element. */ |
| 402 | static constexpr size_t WIDTH = sizeof(Element) * CHAR_BIT; |
| 403 | /* Number of elements to represent a bit array of the specified size of bits. */ |
| 404 | static constexpr size_t COUNT = (BITS + WIDTH - 1) / WIDTH; |
| 405 | |
| 406 | public: |
| 407 | /* BUFFER type declaration for BitArray */ |
| 408 | using Buffer = std::array<Element, COUNT>; |
| 409 | /* To tell if a bit is set in array, it selects an element from the array, and test |
| 410 | * if the relevant bit set. |
| 411 | * Note the parameter "bit" is an index to the bit, 0 <= bit < BITS. |
| 412 | */ |
| 413 | inline bool test(size_t bit) const { |
Prabir Pradhan | 9762ac9 | 2023-07-13 21:45:12 +0000 | [diff] [blame] | 414 | return (bit < BITS) && mData[bit / WIDTH].test(bit % WIDTH); |
| 415 | } |
| 416 | /* Sets the given bit in the bit array to given value. |
| 417 | * Returns true if the given bit is a valid index and thus was set successfully. |
| 418 | */ |
| 419 | inline bool set(size_t bit, bool value) { |
| 420 | if (bit >= BITS) { |
| 421 | return false; |
| 422 | } |
| 423 | mData[bit / WIDTH].set(bit % WIDTH, value); |
| 424 | return true; |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 425 | } |
| 426 | /* Returns total number of bytes needed for the array */ |
| 427 | inline size_t bytes() { return (BITS + CHAR_BIT - 1) / CHAR_BIT; } |
| 428 | /* Returns true if array contains any non-zero bit from the range defined by start and end |
| 429 | * bit index [startIndex, endIndex). |
| 430 | */ |
| 431 | bool any(size_t startIndex, size_t endIndex) { |
| 432 | if (startIndex >= endIndex || startIndex > BITS || endIndex > BITS + 1) { |
| 433 | ALOGE("Invalid start/end index. start = %zu, end = %zu, total bits = %zu", startIndex, |
| 434 | endIndex, BITS); |
| 435 | return false; |
| 436 | } |
| 437 | size_t se = startIndex / WIDTH; // Start of element |
| 438 | size_t ee = endIndex / WIDTH; // End of element |
| 439 | size_t si = startIndex % WIDTH; // Start index in start element |
| 440 | size_t ei = endIndex % WIDTH; // End index in end element |
| 441 | // Need to check first unaligned bitset for any non zero bit |
| 442 | if (si > 0) { |
| 443 | size_t nBits = se == ee ? ei - si : WIDTH - si; |
| 444 | // Generate the mask of interested bit range |
| 445 | Element mask = ((1 << nBits) - 1) << si; |
| 446 | if (mData[se++].to_ulong() & mask) { |
| 447 | return true; |
| 448 | } |
| 449 | } |
| 450 | // Check whole bitset for any bit set |
| 451 | for (; se < ee; se++) { |
| 452 | if (mData[se].any()) { |
| 453 | return true; |
| 454 | } |
| 455 | } |
| 456 | // Need to check last unaligned bitset for any non zero bit |
| 457 | if (ei > 0 && se <= ee) { |
| 458 | // Generate the mask of interested bit range |
| 459 | Element mask = (1 << ei) - 1; |
| 460 | if (mData[se].to_ulong() & mask) { |
| 461 | return true; |
| 462 | } |
| 463 | } |
| 464 | return false; |
| 465 | } |
| 466 | /* Load bit array values from buffer */ |
| 467 | void loadFromBuffer(const Buffer& buffer) { |
| 468 | for (size_t i = 0; i < COUNT; i++) { |
| 469 | mData[i] = std::bitset<WIDTH>(buffer[i]); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | private: |
| 474 | std::array<std::bitset<WIDTH>, COUNT> mData; |
| 475 | }; |
| 476 | |
Prabir Pradhan | da7c00c | 2019-08-29 14:12:42 -0700 | [diff] [blame] | 477 | class EventHub : public EventHubInterface { |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 478 | public: |
| 479 | EventHub(); |
| 480 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 481 | ftl::Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 482 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 483 | InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 484 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 485 | int32_t getDeviceControllerNumber(int32_t deviceId) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 486 | |
Harry Cutts | c34f758 | 2023-03-07 16:23:30 +0000 | [diff] [blame] | 487 | std::optional<PropertyMap> getConfiguration(int32_t deviceId) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 488 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 489 | status_t getAbsoluteAxisInfo(int32_t deviceId, int axis, |
| 490 | RawAbsoluteAxisInfo* outAxisInfo) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 491 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 492 | bool hasRelativeAxis(int32_t deviceId, int axis) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 493 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 494 | bool hasInputProperty(int32_t deviceId, int property) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 495 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 496 | bool hasMscEvent(int32_t deviceId, int mscEvent) const override final; |
| 497 | |
Vaibhav Devmurari | cbba14c | 2022-10-10 16:54:49 +0000 | [diff] [blame] | 498 | void addKeyRemapping(int32_t deviceId, int32_t fromKeyCode, |
| 499 | int32_t toKeyCode) const override final; |
| 500 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 501 | status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t metaState, |
| 502 | int32_t* outKeycode, int32_t* outMetaState, |
| 503 | uint32_t* outFlags) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 504 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 505 | status_t mapAxis(int32_t deviceId, int32_t scanCode, |
| 506 | AxisInfo* outAxisInfo) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 507 | |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 508 | base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor( |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 509 | int32_t deviceId, int32_t absCode) const override final; |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 510 | |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 511 | std::vector<int32_t> getRawBatteryIds(int32_t deviceId) const override final; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 512 | std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId, |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 513 | int32_t BatteryId) const override final; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 514 | |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 515 | std::vector<int32_t> getRawLightIds(int32_t deviceId) const override final; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 516 | |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 517 | std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId, |
| 518 | int32_t lightId) const override final; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 519 | |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 520 | std::optional<int32_t> getLightBrightness(int32_t deviceId, |
| 521 | int32_t lightId) const override final; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 522 | void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) override final; |
| 523 | std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities( |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 524 | int32_t deviceId, int32_t lightId) const override final; |
Chris Ye | 3fdbfef | 2021-01-06 18:45:18 -0800 | [diff] [blame] | 525 | void setLightIntensities(int32_t deviceId, int32_t lightId, |
| 526 | std::unordered_map<LightColor, int32_t> intensities) override final; |
| 527 | |
Vaibhav Devmurari | 7fb4113 | 2023-01-02 13:30:26 +0000 | [diff] [blame] | 528 | std::optional<RawLayoutInfo> getRawLayoutInfo(int32_t deviceId) const override final; |
Vaibhav Devmurari | dd82b8e | 2022-08-16 15:34:01 +0000 | [diff] [blame] | 529 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 530 | void setExcludedDevices(const std::vector<std::string>& devices) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 531 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 532 | int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override final; |
| 533 | int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override final; |
| 534 | int32_t getSwitchState(int32_t deviceId, int32_t sw) const override final; |
Philip Junker | 4af3b3d | 2021-12-14 10:36:55 +0100 | [diff] [blame] | 535 | int32_t getKeyCodeForKeyLocation(int32_t deviceId, |
| 536 | int32_t locationKeyCode) const override final; |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 537 | status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, |
| 538 | int32_t* outValue) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 539 | |
Siarhei Vishniakou | 7400794 | 2022-06-13 13:57:47 -0700 | [diff] [blame] | 540 | bool markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes, |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 541 | uint8_t* outFlags) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 542 | |
Siarhei Vishniakou | 7b3ea0b | 2022-09-16 14:23:20 -0700 | [diff] [blame] | 543 | std::vector<RawEvent> getEvents(int timeoutMillis) override final; |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 544 | std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 545 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 546 | bool hasScanCode(int32_t deviceId, int32_t scanCode) const override final; |
Arthur Hung | cb40a00 | 2021-08-03 14:31:01 +0000 | [diff] [blame] | 547 | bool hasKeyCode(int32_t deviceId, int32_t keyCode) const override final; |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 548 | bool hasLed(int32_t deviceId, int32_t led) const override final; |
| 549 | void setLedState(int32_t deviceId, int32_t led, bool on) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 550 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 551 | void getVirtualKeyDefinitions( |
| 552 | int32_t deviceId, |
| 553 | std::vector<VirtualKeyDefinition>& outVirtualKeys) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 554 | |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 555 | const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap( |
| 556 | int32_t deviceId) const override final; |
| 557 | bool setKeyboardLayoutOverlay(int32_t deviceId, |
| 558 | std::shared_ptr<KeyCharacterMap> map) override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 559 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 560 | void vibrate(int32_t deviceId, const VibrationElement& effect) override final; |
| 561 | void cancelVibrate(int32_t deviceId) override final; |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 562 | std::vector<int32_t> getVibratorIds(int32_t deviceId) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 563 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 564 | void requestReopenDevices() override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 565 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 566 | void wake() override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 567 | |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 568 | void dump(std::string& dump) const override final; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 569 | |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 570 | void monitor() const override final; |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 571 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 572 | std::optional<int32_t> getBatteryCapacity(int32_t deviceId, |
| 573 | int32_t batteryId) const override final; |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 574 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 575 | std::optional<int32_t> getBatteryStatus(int32_t deviceId, |
| 576 | int32_t batteryId) const override final; |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 577 | |
Prabir Pradhan | ae4ff28 | 2022-08-23 16:21:39 +0000 | [diff] [blame] | 578 | bool isDeviceEnabled(int32_t deviceId) const override final; |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 579 | |
| 580 | status_t enableDevice(int32_t deviceId) override final; |
| 581 | |
| 582 | status_t disableDevice(int32_t deviceId) override final; |
| 583 | |
Vaibhav Devmurari | 5fc7d85 | 2023-03-17 18:43:33 +0000 | [diff] [blame] | 584 | void sysfsNodeChanged(const std::string& sysfsNodePath) override final; |
| 585 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 586 | ~EventHub() override; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 587 | |
| 588 | private: |
Prabir Pradhan | cb42b47 | 2022-08-23 16:01:19 +0000 | [diff] [blame] | 589 | // Holds information about the sysfs device associated with the Device. |
Chris Ye | 1dd2e5c | 2021-04-04 23:12:41 -0700 | [diff] [blame] | 590 | struct AssociatedDevice { |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 591 | // The sysfs root path of the misc device. |
| 592 | std::filesystem::path sysfsRootPath; |
Prabir Pradhan | cb42b47 | 2022-08-23 16:01:19 +0000 | [diff] [blame] | 593 | std::unordered_map<int32_t /*batteryId*/, RawBatteryInfo> batteryInfos; |
| 594 | std::unordered_map<int32_t /*lightId*/, RawLightInfo> lightInfos; |
Vaibhav Devmurari | 7fb4113 | 2023-01-02 13:30:26 +0000 | [diff] [blame] | 595 | std::optional<RawLayoutInfo> layoutInfo; |
Prabir Pradhan | edeec3b | 2022-08-26 22:33:55 +0000 | [diff] [blame] | 596 | |
Vaibhav Devmurari | 5fc7d85 | 2023-03-17 18:43:33 +0000 | [diff] [blame] | 597 | bool isChanged() const; |
Prabir Pradhan | edeec3b | 2022-08-26 22:33:55 +0000 | [diff] [blame] | 598 | bool operator==(const AssociatedDevice&) const = default; |
| 599 | bool operator!=(const AssociatedDevice&) const = default; |
| 600 | std::string dump() const; |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 601 | }; |
| 602 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 603 | struct Device { |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 604 | int fd; // may be -1 if device is closed |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 605 | const int32_t id; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 606 | const std::string path; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 607 | const InputDeviceIdentifier identifier; |
| 608 | |
Siarhei Vishniakou | ec7854a | 2018-12-14 16:52:34 -0800 | [diff] [blame] | 609 | std::unique_ptr<TouchVideoDevice> videoDevice; |
| 610 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 611 | ftl::Flags<InputDeviceClass> classes; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 612 | |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 613 | BitArray<KEY_MAX> keyBitmask; |
| 614 | BitArray<KEY_MAX> keyState; |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 615 | BitArray<REL_MAX> relBitmask; |
| 616 | BitArray<SW_MAX> swBitmask; |
| 617 | BitArray<SW_MAX> swState; |
| 618 | BitArray<LED_MAX> ledBitmask; |
| 619 | BitArray<FF_MAX> ffBitmask; |
| 620 | BitArray<INPUT_PROP_MAX> propBitmask; |
Chris Ye | f59a2f4 | 2020-10-16 12:55:26 -0700 | [diff] [blame] | 621 | BitArray<MSC_MAX> mscBitmask; |
Prabir Pradhan | 341d078 | 2023-07-14 19:04:10 +0000 | [diff] [blame^] | 622 | BitArray<ABS_MAX> absBitmask; |
| 623 | struct AxisState { |
| 624 | RawAbsoluteAxisInfo info; |
| 625 | int value; |
| 626 | }; |
| 627 | std::unordered_map<int /*axis*/, AxisState> absState; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 628 | |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 629 | std::string configurationFile; |
Siarhei Vishniakou | d549b25 | 2020-08-11 11:25:26 -0500 | [diff] [blame] | 630 | std::unique_ptr<PropertyMap> configuration; |
Siarhei Vishniakou | 3e78dec | 2019-02-20 16:21:46 -0600 | [diff] [blame] | 631 | std::unique_ptr<VirtualKeyMap> virtualKeyMap; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 632 | KeyMap keyMap; |
| 633 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 634 | bool ffEffectPlaying; |
| 635 | int16_t ffEffectId; // initially -1 |
| 636 | |
Chris Ye | 1dd2e5c | 2021-04-04 23:12:41 -0700 | [diff] [blame] | 637 | // A shared_ptr of a device associated with the input device. |
Prabir Pradhan | 5189478 | 2022-08-23 16:29:10 +0000 | [diff] [blame] | 638 | // The input devices that have the same sysfs path have the same associated device. |
Prabir Pradhan | edeec3b | 2022-08-26 22:33:55 +0000 | [diff] [blame] | 639 | std::shared_ptr<const AssociatedDevice> associatedDevice; |
Kim Low | 03ea035 | 2020-11-06 12:45:07 -0800 | [diff] [blame] | 640 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 641 | int32_t controllerNumber; |
| 642 | |
Prabir Pradhan | cb42b47 | 2022-08-23 16:01:19 +0000 | [diff] [blame] | 643 | Device(int fd, int32_t id, std::string path, InputDeviceIdentifier identifier, |
| 644 | std::shared_ptr<const AssociatedDevice> assocDev); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 645 | ~Device(); |
| 646 | |
| 647 | void close(); |
| 648 | |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 649 | bool enabled; // initially true |
| 650 | status_t enable(); |
| 651 | status_t disable(); |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 652 | bool hasValidFd() const; |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 653 | const bool isVirtual; // set if fd < 0 is passed to constructor |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 654 | |
Chris Ye | 3a1e446 | 2020-08-12 10:13:15 -0700 | [diff] [blame] | 655 | const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const; |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 656 | |
| 657 | template <std::size_t N> |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 658 | status_t readDeviceBitMask(unsigned long ioctlCode, BitArray<N>& bitArray); |
Chris Ye | 66fbac3 | 2020-07-06 20:36:43 -0700 | [diff] [blame] | 659 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 660 | void configureFd(); |
Prabir Pradhan | 341d078 | 2023-07-14 19:04:10 +0000 | [diff] [blame^] | 661 | void populateAbsoluteAxisStates(); |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 662 | bool hasKeycodeLocked(int keycode) const; |
| 663 | void loadConfigurationLocked(); |
| 664 | bool loadVirtualKeyMapLocked(); |
| 665 | status_t loadKeyMapLocked(); |
| 666 | bool isExternalDeviceLocked(); |
| 667 | bool deviceHasMicLocked(); |
| 668 | void setLedForControllerLocked(); |
| 669 | status_t mapLed(int32_t led, int32_t* outScanCode) const; |
| 670 | void setLedStateLocked(int32_t led, bool on); |
Prabir Pradhan | 9762ac9 | 2023-07-13 21:45:12 +0000 | [diff] [blame] | 671 | |
| 672 | bool currentFrameDropped; |
| 673 | void trackInputEvent(const struct input_event& event); |
| 674 | void readDeviceState(); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 675 | }; |
| 676 | |
Siarhei Vishniakou | a4c502a | 2021-02-05 00:45:20 +0000 | [diff] [blame] | 677 | /** |
| 678 | * Create a new device for the provided path. |
| 679 | */ |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 680 | void openDeviceLocked(const std::string& devicePath) REQUIRES(mLock); |
| 681 | void openVideoDeviceLocked(const std::string& devicePath) REQUIRES(mLock); |
Siarhei Vishniakou | f49608d | 2020-08-20 19:18:21 -0500 | [diff] [blame] | 682 | /** |
| 683 | * Try to associate a video device with an input device. If the association succeeds, |
| 684 | * the videoDevice is moved into the input device. 'videoDevice' will become null if this |
| 685 | * happens. |
| 686 | * Return true if the association succeeds. |
| 687 | * Return false otherwise. |
| 688 | */ |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 689 | bool tryAddVideoDeviceLocked(Device& device, std::unique_ptr<TouchVideoDevice>& videoDevice) |
| 690 | REQUIRES(mLock); |
| 691 | void createVirtualKeyboardLocked() REQUIRES(mLock); |
| 692 | void addDeviceLocked(std::unique_ptr<Device> device) REQUIRES(mLock); |
| 693 | void assignDescriptorLocked(InputDeviceIdentifier& identifier) REQUIRES(mLock); |
Prabir Pradhan | cb42b47 | 2022-08-23 16:01:19 +0000 | [diff] [blame] | 694 | std::shared_ptr<const AssociatedDevice> obtainAssociatedDeviceLocked( |
| 695 | const std::filesystem::path& devicePath) const REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 696 | |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 697 | void closeDeviceByPathLocked(const std::string& devicePath) REQUIRES(mLock); |
| 698 | void closeVideoDeviceByPathLocked(const std::string& devicePath) REQUIRES(mLock); |
| 699 | void closeDeviceLocked(Device& device) REQUIRES(mLock); |
| 700 | void closeAllDevicesLocked() REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 701 | |
Siarhei Vishniakou | 2592031 | 2018-12-12 15:24:44 -0800 | [diff] [blame] | 702 | status_t registerFdForEpoll(int fd); |
| 703 | status_t unregisterFdFromEpoll(int fd); |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 704 | status_t registerDeviceForEpollLocked(Device& device) REQUIRES(mLock); |
| 705 | void registerVideoDeviceForEpollLocked(const TouchVideoDevice& videoDevice) REQUIRES(mLock); |
| 706 | status_t unregisterDeviceFromEpollLocked(Device& device) REQUIRES(mLock); |
| 707 | void unregisterVideoDeviceFromEpollLocked(const TouchVideoDevice& videoDevice) REQUIRES(mLock); |
Siarhei Vishniakou | e54cb85 | 2017-03-21 17:48:16 -0700 | [diff] [blame] | 708 | |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 709 | status_t scanDirLocked(const std::string& dirname) REQUIRES(mLock); |
| 710 | status_t scanVideoDirLocked(const std::string& dirname) REQUIRES(mLock); |
| 711 | void scanDevicesLocked() REQUIRES(mLock); |
Prabir Pradhan | 952e65b | 2022-06-23 17:49:55 +0000 | [diff] [blame] | 712 | base::Result<void> readNotifyLocked() REQUIRES(mLock); |
| 713 | void handleNotifyEventLocked(const inotify_event&) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 714 | |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 715 | Device* getDeviceLocked(int32_t deviceId) const REQUIRES(mLock); |
| 716 | Device* getDeviceByPathLocked(const std::string& devicePath) const REQUIRES(mLock); |
Siarhei Vishniakou | 1259868 | 2018-11-02 17:19:19 -0700 | [diff] [blame] | 717 | /** |
| 718 | * Look through all available fd's (both for input devices and for video devices), |
| 719 | * and return the device pointer. |
| 720 | */ |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 721 | Device* getDeviceByFdLocked(int fd) const REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 722 | |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 723 | int32_t getNextControllerNumberLocked(const std::string& name) REQUIRES(mLock); |
Josh Bartel | 938632f | 2022-07-19 15:34:22 -0500 | [diff] [blame] | 724 | |
| 725 | bool hasDeviceWithDescriptorLocked(const std::string& descriptor) const REQUIRES(mLock); |
| 726 | |
Chris Ye | d3fef46 | 2021-03-07 17:10:08 -0800 | [diff] [blame] | 727 | void releaseControllerNumberLocked(int32_t num) REQUIRES(mLock); |
| 728 | void reportDeviceAddedForStatisticsLocked(const InputDeviceIdentifier& identifier, |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 729 | ftl::Flags<InputDeviceClass> classes) REQUIRES(mLock); |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 730 | |
Chris Ye | e2b1e5c | 2021-03-10 22:45:12 -0800 | [diff] [blame] | 731 | const std::unordered_map<int32_t, RawBatteryInfo>& getBatteryInfoLocked(int32_t deviceId) const |
| 732 | REQUIRES(mLock); |
| 733 | |
| 734 | const std::unordered_map<int32_t, RawLightInfo>& getLightInfoLocked(int32_t deviceId) const |
| 735 | REQUIRES(mLock); |
| 736 | |
Usama Arif | b27c8e6 | 2021-06-03 16:44:09 +0100 | [diff] [blame] | 737 | void addDeviceInputInotify(); |
| 738 | void addDeviceInotify(); |
| 739 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 740 | // Protect all internal state. |
Chris Ye | 1c2e089 | 2020-11-30 21:41:44 -0800 | [diff] [blame] | 741 | mutable std::mutex mLock; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 742 | |
| 743 | // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none. |
| 744 | // EventHub remaps the built-in keyboard to id 0 externally as required by the API. |
| 745 | enum { |
| 746 | // Must not conflict with any other assigned device ids, including |
| 747 | // the virtual keyboard id (-1). |
| 748 | NO_BUILT_IN_KEYBOARD = -2, |
| 749 | }; |
| 750 | int32_t mBuiltInKeyboardId; |
| 751 | |
| 752 | int32_t mNextDeviceId; |
| 753 | |
| 754 | BitSet32 mControllerNumbers; |
| 755 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 756 | std::unordered_map<int32_t, std::unique_ptr<Device>> mDevices; |
Siarhei Vishniakou | 22c8846 | 2018-12-13 19:34:53 -0800 | [diff] [blame] | 757 | /** |
| 758 | * Video devices that report touchscreen heatmap, but have not (yet) been paired |
| 759 | * with a specific input device. Video device discovery is independent from input device |
| 760 | * discovery, so the two types of devices could be found in any order. |
| 761 | * Ideally, video devices in this queue do not have an open fd, or at least aren't |
| 762 | * actively streaming. |
| 763 | */ |
| 764 | std::vector<std::unique_ptr<TouchVideoDevice>> mUnattachedVideoDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 765 | |
Chris Ye | 989bb93 | 2020-07-04 16:18:59 -0700 | [diff] [blame] | 766 | std::vector<std::unique_ptr<Device>> mOpeningDevices; |
| 767 | std::vector<std::unique_ptr<Device>> mClosingDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 768 | |
| 769 | bool mNeedToSendFinishedDeviceScan; |
| 770 | bool mNeedToReopenDevices; |
| 771 | bool mNeedToScanDevices; |
Siarhei Vishniakou | ec8f725 | 2018-07-06 11:19:32 +0100 | [diff] [blame] | 772 | std::vector<std::string> mExcludedDevices; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 773 | |
| 774 | int mEpollFd; |
| 775 | int mINotifyFd; |
| 776 | int mWakeReadPipeFd; |
| 777 | int mWakeWritePipeFd; |
| 778 | |
Usama Arif | b27c8e6 | 2021-06-03 16:44:09 +0100 | [diff] [blame] | 779 | int mDeviceInputWd; |
| 780 | int mDeviceWd = -1; |
Siarhei Vishniakou | 951f362 | 2018-12-12 19:45:42 -0800 | [diff] [blame] | 781 | |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 782 | // Maximum number of signalled FDs to handle at a time. |
| 783 | static const int EPOLL_MAX_EVENTS = 16; |
| 784 | |
| 785 | // The array of pending epoll events and the index of the next event to be handled. |
| 786 | struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS]; |
| 787 | size_t mPendingEventCount; |
| 788 | size_t mPendingEventIndex; |
| 789 | bool mPendingINotify; |
Michael Wright | d02c5b6 | 2014-02-10 15:10:22 -0800 | [diff] [blame] | 790 | }; |
| 791 | |
Dominik Laskowski | 2f01d77 | 2022-03-23 16:01:29 -0700 | [diff] [blame] | 792 | } // namespace android |