blob: ceae10db0c8203691678932e3a336c82602fbd4e [file] [log] [blame]
Michael Wrightd02c5b62014-02-10 15:10:22 -08001/*
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 Pradhan48108662022-09-09 21:22:04 +000017#pragma once
Michael Wrightd02c5b62014-02-10 15:10:22 -080018
Chris Ye66fbac32020-07-06 20:36:43 -070019#include <bitset>
20#include <climits>
Dominik Laskowski2f01d772022-03-23 16:01:29 -070021#include <filesystem>
Chris Ye989bb932020-07-04 16:18:59 -070022#include <unordered_map>
Prabir Pradhan51894782022-08-23 16:29:10 +000023#include <utility>
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010024#include <vector>
25
Kim Low03ea0352020-11-06 12:45:07 -080026#include <batteryservice/BatteryService.h>
Dominik Laskowski2f01d772022-03-23 16:01:29 -070027#include <ftl/flags.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080028#include <input/Input.h>
29#include <input/InputDevice.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080030#include <input/KeyCharacterMap.h>
Prabir Pradhanda7c00c2019-08-29 14:12:42 -070031#include <input/KeyLayoutMap.h>
32#include <input/Keyboard.h>
Siarhei Vishniakou32f36ae2020-09-02 20:17:10 -070033#include <input/PropertyMap.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080034#include <input/VirtualKeyMap.h>
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000035#include <linux/input.h>
36#include <sys/epoll.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080037#include <utils/BitSet.h>
Prabir Pradhanda7c00c2019-08-29 14:12:42 -070038#include <utils/Errors.h>
Prabir Pradhanda7c00c2019-08-29 14:12:42 -070039#include <utils/List.h>
40#include <utils/Log.h>
41#include <utils/Mutex.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080042
Siarhei Vishniakou22c88462018-12-13 19:34:53 -080043#include "TouchVideoDevice.h"
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000044#include "VibrationElement.h"
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +000045#include "android/hardware/input/InputDeviceCountryCode.h"
Siarhei Vishniakou22c88462018-12-13 19:34:53 -080046
Prabir Pradhan952e65b2022-06-23 17:49:55 +000047struct inotify_event;
48
Michael Wrightd02c5b62014-02-10 15:10:22 -080049namespace android {
50
Chris Ye3fdbfef2021-01-06 18:45:18 -080051/* Number of colors : {red, green, blue} */
52static constexpr size_t COLOR_NUM = 3;
Michael Wrightd02c5b62014-02-10 15:10:22 -080053/*
54 * A raw event as retrieved from the EventHub.
55 */
56struct RawEvent {
Siarhei Vishniakou58ba3d12021-02-11 01:31:07 +000057 // Time when the event happened
Michael Wrightd02c5b62014-02-10 15:10:22 -080058 nsecs_t when;
Siarhei Vishniakou58ba3d12021-02-11 01:31:07 +000059 // Time when the event was read by EventHub. Only populated for input events.
60 // For other events (device added/removed/etc), this value is undefined and should not be read.
61 nsecs_t readTime;
Michael Wrightd02c5b62014-02-10 15:10:22 -080062 int32_t deviceId;
63 int32_t type;
64 int32_t code;
65 int32_t value;
66};
67
68/* Describes an absolute axis. */
69struct RawAbsoluteAxisInfo {
70 bool valid; // true if the information is valid, false otherwise
71
Prabir Pradhanda7c00c2019-08-29 14:12:42 -070072 int32_t minValue; // minimum value
73 int32_t maxValue; // maximum value
74 int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8
75 int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
Michael Wrightd02c5b62014-02-10 15:10:22 -080076 int32_t resolution; // resolution in units per mm or radians per mm
77
78 inline void clear() {
79 valid = false;
80 minValue = 0;
81 maxValue = 0;
82 flat = 0;
83 fuzz = 0;
84 resolution = 0;
85 }
86};
87
88/*
89 * Input device classes.
90 */
Chris Ye1b0c7342020-07-28 21:57:03 -070091enum class InputDeviceClass : uint32_t {
Michael Wrightd02c5b62014-02-10 15:10:22 -080092 /* The input device is a keyboard or has buttons. */
Chris Ye1b0c7342020-07-28 21:57:03 -070093 KEYBOARD = 0x00000001,
Michael Wrightd02c5b62014-02-10 15:10:22 -080094
95 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
Chris Ye1b0c7342020-07-28 21:57:03 -070096 ALPHAKEY = 0x00000002,
Michael Wrightd02c5b62014-02-10 15:10:22 -080097
98 /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
Chris Ye1b0c7342020-07-28 21:57:03 -070099 TOUCH = 0x00000004,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800100
101 /* The input device is a cursor device such as a trackball or mouse. */
Chris Ye1b0c7342020-07-28 21:57:03 -0700102 CURSOR = 0x00000008,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800103
104 /* The input device is a multi-touch touchscreen. */
Chris Ye1b0c7342020-07-28 21:57:03 -0700105 TOUCH_MT = 0x00000010,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800106
107 /* The input device is a directional pad (implies keyboard, has DPAD keys). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700108 DPAD = 0x00000020,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800109
110 /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700111 GAMEPAD = 0x00000040,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800112
113 /* The input device has switches. */
Chris Ye1b0c7342020-07-28 21:57:03 -0700114 SWITCH = 0x00000080,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800115
116 /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700117 JOYSTICK = 0x00000100,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800118
119 /* The input device has a vibrator (supports FF_RUMBLE). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700120 VIBRATOR = 0x00000200,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800121
Tim Kilbourn063ff532015-04-08 10:26:18 -0700122 /* The input device has a microphone. */
Chris Ye1b0c7342020-07-28 21:57:03 -0700123 MIC = 0x00000400,
Tim Kilbourn063ff532015-04-08 10:26:18 -0700124
Michael Wright842500e2015-03-13 17:32:02 -0700125 /* The input device is an external stylus (has data we want to fuse with touch data). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700126 EXTERNAL_STYLUS = 0x00000800,
Michael Wright842500e2015-03-13 17:32:02 -0700127
Prashant Malani1941ff52015-08-11 18:29:28 -0700128 /* The input device has a rotary encoder */
Chris Ye1b0c7342020-07-28 21:57:03 -0700129 ROTARY_ENCODER = 0x00001000,
Prashant Malani1941ff52015-08-11 18:29:28 -0700130
Chris Yef59a2f42020-10-16 12:55:26 -0700131 /* The input device has a sensor like accelerometer, gyro, etc */
132 SENSOR = 0x00002000,
133
Kim Low03ea0352020-11-06 12:45:07 -0800134 /* The input device has a battery */
135 BATTERY = 0x00004000,
136
Chris Ye3fdbfef2021-01-06 18:45:18 -0800137 /* The input device has sysfs controllable lights */
138 LIGHT = 0x00008000,
139
Michael Wrightd02c5b62014-02-10 15:10:22 -0800140 /* The input device is virtual (not a real device, not part of UI configuration). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700141 VIRTUAL = 0x40000000,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800142
143 /* The input device is external (not built-in). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700144 EXTERNAL = 0x80000000,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800145};
146
Chris Ye3fdbfef2021-01-06 18:45:18 -0800147enum class SysfsClass : uint32_t {
148 POWER_SUPPLY = 0,
149 LEDS = 1,
Dominik Laskowski75788452021-02-09 18:51:25 -0800150
151 ftl_last = LEDS
Chris Ye3fdbfef2021-01-06 18:45:18 -0800152};
153
154enum class LightColor : uint32_t {
155 RED = 0,
156 GREEN = 1,
157 BLUE = 2,
158};
159
160enum class InputLightClass : uint32_t {
161 /* The input light has brightness node. */
162 BRIGHTNESS = 0x00000001,
163 /* The input light has red name. */
164 RED = 0x00000002,
165 /* The input light has green name. */
166 GREEN = 0x00000004,
167 /* The input light has blue name. */
168 BLUE = 0x00000008,
169 /* The input light has global name. */
170 GLOBAL = 0x00000010,
171 /* The input light has multi index node. */
172 MULTI_INDEX = 0x00000020,
173 /* The input light has multi intensity node. */
174 MULTI_INTENSITY = 0x00000040,
175 /* The input light has max brightness node. */
176 MAX_BRIGHTNESS = 0x00000080,
Vaibhav Devmurari82b37d62022-09-12 13:36:48 +0000177 /* The input light has kbd_backlight name */
178 KEYBOARD_BACKLIGHT = 0x00000100,
Chris Ye3fdbfef2021-01-06 18:45:18 -0800179};
180
Chris Yee2b1e5c2021-03-10 22:45:12 -0800181enum class InputBatteryClass : uint32_t {
182 /* The input device battery has capacity node. */
183 CAPACITY = 0x00000001,
184 /* The input device battery has capacity_level node. */
185 CAPACITY_LEVEL = 0x00000002,
186 /* The input device battery has status node. */
187 STATUS = 0x00000004,
188};
189
Chris Ye3fdbfef2021-01-06 18:45:18 -0800190/* Describes a raw light. */
191struct RawLightInfo {
192 int32_t id;
193 std::string name;
194 std::optional<int32_t> maxBrightness;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700195 ftl::Flags<InputLightClass> flags;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800196 std::array<int32_t, COLOR_NUM> rgbIndex;
197 std::filesystem::path path;
Prabir Pradhanedeec3b2022-08-26 22:33:55 +0000198
199 bool operator==(const RawLightInfo&) const = default;
200 bool operator!=(const RawLightInfo&) const = default;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800201};
202
Chris Yee2b1e5c2021-03-10 22:45:12 -0800203/* Describes a raw battery. */
204struct RawBatteryInfo {
205 int32_t id;
206 std::string name;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700207 ftl::Flags<InputBatteryClass> flags;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800208 std::filesystem::path path;
Prabir Pradhanedeec3b2022-08-26 22:33:55 +0000209
210 bool operator==(const RawBatteryInfo&) const = default;
211 bool operator!=(const RawBatteryInfo&) const = default;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800212};
213
Michael Wrightd02c5b62014-02-10 15:10:22 -0800214/*
215 * Gets the class that owns an axis, in cases where multiple classes might claim
216 * the same axis for different purposes.
217 */
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700218extern ftl::Flags<InputDeviceClass> getAbsAxisUsage(int32_t axis,
219 ftl::Flags<InputDeviceClass> deviceClasses);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800220
221/*
222 * Grand Central Station for events.
223 *
224 * The event hub aggregates input events received across all known input
225 * devices on the system, including devices that may be emulated by the simulator
226 * environment. In addition, the event hub generates fake input events to indicate
227 * when devices are added or removed.
228 *
229 * The event hub provides a stream of input events (via the getEvent function).
230 * It also supports querying the current actual state of input devices such as identifying
231 * which keys are currently down. Finally, the event hub keeps track of the capabilities of
232 * individual input devices, such as their class and the set of key codes that they support.
233 */
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -0700234class EventHubInterface {
235public:
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700236 EventHubInterface() {}
237 virtual ~EventHubInterface() {}
Michael Wrightd02c5b62014-02-10 15:10:22 -0800238
Michael Wrightd02c5b62014-02-10 15:10:22 -0800239 // Synthetic raw event type codes produced when devices are added or removed.
240 enum {
241 // Sent when a device is added.
242 DEVICE_ADDED = 0x10000000,
243 // Sent when a device is removed.
244 DEVICE_REMOVED = 0x20000000,
245 // Sent when all added/removed devices from the most recent scan have been reported.
246 // This event is always sent at least once.
247 FINISHED_DEVICE_SCAN = 0x30000000,
248
249 FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
250 };
251
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700252 virtual ftl::Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800253
254 virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0;
255
256 virtual int32_t getDeviceControllerNumber(int32_t deviceId) const = 0;
257
258 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0;
259
260 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700261 RawAbsoluteAxisInfo* outAxisInfo) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800262
263 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0;
264
265 virtual bool hasInputProperty(int32_t deviceId, int property) const = 0;
266
Chris Yef59a2f42020-10-16 12:55:26 -0700267 virtual bool hasMscEvent(int32_t deviceId, int mscEvent) const = 0;
268
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700269 virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
270 int32_t metaState, int32_t* outKeycode, int32_t* outMetaState,
271 uint32_t* outFlags) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800272
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700273 virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800274
275 // Sets devices that are excluded from opening.
276 // This can be used to ignore input devices for sensors.
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100277 virtual void setExcludedDevices(const std::vector<std::string>& devices) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800278
279 /*
280 * Wait for events to become available and returns them.
281 * After returning, the EventHub holds onto a wake lock until the next call to getEvent.
282 * This ensures that the device will not go to sleep while the event is being processed.
283 * If the device needs to remain awake longer than that, then the caller is responsible
284 * for taking care of it (say, by poking the power manager user activity timer).
285 *
286 * The timeout is advisory only. If the device is asleep, it will not wake just to
287 * service the timeout.
288 *
289 * Returns the number of events obtained, or 0 if the timeout expired.
290 */
291 virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0;
Siarhei Vishniakouadd89292018-12-13 19:23:36 -0800292 virtual std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) = 0;
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000293 virtual base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(
294 int32_t deviceId, int32_t absCode) const = 0;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800295 // Raw batteries are sysfs power_supply nodes we found from the EventHub device sysfs node,
296 // containing the raw info of the sysfs node structure.
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000297 virtual std::vector<int32_t> getRawBatteryIds(int32_t deviceId) const = 0;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800298 virtual std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId,
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000299 int32_t BatteryId) const = 0;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800300
Chris Ye3fdbfef2021-01-06 18:45:18 -0800301 // Raw lights are sysfs led light nodes we found from the EventHub device sysfs node,
302 // containing the raw info of the sysfs node structure.
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000303 virtual std::vector<int32_t> getRawLightIds(int32_t deviceId) const = 0;
304 virtual std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId,
305 int32_t lightId) const = 0;
306 virtual std::optional<int32_t> getLightBrightness(int32_t deviceId, int32_t lightId) const = 0;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800307 virtual void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) = 0;
308 virtual std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000309 int32_t deviceId, int32_t lightId) const = 0;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800310 virtual void setLightIntensities(int32_t deviceId, int32_t lightId,
311 std::unordered_map<LightColor, int32_t> intensities) = 0;
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000312 /* Query Country code associated with the input device. */
313 virtual hardware::input::InputDeviceCountryCode getCountryCode(int32_t deviceId) const = 0;
314 /* Query current input state. */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800315 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0;
316 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0;
317 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0;
318 virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700319 int32_t* outValue) const = 0;
Philip Junker4af3b3d2021-12-14 10:36:55 +0100320 virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800321
322 /*
323 * Examine key input devices for specific framework keycode support
324 */
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700325 virtual bool markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700326 uint8_t* outFlags) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800327
328 virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
Arthur Hungcb40a002021-08-03 14:31:01 +0000329 virtual bool hasKeyCode(int32_t deviceId, int32_t keyCode) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800330
331 /* LED related functions expect Android LED constants, not scan codes or HID usages */
332 virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
333 virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0;
334
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700335 virtual void getVirtualKeyDefinitions(
336 int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800337
Chris Ye3a1e4462020-08-12 10:13:15 -0700338 virtual const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0;
339 virtual bool setKeyboardLayoutOverlay(int32_t deviceId,
340 std::shared_ptr<KeyCharacterMap> map) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800341
342 /* Control the vibrator. */
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000343 virtual void vibrate(int32_t deviceId, const VibrationElement& effect) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800344 virtual void cancelVibrate(int32_t deviceId) = 0;
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000345 virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800346
Kim Low03ea0352020-11-06 12:45:07 -0800347 /* Query battery level. */
Chris Yee2b1e5c2021-03-10 22:45:12 -0800348 virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId,
349 int32_t batteryId) const = 0;
Kim Low03ea0352020-11-06 12:45:07 -0800350
351 /* Query battery status. */
Chris Yee2b1e5c2021-03-10 22:45:12 -0800352 virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId, int32_t batteryId) const = 0;
Kim Low03ea0352020-11-06 12:45:07 -0800353
Michael Wrightd02c5b62014-02-10 15:10:22 -0800354 /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */
355 virtual void requestReopenDevices() = 0;
356
357 /* Wakes up getEvents() if it is blocked on a read. */
358 virtual void wake() = 0;
359
360 /* Dump EventHub state to a string. */
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000361 virtual void dump(std::string& dump) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800362
363 /* Called by the heatbeat to ensures that the reader has not deadlocked. */
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000364 virtual void monitor() const = 0;
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700365
366 /* Return true if the device is enabled. */
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000367 virtual bool isDeviceEnabled(int32_t deviceId) const = 0;
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700368
369 /* Enable an input device */
370 virtual status_t enableDevice(int32_t deviceId) = 0;
371
372 /* Disable an input device. Closes file descriptor to that device. */
373 virtual status_t disableDevice(int32_t deviceId) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800374};
375
Chris Ye66fbac32020-07-06 20:36:43 -0700376template <std::size_t BITS>
377class BitArray {
378 /* Array element type and vector of element type. */
379 using Element = std::uint32_t;
380 /* Number of bits in each BitArray element. */
381 static constexpr size_t WIDTH = sizeof(Element) * CHAR_BIT;
382 /* Number of elements to represent a bit array of the specified size of bits. */
383 static constexpr size_t COUNT = (BITS + WIDTH - 1) / WIDTH;
384
385public:
386 /* BUFFER type declaration for BitArray */
387 using Buffer = std::array<Element, COUNT>;
388 /* To tell if a bit is set in array, it selects an element from the array, and test
389 * if the relevant bit set.
390 * Note the parameter "bit" is an index to the bit, 0 <= bit < BITS.
391 */
392 inline bool test(size_t bit) const {
393 return (bit < BITS) ? mData[bit / WIDTH].test(bit % WIDTH) : false;
394 }
395 /* Returns total number of bytes needed for the array */
396 inline size_t bytes() { return (BITS + CHAR_BIT - 1) / CHAR_BIT; }
397 /* Returns true if array contains any non-zero bit from the range defined by start and end
398 * bit index [startIndex, endIndex).
399 */
400 bool any(size_t startIndex, size_t endIndex) {
401 if (startIndex >= endIndex || startIndex > BITS || endIndex > BITS + 1) {
402 ALOGE("Invalid start/end index. start = %zu, end = %zu, total bits = %zu", startIndex,
403 endIndex, BITS);
404 return false;
405 }
406 size_t se = startIndex / WIDTH; // Start of element
407 size_t ee = endIndex / WIDTH; // End of element
408 size_t si = startIndex % WIDTH; // Start index in start element
409 size_t ei = endIndex % WIDTH; // End index in end element
410 // Need to check first unaligned bitset for any non zero bit
411 if (si > 0) {
412 size_t nBits = se == ee ? ei - si : WIDTH - si;
413 // Generate the mask of interested bit range
414 Element mask = ((1 << nBits) - 1) << si;
415 if (mData[se++].to_ulong() & mask) {
416 return true;
417 }
418 }
419 // Check whole bitset for any bit set
420 for (; se < ee; se++) {
421 if (mData[se].any()) {
422 return true;
423 }
424 }
425 // Need to check last unaligned bitset for any non zero bit
426 if (ei > 0 && se <= ee) {
427 // Generate the mask of interested bit range
428 Element mask = (1 << ei) - 1;
429 if (mData[se].to_ulong() & mask) {
430 return true;
431 }
432 }
433 return false;
434 }
435 /* Load bit array values from buffer */
436 void loadFromBuffer(const Buffer& buffer) {
437 for (size_t i = 0; i < COUNT; i++) {
438 mData[i] = std::bitset<WIDTH>(buffer[i]);
439 }
440 }
441
442private:
443 std::array<std::bitset<WIDTH>, COUNT> mData;
444};
445
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700446class EventHub : public EventHubInterface {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800447public:
448 EventHub();
449
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700450 ftl::Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800451
Chris Ye989bb932020-07-04 16:18:59 -0700452 InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800453
Chris Ye989bb932020-07-04 16:18:59 -0700454 int32_t getDeviceControllerNumber(int32_t deviceId) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800455
Chris Ye989bb932020-07-04 16:18:59 -0700456 void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800457
Chris Ye989bb932020-07-04 16:18:59 -0700458 status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
459 RawAbsoluteAxisInfo* outAxisInfo) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800460
Chris Ye989bb932020-07-04 16:18:59 -0700461 bool hasRelativeAxis(int32_t deviceId, int axis) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800462
Chris Ye989bb932020-07-04 16:18:59 -0700463 bool hasInputProperty(int32_t deviceId, int property) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800464
Chris Yef59a2f42020-10-16 12:55:26 -0700465 bool hasMscEvent(int32_t deviceId, int mscEvent) const override final;
466
Chris Ye989bb932020-07-04 16:18:59 -0700467 status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t metaState,
468 int32_t* outKeycode, int32_t* outMetaState,
469 uint32_t* outFlags) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800470
Chris Ye989bb932020-07-04 16:18:59 -0700471 status_t mapAxis(int32_t deviceId, int32_t scanCode,
472 AxisInfo* outAxisInfo) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800473
Chris Yef59a2f42020-10-16 12:55:26 -0700474 base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000475 int32_t deviceId, int32_t absCode) const override final;
Chris Yef59a2f42020-10-16 12:55:26 -0700476
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000477 std::vector<int32_t> getRawBatteryIds(int32_t deviceId) const override final;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800478 std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId,
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000479 int32_t BatteryId) const override final;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800480
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000481 std::vector<int32_t> getRawLightIds(int32_t deviceId) const override final;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800482
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000483 std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId,
484 int32_t lightId) const override final;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800485
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000486 std::optional<int32_t> getLightBrightness(int32_t deviceId,
487 int32_t lightId) const override final;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800488 void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) override final;
489 std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000490 int32_t deviceId, int32_t lightId) const override final;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800491 void setLightIntensities(int32_t deviceId, int32_t lightId,
492 std::unordered_map<LightColor, int32_t> intensities) override final;
493
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000494 hardware::input::InputDeviceCountryCode getCountryCode(int32_t deviceId) const override final;
495
Chris Ye989bb932020-07-04 16:18:59 -0700496 void setExcludedDevices(const std::vector<std::string>& devices) override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800497
Chris Ye989bb932020-07-04 16:18:59 -0700498 int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override final;
499 int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override final;
500 int32_t getSwitchState(int32_t deviceId, int32_t sw) const override final;
Philip Junker4af3b3d2021-12-14 10:36:55 +0100501 int32_t getKeyCodeForKeyLocation(int32_t deviceId,
502 int32_t locationKeyCode) const override final;
Chris Ye989bb932020-07-04 16:18:59 -0700503 status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
504 int32_t* outValue) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800505
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700506 bool markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes,
Chris Ye989bb932020-07-04 16:18:59 -0700507 uint8_t* outFlags) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800508
Chris Ye989bb932020-07-04 16:18:59 -0700509 size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) override final;
510 std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800511
Chris Ye989bb932020-07-04 16:18:59 -0700512 bool hasScanCode(int32_t deviceId, int32_t scanCode) const override final;
Arthur Hungcb40a002021-08-03 14:31:01 +0000513 bool hasKeyCode(int32_t deviceId, int32_t keyCode) const override final;
Chris Ye989bb932020-07-04 16:18:59 -0700514 bool hasLed(int32_t deviceId, int32_t led) const override final;
515 void setLedState(int32_t deviceId, int32_t led, bool on) override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800516
Chris Ye989bb932020-07-04 16:18:59 -0700517 void getVirtualKeyDefinitions(
518 int32_t deviceId,
519 std::vector<VirtualKeyDefinition>& outVirtualKeys) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800520
Chris Ye3a1e4462020-08-12 10:13:15 -0700521 const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(
522 int32_t deviceId) const override final;
523 bool setKeyboardLayoutOverlay(int32_t deviceId,
524 std::shared_ptr<KeyCharacterMap> map) override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800525
Chris Ye989bb932020-07-04 16:18:59 -0700526 void vibrate(int32_t deviceId, const VibrationElement& effect) override final;
527 void cancelVibrate(int32_t deviceId) override final;
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000528 std::vector<int32_t> getVibratorIds(int32_t deviceId) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800529
Chris Ye989bb932020-07-04 16:18:59 -0700530 void requestReopenDevices() override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800531
Chris Ye989bb932020-07-04 16:18:59 -0700532 void wake() override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800533
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000534 void dump(std::string& dump) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800535
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000536 void monitor() const override final;
Chris Ye989bb932020-07-04 16:18:59 -0700537
Chris Yee2b1e5c2021-03-10 22:45:12 -0800538 std::optional<int32_t> getBatteryCapacity(int32_t deviceId,
539 int32_t batteryId) const override final;
Kim Low03ea0352020-11-06 12:45:07 -0800540
Chris Yee2b1e5c2021-03-10 22:45:12 -0800541 std::optional<int32_t> getBatteryStatus(int32_t deviceId,
542 int32_t batteryId) const override final;
Kim Low03ea0352020-11-06 12:45:07 -0800543
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000544 bool isDeviceEnabled(int32_t deviceId) const override final;
Chris Ye989bb932020-07-04 16:18:59 -0700545
546 status_t enableDevice(int32_t deviceId) override final;
547
548 status_t disableDevice(int32_t deviceId) override final;
549
550 ~EventHub() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800551
552private:
Prabir Pradhancb42b472022-08-23 16:01:19 +0000553 // Holds information about the sysfs device associated with the Device.
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700554 struct AssociatedDevice {
Chris Yee2b1e5c2021-03-10 22:45:12 -0800555 // The sysfs root path of the misc device.
556 std::filesystem::path sysfsRootPath;
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000557 hardware::input::InputDeviceCountryCode countryCode;
Prabir Pradhancb42b472022-08-23 16:01:19 +0000558 std::unordered_map<int32_t /*batteryId*/, RawBatteryInfo> batteryInfos;
559 std::unordered_map<int32_t /*lightId*/, RawLightInfo> lightInfos;
Prabir Pradhanedeec3b2022-08-26 22:33:55 +0000560
561 bool operator==(const AssociatedDevice&) const = default;
562 bool operator!=(const AssociatedDevice&) const = default;
563 std::string dump() const;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800564 };
565
Michael Wrightd02c5b62014-02-10 15:10:22 -0800566 struct Device {
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700567 int fd; // may be -1 if device is closed
Michael Wrightd02c5b62014-02-10 15:10:22 -0800568 const int32_t id;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100569 const std::string path;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800570 const InputDeviceIdentifier identifier;
571
Siarhei Vishniakouec7854a2018-12-14 16:52:34 -0800572 std::unique_ptr<TouchVideoDevice> videoDevice;
573
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700574 ftl::Flags<InputDeviceClass> classes;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800575
Chris Ye66fbac32020-07-06 20:36:43 -0700576 BitArray<KEY_MAX> keyBitmask;
577 BitArray<KEY_MAX> keyState;
578 BitArray<ABS_MAX> absBitmask;
579 BitArray<REL_MAX> relBitmask;
580 BitArray<SW_MAX> swBitmask;
581 BitArray<SW_MAX> swState;
582 BitArray<LED_MAX> ledBitmask;
583 BitArray<FF_MAX> ffBitmask;
584 BitArray<INPUT_PROP_MAX> propBitmask;
Chris Yef59a2f42020-10-16 12:55:26 -0700585 BitArray<MSC_MAX> mscBitmask;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800586
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100587 std::string configurationFile;
Siarhei Vishniakoud549b252020-08-11 11:25:26 -0500588 std::unique_ptr<PropertyMap> configuration;
Siarhei Vishniakou3e78dec2019-02-20 16:21:46 -0600589 std::unique_ptr<VirtualKeyMap> virtualKeyMap;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800590 KeyMap keyMap;
591
Michael Wrightd02c5b62014-02-10 15:10:22 -0800592 bool ffEffectPlaying;
593 int16_t ffEffectId; // initially -1
594
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700595 // A shared_ptr of a device associated with the input device.
Prabir Pradhan51894782022-08-23 16:29:10 +0000596 // The input devices that have the same sysfs path have the same associated device.
Prabir Pradhanedeec3b2022-08-26 22:33:55 +0000597 std::shared_ptr<const AssociatedDevice> associatedDevice;
Kim Low03ea0352020-11-06 12:45:07 -0800598
Michael Wrightd02c5b62014-02-10 15:10:22 -0800599 int32_t controllerNumber;
600
Prabir Pradhancb42b472022-08-23 16:01:19 +0000601 Device(int fd, int32_t id, std::string path, InputDeviceIdentifier identifier,
602 std::shared_ptr<const AssociatedDevice> assocDev);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800603 ~Device();
604
605 void close();
606
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700607 bool enabled; // initially true
608 status_t enable();
609 status_t disable();
Chris Ye989bb932020-07-04 16:18:59 -0700610 bool hasValidFd() const;
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700611 const bool isVirtual; // set if fd < 0 is passed to constructor
Michael Wrightd02c5b62014-02-10 15:10:22 -0800612
Chris Ye3a1e4462020-08-12 10:13:15 -0700613 const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const;
Chris Ye66fbac32020-07-06 20:36:43 -0700614
615 template <std::size_t N>
Chris Ye989bb932020-07-04 16:18:59 -0700616 status_t readDeviceBitMask(unsigned long ioctlCode, BitArray<N>& bitArray);
Chris Ye66fbac32020-07-06 20:36:43 -0700617
Chris Ye989bb932020-07-04 16:18:59 -0700618 void configureFd();
619 bool hasKeycodeLocked(int keycode) const;
620 void loadConfigurationLocked();
621 bool loadVirtualKeyMapLocked();
622 status_t loadKeyMapLocked();
623 bool isExternalDeviceLocked();
624 bool deviceHasMicLocked();
625 void setLedForControllerLocked();
626 status_t mapLed(int32_t led, int32_t* outScanCode) const;
627 void setLedStateLocked(int32_t led, bool on);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800628 };
629
Siarhei Vishniakoua4c502a2021-02-05 00:45:20 +0000630 /**
631 * Create a new device for the provided path.
632 */
Chris Yed3fef462021-03-07 17:10:08 -0800633 void openDeviceLocked(const std::string& devicePath) REQUIRES(mLock);
634 void openVideoDeviceLocked(const std::string& devicePath) REQUIRES(mLock);
Siarhei Vishniakouf49608d2020-08-20 19:18:21 -0500635 /**
636 * Try to associate a video device with an input device. If the association succeeds,
637 * the videoDevice is moved into the input device. 'videoDevice' will become null if this
638 * happens.
639 * Return true if the association succeeds.
640 * Return false otherwise.
641 */
Chris Yed3fef462021-03-07 17:10:08 -0800642 bool tryAddVideoDeviceLocked(Device& device, std::unique_ptr<TouchVideoDevice>& videoDevice)
643 REQUIRES(mLock);
644 void createVirtualKeyboardLocked() REQUIRES(mLock);
645 void addDeviceLocked(std::unique_ptr<Device> device) REQUIRES(mLock);
646 void assignDescriptorLocked(InputDeviceIdentifier& identifier) REQUIRES(mLock);
Prabir Pradhancb42b472022-08-23 16:01:19 +0000647 std::shared_ptr<const AssociatedDevice> obtainAssociatedDeviceLocked(
648 const std::filesystem::path& devicePath) const REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800649
Chris Yed3fef462021-03-07 17:10:08 -0800650 void closeDeviceByPathLocked(const std::string& devicePath) REQUIRES(mLock);
651 void closeVideoDeviceByPathLocked(const std::string& devicePath) REQUIRES(mLock);
652 void closeDeviceLocked(Device& device) REQUIRES(mLock);
653 void closeAllDevicesLocked() REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800654
Siarhei Vishniakou25920312018-12-12 15:24:44 -0800655 status_t registerFdForEpoll(int fd);
656 status_t unregisterFdFromEpoll(int fd);
Chris Yed3fef462021-03-07 17:10:08 -0800657 status_t registerDeviceForEpollLocked(Device& device) REQUIRES(mLock);
658 void registerVideoDeviceForEpollLocked(const TouchVideoDevice& videoDevice) REQUIRES(mLock);
659 status_t unregisterDeviceFromEpollLocked(Device& device) REQUIRES(mLock);
660 void unregisterVideoDeviceFromEpollLocked(const TouchVideoDevice& videoDevice) REQUIRES(mLock);
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700661
Chris Yed3fef462021-03-07 17:10:08 -0800662 status_t scanDirLocked(const std::string& dirname) REQUIRES(mLock);
663 status_t scanVideoDirLocked(const std::string& dirname) REQUIRES(mLock);
664 void scanDevicesLocked() REQUIRES(mLock);
Prabir Pradhan952e65b2022-06-23 17:49:55 +0000665 base::Result<void> readNotifyLocked() REQUIRES(mLock);
666 void handleNotifyEventLocked(const inotify_event&) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800667
Chris Yed3fef462021-03-07 17:10:08 -0800668 Device* getDeviceLocked(int32_t deviceId) const REQUIRES(mLock);
669 Device* getDeviceByPathLocked(const std::string& devicePath) const REQUIRES(mLock);
Siarhei Vishniakou12598682018-11-02 17:19:19 -0700670 /**
671 * Look through all available fd's (both for input devices and for video devices),
672 * and return the device pointer.
673 */
Chris Yed3fef462021-03-07 17:10:08 -0800674 Device* getDeviceByFdLocked(int fd) const REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800675
Chris Yed3fef462021-03-07 17:10:08 -0800676 int32_t getNextControllerNumberLocked(const std::string& name) REQUIRES(mLock);
Josh Bartel938632f2022-07-19 15:34:22 -0500677
678 bool hasDeviceWithDescriptorLocked(const std::string& descriptor) const REQUIRES(mLock);
679
Chris Yed3fef462021-03-07 17:10:08 -0800680 void releaseControllerNumberLocked(int32_t num) REQUIRES(mLock);
681 void reportDeviceAddedForStatisticsLocked(const InputDeviceIdentifier& identifier,
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700682 ftl::Flags<InputDeviceClass> classes) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800683
Chris Yee2b1e5c2021-03-10 22:45:12 -0800684 const std::unordered_map<int32_t, RawBatteryInfo>& getBatteryInfoLocked(int32_t deviceId) const
685 REQUIRES(mLock);
686
687 const std::unordered_map<int32_t, RawLightInfo>& getLightInfoLocked(int32_t deviceId) const
688 REQUIRES(mLock);
689
Usama Arifb27c8e62021-06-03 16:44:09 +0100690 void addDeviceInputInotify();
691 void addDeviceInotify();
692
Michael Wrightd02c5b62014-02-10 15:10:22 -0800693 // Protect all internal state.
Chris Ye1c2e0892020-11-30 21:41:44 -0800694 mutable std::mutex mLock;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800695
696 // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none.
697 // EventHub remaps the built-in keyboard to id 0 externally as required by the API.
698 enum {
699 // Must not conflict with any other assigned device ids, including
700 // the virtual keyboard id (-1).
701 NO_BUILT_IN_KEYBOARD = -2,
702 };
703 int32_t mBuiltInKeyboardId;
704
705 int32_t mNextDeviceId;
706
707 BitSet32 mControllerNumbers;
708
Chris Ye989bb932020-07-04 16:18:59 -0700709 std::unordered_map<int32_t, std::unique_ptr<Device>> mDevices;
Siarhei Vishniakou22c88462018-12-13 19:34:53 -0800710 /**
711 * Video devices that report touchscreen heatmap, but have not (yet) been paired
712 * with a specific input device. Video device discovery is independent from input device
713 * discovery, so the two types of devices could be found in any order.
714 * Ideally, video devices in this queue do not have an open fd, or at least aren't
715 * actively streaming.
716 */
717 std::vector<std::unique_ptr<TouchVideoDevice>> mUnattachedVideoDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800718
Chris Ye989bb932020-07-04 16:18:59 -0700719 std::vector<std::unique_ptr<Device>> mOpeningDevices;
720 std::vector<std::unique_ptr<Device>> mClosingDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800721
722 bool mNeedToSendFinishedDeviceScan;
723 bool mNeedToReopenDevices;
724 bool mNeedToScanDevices;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100725 std::vector<std::string> mExcludedDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800726
727 int mEpollFd;
728 int mINotifyFd;
729 int mWakeReadPipeFd;
730 int mWakeWritePipeFd;
731
Usama Arifb27c8e62021-06-03 16:44:09 +0100732 int mDeviceInputWd;
733 int mDeviceWd = -1;
Siarhei Vishniakou951f3622018-12-12 19:45:42 -0800734
Michael Wrightd02c5b62014-02-10 15:10:22 -0800735 // Maximum number of signalled FDs to handle at a time.
736 static const int EPOLL_MAX_EVENTS = 16;
737
738 // The array of pending epoll events and the index of the next event to be handled.
739 struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS];
740 size_t mPendingEventCount;
741 size_t mPendingEventIndex;
742 bool mPendingINotify;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800743};
744
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700745} // namespace android