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