blob: dfb98f14c563716f6bb3e41a8348661a09c0131d [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
Michael Wrightd02c5b62014-02-10 15:10:22 -080017#ifndef _RUNTIME_EVENT_HUB_H
18#define _RUNTIME_EVENT_HUB_H
19
Chris Ye66fbac32020-07-06 20:36:43 -070020#include <bitset>
21#include <climits>
Dominik Laskowski2f01d772022-03-23 16:01:29 -070022#include <filesystem>
Chris Ye989bb932020-07-04 16:18:59 -070023#include <unordered_map>
Prabir Pradhan51894782022-08-23 16:29:10 +000024#include <utility>
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +010025#include <vector>
26
Kim Low03ea0352020-11-06 12:45:07 -080027#include <batteryservice/BatteryService.h>
Dominik Laskowski2f01d772022-03-23 16:01:29 -070028#include <ftl/flags.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080029#include <input/Input.h>
30#include <input/InputDevice.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080031#include <input/KeyCharacterMap.h>
Prabir Pradhanda7c00c2019-08-29 14:12:42 -070032#include <input/KeyLayoutMap.h>
33#include <input/Keyboard.h>
Siarhei Vishniakou32f36ae2020-09-02 20:17:10 -070034#include <input/PropertyMap.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080035#include <input/VirtualKeyMap.h>
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000036#include <linux/input.h>
37#include <sys/epoll.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080038#include <utils/BitSet.h>
Prabir Pradhanda7c00c2019-08-29 14:12:42 -070039#include <utils/Errors.h>
Prabir Pradhanda7c00c2019-08-29 14:12:42 -070040#include <utils/List.h>
41#include <utils/Log.h>
42#include <utils/Mutex.h>
Michael Wrightd02c5b62014-02-10 15:10:22 -080043
Siarhei Vishniakou22c88462018-12-13 19:34:53 -080044#include "TouchVideoDevice.h"
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +000045#include "VibrationElement.h"
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +000046#include "android/hardware/input/InputDeviceCountryCode.h"
Siarhei Vishniakou22c88462018-12-13 19:34:53 -080047
Prabir Pradhan952e65b2022-06-23 17:49:55 +000048struct inotify_event;
49
Michael Wrightd02c5b62014-02-10 15:10:22 -080050namespace android {
51
Chris Ye3fdbfef2021-01-06 18:45:18 -080052/* Number of colors : {red, green, blue} */
53static constexpr size_t COLOR_NUM = 3;
Michael Wrightd02c5b62014-02-10 15:10:22 -080054/*
55 * A raw event as retrieved from the EventHub.
56 */
57struct RawEvent {
Siarhei Vishniakou58ba3d12021-02-11 01:31:07 +000058 // Time when the event happened
Michael Wrightd02c5b62014-02-10 15:10:22 -080059 nsecs_t when;
Siarhei Vishniakou58ba3d12021-02-11 01:31:07 +000060 // Time when the event was read by EventHub. Only populated for input events.
61 // For other events (device added/removed/etc), this value is undefined and should not be read.
62 nsecs_t readTime;
Michael Wrightd02c5b62014-02-10 15:10:22 -080063 int32_t deviceId;
64 int32_t type;
65 int32_t code;
66 int32_t value;
67};
68
69/* Describes an absolute axis. */
70struct RawAbsoluteAxisInfo {
71 bool valid; // true if the information is valid, false otherwise
72
Prabir Pradhanda7c00c2019-08-29 14:12:42 -070073 int32_t minValue; // minimum value
74 int32_t maxValue; // maximum value
75 int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8
76 int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
Michael Wrightd02c5b62014-02-10 15:10:22 -080077 int32_t resolution; // resolution in units per mm or radians per mm
78
79 inline void clear() {
80 valid = false;
81 minValue = 0;
82 maxValue = 0;
83 flat = 0;
84 fuzz = 0;
85 resolution = 0;
86 }
87};
88
89/*
90 * Input device classes.
91 */
Chris Ye1b0c7342020-07-28 21:57:03 -070092enum class InputDeviceClass : uint32_t {
Michael Wrightd02c5b62014-02-10 15:10:22 -080093 /* The input device is a keyboard or has buttons. */
Chris Ye1b0c7342020-07-28 21:57:03 -070094 KEYBOARD = 0x00000001,
Michael Wrightd02c5b62014-02-10 15:10:22 -080095
96 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
Chris Ye1b0c7342020-07-28 21:57:03 -070097 ALPHAKEY = 0x00000002,
Michael Wrightd02c5b62014-02-10 15:10:22 -080098
99 /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700100 TOUCH = 0x00000004,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800101
102 /* The input device is a cursor device such as a trackball or mouse. */
Chris Ye1b0c7342020-07-28 21:57:03 -0700103 CURSOR = 0x00000008,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800104
105 /* The input device is a multi-touch touchscreen. */
Chris Ye1b0c7342020-07-28 21:57:03 -0700106 TOUCH_MT = 0x00000010,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800107
108 /* The input device is a directional pad (implies keyboard, has DPAD keys). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700109 DPAD = 0x00000020,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800110
111 /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700112 GAMEPAD = 0x00000040,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800113
114 /* The input device has switches. */
Chris Ye1b0c7342020-07-28 21:57:03 -0700115 SWITCH = 0x00000080,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800116
117 /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700118 JOYSTICK = 0x00000100,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800119
120 /* The input device has a vibrator (supports FF_RUMBLE). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700121 VIBRATOR = 0x00000200,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800122
Tim Kilbourn063ff532015-04-08 10:26:18 -0700123 /* The input device has a microphone. */
Chris Ye1b0c7342020-07-28 21:57:03 -0700124 MIC = 0x00000400,
Tim Kilbourn063ff532015-04-08 10:26:18 -0700125
Michael Wright842500e2015-03-13 17:32:02 -0700126 /* The input device is an external stylus (has data we want to fuse with touch data). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700127 EXTERNAL_STYLUS = 0x00000800,
Michael Wright842500e2015-03-13 17:32:02 -0700128
Prashant Malani1941ff52015-08-11 18:29:28 -0700129 /* The input device has a rotary encoder */
Chris Ye1b0c7342020-07-28 21:57:03 -0700130 ROTARY_ENCODER = 0x00001000,
Prashant Malani1941ff52015-08-11 18:29:28 -0700131
Chris Yef59a2f42020-10-16 12:55:26 -0700132 /* The input device has a sensor like accelerometer, gyro, etc */
133 SENSOR = 0x00002000,
134
Kim Low03ea0352020-11-06 12:45:07 -0800135 /* The input device has a battery */
136 BATTERY = 0x00004000,
137
Chris Ye3fdbfef2021-01-06 18:45:18 -0800138 /* The input device has sysfs controllable lights */
139 LIGHT = 0x00008000,
140
Michael Wrightd02c5b62014-02-10 15:10:22 -0800141 /* The input device is virtual (not a real device, not part of UI configuration). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700142 VIRTUAL = 0x40000000,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800143
144 /* The input device is external (not built-in). */
Chris Ye1b0c7342020-07-28 21:57:03 -0700145 EXTERNAL = 0x80000000,
Michael Wrightd02c5b62014-02-10 15:10:22 -0800146};
147
Chris Ye3fdbfef2021-01-06 18:45:18 -0800148enum class SysfsClass : uint32_t {
149 POWER_SUPPLY = 0,
150 LEDS = 1,
Dominik Laskowski75788452021-02-09 18:51:25 -0800151
152 ftl_last = LEDS
Chris Ye3fdbfef2021-01-06 18:45:18 -0800153};
154
155enum class LightColor : uint32_t {
156 RED = 0,
157 GREEN = 1,
158 BLUE = 2,
159};
160
161enum 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,
178};
179
Chris Yee2b1e5c2021-03-10 22:45:12 -0800180enum class InputBatteryClass : uint32_t {
181 /* The input device battery has capacity node. */
182 CAPACITY = 0x00000001,
183 /* The input device battery has capacity_level node. */
184 CAPACITY_LEVEL = 0x00000002,
185 /* The input device battery has status node. */
186 STATUS = 0x00000004,
187};
188
Chris Ye3fdbfef2021-01-06 18:45:18 -0800189/* Describes a raw light. */
190struct RawLightInfo {
191 int32_t id;
192 std::string name;
193 std::optional<int32_t> maxBrightness;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700194 ftl::Flags<InputLightClass> flags;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800195 std::array<int32_t, COLOR_NUM> rgbIndex;
196 std::filesystem::path path;
197};
198
Chris Yee2b1e5c2021-03-10 22:45:12 -0800199/* Describes a raw battery. */
200struct RawBatteryInfo {
201 int32_t id;
202 std::string name;
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700203 ftl::Flags<InputBatteryClass> flags;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800204 std::filesystem::path path;
205};
206
Michael Wrightd02c5b62014-02-10 15:10:22 -0800207/*
208 * Gets the class that owns an axis, in cases where multiple classes might claim
209 * the same axis for different purposes.
210 */
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700211extern ftl::Flags<InputDeviceClass> getAbsAxisUsage(int32_t axis,
212 ftl::Flags<InputDeviceClass> deviceClasses);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800213
214/*
215 * Grand Central Station for events.
216 *
217 * The event hub aggregates input events received across all known input
218 * devices on the system, including devices that may be emulated by the simulator
219 * environment. In addition, the event hub generates fake input events to indicate
220 * when devices are added or removed.
221 *
222 * The event hub provides a stream of input events (via the getEvent function).
223 * It also supports querying the current actual state of input devices such as identifying
224 * which keys are currently down. Finally, the event hub keeps track of the capabilities of
225 * individual input devices, such as their class and the set of key codes that they support.
226 */
Siarhei Vishniakou3bc7e092019-07-24 17:43:30 -0700227class EventHubInterface {
228public:
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700229 EventHubInterface() {}
230 virtual ~EventHubInterface() {}
Michael Wrightd02c5b62014-02-10 15:10:22 -0800231
Michael Wrightd02c5b62014-02-10 15:10:22 -0800232 // Synthetic raw event type codes produced when devices are added or removed.
233 enum {
234 // Sent when a device is added.
235 DEVICE_ADDED = 0x10000000,
236 // Sent when a device is removed.
237 DEVICE_REMOVED = 0x20000000,
238 // Sent when all added/removed devices from the most recent scan have been reported.
239 // This event is always sent at least once.
240 FINISHED_DEVICE_SCAN = 0x30000000,
241
242 FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
243 };
244
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700245 virtual ftl::Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800246
247 virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0;
248
249 virtual int32_t getDeviceControllerNumber(int32_t deviceId) const = 0;
250
251 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0;
252
253 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700254 RawAbsoluteAxisInfo* outAxisInfo) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800255
256 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0;
257
258 virtual bool hasInputProperty(int32_t deviceId, int property) const = 0;
259
Chris Yef59a2f42020-10-16 12:55:26 -0700260 virtual bool hasMscEvent(int32_t deviceId, int mscEvent) const = 0;
261
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700262 virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
263 int32_t metaState, int32_t* outKeycode, int32_t* outMetaState,
264 uint32_t* outFlags) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800265
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700266 virtual status_t mapAxis(int32_t deviceId, int32_t scanCode, AxisInfo* outAxisInfo) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800267
268 // Sets devices that are excluded from opening.
269 // This can be used to ignore input devices for sensors.
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100270 virtual void setExcludedDevices(const std::vector<std::string>& devices) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800271
272 /*
273 * Wait for events to become available and returns them.
274 * After returning, the EventHub holds onto a wake lock until the next call to getEvent.
275 * This ensures that the device will not go to sleep while the event is being processed.
276 * If the device needs to remain awake longer than that, then the caller is responsible
277 * for taking care of it (say, by poking the power manager user activity timer).
278 *
279 * The timeout is advisory only. If the device is asleep, it will not wake just to
280 * service the timeout.
281 *
282 * Returns the number of events obtained, or 0 if the timeout expired.
283 */
284 virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0;
Siarhei Vishniakouadd89292018-12-13 19:23:36 -0800285 virtual std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) = 0;
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000286 virtual base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(
287 int32_t deviceId, int32_t absCode) const = 0;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800288 // Raw batteries are sysfs power_supply nodes we found from the EventHub device sysfs node,
289 // containing the raw info of the sysfs node structure.
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000290 virtual std::vector<int32_t> getRawBatteryIds(int32_t deviceId) const = 0;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800291 virtual std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId,
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000292 int32_t BatteryId) const = 0;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800293
Chris Ye3fdbfef2021-01-06 18:45:18 -0800294 // Raw lights are sysfs led light nodes we found from the EventHub device sysfs node,
295 // containing the raw info of the sysfs node structure.
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000296 virtual std::vector<int32_t> getRawLightIds(int32_t deviceId) const = 0;
297 virtual std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId,
298 int32_t lightId) const = 0;
299 virtual std::optional<int32_t> getLightBrightness(int32_t deviceId, int32_t lightId) const = 0;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800300 virtual void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) = 0;
301 virtual std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000302 int32_t deviceId, int32_t lightId) const = 0;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800303 virtual void setLightIntensities(int32_t deviceId, int32_t lightId,
304 std::unordered_map<LightColor, int32_t> intensities) = 0;
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000305 /* Query Country code associated with the input device. */
306 virtual hardware::input::InputDeviceCountryCode getCountryCode(int32_t deviceId) const = 0;
307 /* Query current input state. */
Michael Wrightd02c5b62014-02-10 15:10:22 -0800308 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0;
309 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0;
310 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0;
311 virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700312 int32_t* outValue) const = 0;
Philip Junker4af3b3d2021-12-14 10:36:55 +0100313 virtual int32_t getKeyCodeForKeyLocation(int32_t deviceId, int32_t locationKeyCode) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800314
315 /*
316 * Examine key input devices for specific framework keycode support
317 */
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700318 virtual bool markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes,
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700319 uint8_t* outFlags) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800320
321 virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
Arthur Hungcb40a002021-08-03 14:31:01 +0000322 virtual bool hasKeyCode(int32_t deviceId, int32_t keyCode) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800323
324 /* LED related functions expect Android LED constants, not scan codes or HID usages */
325 virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
326 virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0;
327
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700328 virtual void getVirtualKeyDefinitions(
329 int32_t deviceId, std::vector<VirtualKeyDefinition>& outVirtualKeys) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800330
Chris Ye3a1e4462020-08-12 10:13:15 -0700331 virtual const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0;
332 virtual bool setKeyboardLayoutOverlay(int32_t deviceId,
333 std::shared_ptr<KeyCharacterMap> map) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800334
335 /* Control the vibrator. */
Nathaniel R. Lewiscacd69a2019-08-12 22:07:00 +0000336 virtual void vibrate(int32_t deviceId, const VibrationElement& effect) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800337 virtual void cancelVibrate(int32_t deviceId) = 0;
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000338 virtual std::vector<int32_t> getVibratorIds(int32_t deviceId) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800339
Kim Low03ea0352020-11-06 12:45:07 -0800340 /* Query battery level. */
Chris Yee2b1e5c2021-03-10 22:45:12 -0800341 virtual std::optional<int32_t> getBatteryCapacity(int32_t deviceId,
342 int32_t batteryId) const = 0;
Kim Low03ea0352020-11-06 12:45:07 -0800343
344 /* Query battery status. */
Chris Yee2b1e5c2021-03-10 22:45:12 -0800345 virtual std::optional<int32_t> getBatteryStatus(int32_t deviceId, int32_t batteryId) const = 0;
Kim Low03ea0352020-11-06 12:45:07 -0800346
Michael Wrightd02c5b62014-02-10 15:10:22 -0800347 /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */
348 virtual void requestReopenDevices() = 0;
349
350 /* Wakes up getEvents() if it is blocked on a read. */
351 virtual void wake() = 0;
352
353 /* Dump EventHub state to a string. */
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000354 virtual void dump(std::string& dump) const = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800355
356 /* Called by the heatbeat to ensures that the reader has not deadlocked. */
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000357 virtual void monitor() const = 0;
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700358
359 /* Return true if the device is enabled. */
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000360 virtual bool isDeviceEnabled(int32_t deviceId) const = 0;
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700361
362 /* Enable an input device */
363 virtual status_t enableDevice(int32_t deviceId) = 0;
364
365 /* Disable an input device. Closes file descriptor to that device. */
366 virtual status_t disableDevice(int32_t deviceId) = 0;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800367};
368
Chris Ye66fbac32020-07-06 20:36:43 -0700369template <std::size_t BITS>
370class BitArray {
371 /* Array element type and vector of element type. */
372 using Element = std::uint32_t;
373 /* Number of bits in each BitArray element. */
374 static constexpr size_t WIDTH = sizeof(Element) * CHAR_BIT;
375 /* Number of elements to represent a bit array of the specified size of bits. */
376 static constexpr size_t COUNT = (BITS + WIDTH - 1) / WIDTH;
377
378public:
379 /* BUFFER type declaration for BitArray */
380 using Buffer = std::array<Element, COUNT>;
381 /* To tell if a bit is set in array, it selects an element from the array, and test
382 * if the relevant bit set.
383 * Note the parameter "bit" is an index to the bit, 0 <= bit < BITS.
384 */
385 inline bool test(size_t bit) const {
386 return (bit < BITS) ? mData[bit / WIDTH].test(bit % WIDTH) : false;
387 }
388 /* Returns total number of bytes needed for the array */
389 inline size_t bytes() { return (BITS + CHAR_BIT - 1) / CHAR_BIT; }
390 /* Returns true if array contains any non-zero bit from the range defined by start and end
391 * bit index [startIndex, endIndex).
392 */
393 bool any(size_t startIndex, size_t endIndex) {
394 if (startIndex >= endIndex || startIndex > BITS || endIndex > BITS + 1) {
395 ALOGE("Invalid start/end index. start = %zu, end = %zu, total bits = %zu", startIndex,
396 endIndex, BITS);
397 return false;
398 }
399 size_t se = startIndex / WIDTH; // Start of element
400 size_t ee = endIndex / WIDTH; // End of element
401 size_t si = startIndex % WIDTH; // Start index in start element
402 size_t ei = endIndex % WIDTH; // End index in end element
403 // Need to check first unaligned bitset for any non zero bit
404 if (si > 0) {
405 size_t nBits = se == ee ? ei - si : WIDTH - si;
406 // Generate the mask of interested bit range
407 Element mask = ((1 << nBits) - 1) << si;
408 if (mData[se++].to_ulong() & mask) {
409 return true;
410 }
411 }
412 // Check whole bitset for any bit set
413 for (; se < ee; se++) {
414 if (mData[se].any()) {
415 return true;
416 }
417 }
418 // Need to check last unaligned bitset for any non zero bit
419 if (ei > 0 && se <= ee) {
420 // Generate the mask of interested bit range
421 Element mask = (1 << ei) - 1;
422 if (mData[se].to_ulong() & mask) {
423 return true;
424 }
425 }
426 return false;
427 }
428 /* Load bit array values from buffer */
429 void loadFromBuffer(const Buffer& buffer) {
430 for (size_t i = 0; i < COUNT; i++) {
431 mData[i] = std::bitset<WIDTH>(buffer[i]);
432 }
433 }
434
435private:
436 std::array<std::bitset<WIDTH>, COUNT> mData;
437};
438
Prabir Pradhanda7c00c2019-08-29 14:12:42 -0700439class EventHub : public EventHubInterface {
Michael Wrightd02c5b62014-02-10 15:10:22 -0800440public:
441 EventHub();
442
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700443 ftl::Flags<InputDeviceClass> getDeviceClasses(int32_t deviceId) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800444
Chris Ye989bb932020-07-04 16:18:59 -0700445 InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800446
Chris Ye989bb932020-07-04 16:18:59 -0700447 int32_t getDeviceControllerNumber(int32_t deviceId) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800448
Chris Ye989bb932020-07-04 16:18:59 -0700449 void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800450
Chris Ye989bb932020-07-04 16:18:59 -0700451 status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
452 RawAbsoluteAxisInfo* outAxisInfo) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800453
Chris Ye989bb932020-07-04 16:18:59 -0700454 bool hasRelativeAxis(int32_t deviceId, int axis) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800455
Chris Ye989bb932020-07-04 16:18:59 -0700456 bool hasInputProperty(int32_t deviceId, int property) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800457
Chris Yef59a2f42020-10-16 12:55:26 -0700458 bool hasMscEvent(int32_t deviceId, int mscEvent) const override final;
459
Chris Ye989bb932020-07-04 16:18:59 -0700460 status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode, int32_t metaState,
461 int32_t* outKeycode, int32_t* outMetaState,
462 uint32_t* outFlags) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800463
Chris Ye989bb932020-07-04 16:18:59 -0700464 status_t mapAxis(int32_t deviceId, int32_t scanCode,
465 AxisInfo* outAxisInfo) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800466
Chris Yef59a2f42020-10-16 12:55:26 -0700467 base::Result<std::pair<InputDeviceSensorType, int32_t>> mapSensor(
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000468 int32_t deviceId, int32_t absCode) const override final;
Chris Yef59a2f42020-10-16 12:55:26 -0700469
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000470 std::vector<int32_t> getRawBatteryIds(int32_t deviceId) const override final;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800471 std::optional<RawBatteryInfo> getRawBatteryInfo(int32_t deviceId,
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000472 int32_t BatteryId) const override final;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800473
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000474 std::vector<int32_t> getRawLightIds(int32_t deviceId) const override final;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800475
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000476 std::optional<RawLightInfo> getRawLightInfo(int32_t deviceId,
477 int32_t lightId) const override final;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800478
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000479 std::optional<int32_t> getLightBrightness(int32_t deviceId,
480 int32_t lightId) const override final;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800481 void setLightBrightness(int32_t deviceId, int32_t lightId, int32_t brightness) override final;
482 std::optional<std::unordered_map<LightColor, int32_t>> getLightIntensities(
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000483 int32_t deviceId, int32_t lightId) const override final;
Chris Ye3fdbfef2021-01-06 18:45:18 -0800484 void setLightIntensities(int32_t deviceId, int32_t lightId,
485 std::unordered_map<LightColor, int32_t> intensities) override final;
486
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000487 hardware::input::InputDeviceCountryCode getCountryCode(int32_t deviceId) const override final;
488
Chris Ye989bb932020-07-04 16:18:59 -0700489 void setExcludedDevices(const std::vector<std::string>& devices) override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800490
Chris Ye989bb932020-07-04 16:18:59 -0700491 int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const override final;
492 int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const override final;
493 int32_t getSwitchState(int32_t deviceId, int32_t sw) const override final;
Philip Junker4af3b3d2021-12-14 10:36:55 +0100494 int32_t getKeyCodeForKeyLocation(int32_t deviceId,
495 int32_t locationKeyCode) const override final;
Chris Ye989bb932020-07-04 16:18:59 -0700496 status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
497 int32_t* outValue) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800498
Siarhei Vishniakou74007942022-06-13 13:57:47 -0700499 bool markSupportedKeyCodes(int32_t deviceId, const std::vector<int32_t>& keyCodes,
Chris Ye989bb932020-07-04 16:18:59 -0700500 uint8_t* outFlags) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800501
Chris Ye989bb932020-07-04 16:18:59 -0700502 size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) override final;
503 std::vector<TouchVideoFrame> getVideoFrames(int32_t deviceId) override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800504
Chris Ye989bb932020-07-04 16:18:59 -0700505 bool hasScanCode(int32_t deviceId, int32_t scanCode) const override final;
Arthur Hungcb40a002021-08-03 14:31:01 +0000506 bool hasKeyCode(int32_t deviceId, int32_t keyCode) const override final;
Chris Ye989bb932020-07-04 16:18:59 -0700507 bool hasLed(int32_t deviceId, int32_t led) const override final;
508 void setLedState(int32_t deviceId, int32_t led, bool on) override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800509
Chris Ye989bb932020-07-04 16:18:59 -0700510 void getVirtualKeyDefinitions(
511 int32_t deviceId,
512 std::vector<VirtualKeyDefinition>& outVirtualKeys) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800513
Chris Ye3a1e4462020-08-12 10:13:15 -0700514 const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap(
515 int32_t deviceId) const override final;
516 bool setKeyboardLayoutOverlay(int32_t deviceId,
517 std::shared_ptr<KeyCharacterMap> map) override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800518
Chris Ye989bb932020-07-04 16:18:59 -0700519 void vibrate(int32_t deviceId, const VibrationElement& effect) override final;
520 void cancelVibrate(int32_t deviceId) override final;
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000521 std::vector<int32_t> getVibratorIds(int32_t deviceId) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800522
Chris Ye989bb932020-07-04 16:18:59 -0700523 void requestReopenDevices() override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800524
Chris Ye989bb932020-07-04 16:18:59 -0700525 void wake() override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800526
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000527 void dump(std::string& dump) const override final;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800528
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000529 void monitor() const override final;
Chris Ye989bb932020-07-04 16:18:59 -0700530
Chris Yee2b1e5c2021-03-10 22:45:12 -0800531 std::optional<int32_t> getBatteryCapacity(int32_t deviceId,
532 int32_t batteryId) const override final;
Kim Low03ea0352020-11-06 12:45:07 -0800533
Chris Yee2b1e5c2021-03-10 22:45:12 -0800534 std::optional<int32_t> getBatteryStatus(int32_t deviceId,
535 int32_t batteryId) const override final;
Kim Low03ea0352020-11-06 12:45:07 -0800536
Prabir Pradhanae4ff282022-08-23 16:21:39 +0000537 bool isDeviceEnabled(int32_t deviceId) const override final;
Chris Ye989bb932020-07-04 16:18:59 -0700538
539 status_t enableDevice(int32_t deviceId) override final;
540
541 status_t disableDevice(int32_t deviceId) override final;
542
543 ~EventHub() override;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800544
545private:
Prabir Pradhancb42b472022-08-23 16:01:19 +0000546 // Holds information about the sysfs device associated with the Device.
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700547 struct AssociatedDevice {
Chris Yee2b1e5c2021-03-10 22:45:12 -0800548 // The sysfs root path of the misc device.
549 std::filesystem::path sysfsRootPath;
Vaibhav Devmuraridd82b8e2022-08-16 15:34:01 +0000550 hardware::input::InputDeviceCountryCode countryCode;
Prabir Pradhancb42b472022-08-23 16:01:19 +0000551 std::unordered_map<int32_t /*batteryId*/, RawBatteryInfo> batteryInfos;
552 std::unordered_map<int32_t /*lightId*/, RawLightInfo> lightInfos;
Chris Yee2b1e5c2021-03-10 22:45:12 -0800553 };
554
Michael Wrightd02c5b62014-02-10 15:10:22 -0800555 struct Device {
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700556 int fd; // may be -1 if device is closed
Michael Wrightd02c5b62014-02-10 15:10:22 -0800557 const int32_t id;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100558 const std::string path;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800559 const InputDeviceIdentifier identifier;
560
Siarhei Vishniakouec7854a2018-12-14 16:52:34 -0800561 std::unique_ptr<TouchVideoDevice> videoDevice;
562
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700563 ftl::Flags<InputDeviceClass> classes;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800564
Chris Ye66fbac32020-07-06 20:36:43 -0700565 BitArray<KEY_MAX> keyBitmask;
566 BitArray<KEY_MAX> keyState;
567 BitArray<ABS_MAX> absBitmask;
568 BitArray<REL_MAX> relBitmask;
569 BitArray<SW_MAX> swBitmask;
570 BitArray<SW_MAX> swState;
571 BitArray<LED_MAX> ledBitmask;
572 BitArray<FF_MAX> ffBitmask;
573 BitArray<INPUT_PROP_MAX> propBitmask;
Chris Yef59a2f42020-10-16 12:55:26 -0700574 BitArray<MSC_MAX> mscBitmask;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800575
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100576 std::string configurationFile;
Siarhei Vishniakoud549b252020-08-11 11:25:26 -0500577 std::unique_ptr<PropertyMap> configuration;
Siarhei Vishniakou3e78dec2019-02-20 16:21:46 -0600578 std::unique_ptr<VirtualKeyMap> virtualKeyMap;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800579 KeyMap keyMap;
580
Michael Wrightd02c5b62014-02-10 15:10:22 -0800581 bool ffEffectPlaying;
582 int16_t ffEffectId; // initially -1
583
Chris Ye1dd2e5c2021-04-04 23:12:41 -0700584 // A shared_ptr of a device associated with the input device.
Prabir Pradhan51894782022-08-23 16:29:10 +0000585 // The input devices that have the same sysfs path have the same associated device.
Prabir Pradhancb42b472022-08-23 16:01:19 +0000586 const std::shared_ptr<const AssociatedDevice> associatedDevice;
Kim Low03ea0352020-11-06 12:45:07 -0800587
Michael Wrightd02c5b62014-02-10 15:10:22 -0800588 int32_t controllerNumber;
589
Prabir Pradhancb42b472022-08-23 16:01:19 +0000590 Device(int fd, int32_t id, std::string path, InputDeviceIdentifier identifier,
591 std::shared_ptr<const AssociatedDevice> assocDev);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800592 ~Device();
593
594 void close();
595
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700596 bool enabled; // initially true
597 status_t enable();
598 status_t disable();
Chris Ye989bb932020-07-04 16:18:59 -0700599 bool hasValidFd() const;
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700600 const bool isVirtual; // set if fd < 0 is passed to constructor
Michael Wrightd02c5b62014-02-10 15:10:22 -0800601
Chris Ye3a1e4462020-08-12 10:13:15 -0700602 const std::shared_ptr<KeyCharacterMap> getKeyCharacterMap() const;
Chris Ye66fbac32020-07-06 20:36:43 -0700603
604 template <std::size_t N>
Chris Ye989bb932020-07-04 16:18:59 -0700605 status_t readDeviceBitMask(unsigned long ioctlCode, BitArray<N>& bitArray);
Chris Ye66fbac32020-07-06 20:36:43 -0700606
Chris Ye989bb932020-07-04 16:18:59 -0700607 void configureFd();
608 bool hasKeycodeLocked(int keycode) const;
609 void loadConfigurationLocked();
610 bool loadVirtualKeyMapLocked();
611 status_t loadKeyMapLocked();
612 bool isExternalDeviceLocked();
613 bool deviceHasMicLocked();
614 void setLedForControllerLocked();
615 status_t mapLed(int32_t led, int32_t* outScanCode) const;
616 void setLedStateLocked(int32_t led, bool on);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800617 };
618
Siarhei Vishniakoua4c502a2021-02-05 00:45:20 +0000619 /**
620 * Create a new device for the provided path.
621 */
Chris Yed3fef462021-03-07 17:10:08 -0800622 void openDeviceLocked(const std::string& devicePath) REQUIRES(mLock);
623 void openVideoDeviceLocked(const std::string& devicePath) REQUIRES(mLock);
Siarhei Vishniakouf49608d2020-08-20 19:18:21 -0500624 /**
625 * Try to associate a video device with an input device. If the association succeeds,
626 * the videoDevice is moved into the input device. 'videoDevice' will become null if this
627 * happens.
628 * Return true if the association succeeds.
629 * Return false otherwise.
630 */
Chris Yed3fef462021-03-07 17:10:08 -0800631 bool tryAddVideoDeviceLocked(Device& device, std::unique_ptr<TouchVideoDevice>& videoDevice)
632 REQUIRES(mLock);
633 void createVirtualKeyboardLocked() REQUIRES(mLock);
634 void addDeviceLocked(std::unique_ptr<Device> device) REQUIRES(mLock);
635 void assignDescriptorLocked(InputDeviceIdentifier& identifier) REQUIRES(mLock);
Prabir Pradhancb42b472022-08-23 16:01:19 +0000636 std::shared_ptr<const AssociatedDevice> obtainAssociatedDeviceLocked(
637 const std::filesystem::path& devicePath) const REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800638
Chris Yed3fef462021-03-07 17:10:08 -0800639 void closeDeviceByPathLocked(const std::string& devicePath) REQUIRES(mLock);
640 void closeVideoDeviceByPathLocked(const std::string& devicePath) REQUIRES(mLock);
641 void closeDeviceLocked(Device& device) REQUIRES(mLock);
642 void closeAllDevicesLocked() REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800643
Siarhei Vishniakou25920312018-12-12 15:24:44 -0800644 status_t registerFdForEpoll(int fd);
645 status_t unregisterFdFromEpoll(int fd);
Chris Yed3fef462021-03-07 17:10:08 -0800646 status_t registerDeviceForEpollLocked(Device& device) REQUIRES(mLock);
647 void registerVideoDeviceForEpollLocked(const TouchVideoDevice& videoDevice) REQUIRES(mLock);
648 status_t unregisterDeviceFromEpollLocked(Device& device) REQUIRES(mLock);
649 void unregisterVideoDeviceFromEpollLocked(const TouchVideoDevice& videoDevice) REQUIRES(mLock);
Siarhei Vishniakoue54cb852017-03-21 17:48:16 -0700650
Chris Yed3fef462021-03-07 17:10:08 -0800651 status_t scanDirLocked(const std::string& dirname) REQUIRES(mLock);
652 status_t scanVideoDirLocked(const std::string& dirname) REQUIRES(mLock);
653 void scanDevicesLocked() REQUIRES(mLock);
Prabir Pradhan952e65b2022-06-23 17:49:55 +0000654 base::Result<void> readNotifyLocked() REQUIRES(mLock);
655 void handleNotifyEventLocked(const inotify_event&) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800656
Chris Yed3fef462021-03-07 17:10:08 -0800657 Device* getDeviceLocked(int32_t deviceId) const REQUIRES(mLock);
658 Device* getDeviceByPathLocked(const std::string& devicePath) const REQUIRES(mLock);
Siarhei Vishniakou12598682018-11-02 17:19:19 -0700659 /**
660 * Look through all available fd's (both for input devices and for video devices),
661 * and return the device pointer.
662 */
Chris Yed3fef462021-03-07 17:10:08 -0800663 Device* getDeviceByFdLocked(int fd) const REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800664
Chris Yed3fef462021-03-07 17:10:08 -0800665 int32_t getNextControllerNumberLocked(const std::string& name) REQUIRES(mLock);
Josh Bartel938632f2022-07-19 15:34:22 -0500666
667 bool hasDeviceWithDescriptorLocked(const std::string& descriptor) const REQUIRES(mLock);
668
Chris Yed3fef462021-03-07 17:10:08 -0800669 void releaseControllerNumberLocked(int32_t num) REQUIRES(mLock);
670 void reportDeviceAddedForStatisticsLocked(const InputDeviceIdentifier& identifier,
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700671 ftl::Flags<InputDeviceClass> classes) REQUIRES(mLock);
Michael Wrightd02c5b62014-02-10 15:10:22 -0800672
Chris Yee2b1e5c2021-03-10 22:45:12 -0800673 const std::unordered_map<int32_t, RawBatteryInfo>& getBatteryInfoLocked(int32_t deviceId) const
674 REQUIRES(mLock);
675
676 const std::unordered_map<int32_t, RawLightInfo>& getLightInfoLocked(int32_t deviceId) const
677 REQUIRES(mLock);
678
Usama Arifb27c8e62021-06-03 16:44:09 +0100679 void addDeviceInputInotify();
680 void addDeviceInotify();
681
Michael Wrightd02c5b62014-02-10 15:10:22 -0800682 // Protect all internal state.
Chris Ye1c2e0892020-11-30 21:41:44 -0800683 mutable std::mutex mLock;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800684
685 // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none.
686 // EventHub remaps the built-in keyboard to id 0 externally as required by the API.
687 enum {
688 // Must not conflict with any other assigned device ids, including
689 // the virtual keyboard id (-1).
690 NO_BUILT_IN_KEYBOARD = -2,
691 };
692 int32_t mBuiltInKeyboardId;
693
694 int32_t mNextDeviceId;
695
696 BitSet32 mControllerNumbers;
697
Chris Ye989bb932020-07-04 16:18:59 -0700698 std::unordered_map<int32_t, std::unique_ptr<Device>> mDevices;
Siarhei Vishniakou22c88462018-12-13 19:34:53 -0800699 /**
700 * Video devices that report touchscreen heatmap, but have not (yet) been paired
701 * with a specific input device. Video device discovery is independent from input device
702 * discovery, so the two types of devices could be found in any order.
703 * Ideally, video devices in this queue do not have an open fd, or at least aren't
704 * actively streaming.
705 */
706 std::vector<std::unique_ptr<TouchVideoDevice>> mUnattachedVideoDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800707
Chris Ye989bb932020-07-04 16:18:59 -0700708 std::vector<std::unique_ptr<Device>> mOpeningDevices;
709 std::vector<std::unique_ptr<Device>> mClosingDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800710
711 bool mNeedToSendFinishedDeviceScan;
712 bool mNeedToReopenDevices;
713 bool mNeedToScanDevices;
Siarhei Vishniakouec8f7252018-07-06 11:19:32 +0100714 std::vector<std::string> mExcludedDevices;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800715
716 int mEpollFd;
717 int mINotifyFd;
718 int mWakeReadPipeFd;
719 int mWakeWritePipeFd;
720
Usama Arifb27c8e62021-06-03 16:44:09 +0100721 int mDeviceInputWd;
722 int mDeviceWd = -1;
Siarhei Vishniakou951f3622018-12-12 19:45:42 -0800723
Michael Wrightd02c5b62014-02-10 15:10:22 -0800724 // Maximum number of signalled FDs to handle at a time.
725 static const int EPOLL_MAX_EVENTS = 16;
726
727 // The array of pending epoll events and the index of the next event to be handled.
728 struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS];
729 size_t mPendingEventCount;
730 size_t mPendingEventIndex;
731 bool mPendingINotify;
Michael Wrightd02c5b62014-02-10 15:10:22 -0800732};
733
Dominik Laskowski2f01d772022-03-23 16:01:29 -0700734} // namespace android
Michael Wrightd02c5b62014-02-10 15:10:22 -0800735
736#endif // _RUNTIME_EVENT_HUB_H