blob: 20179aef2242cc7516e996b106547ca18988d550 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -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
17//
18#ifndef _RUNTIME_EVENT_HUB_H
19#define _RUNTIME_EVENT_HUB_H
20
Jeff Brown9d3b1a42013-07-01 19:07:15 -070021#include <input/Input.h>
22#include <input/InputDevice.h>
23#include <input/Keyboard.h>
24#include <input/KeyLayoutMap.h>
25#include <input/KeyCharacterMap.h>
26#include <input/VirtualKeyMap.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027#include <utils/String8.h>
28#include <utils/threads.h>
Mathias Agopian3b4062e2009-05-31 19:13:00 -070029#include <utils/Log.h>
30#include <utils/threads.h>
31#include <utils/List.h>
32#include <utils/Errors.h>
Jeff Brown47e6b1b2010-11-29 17:37:49 -080033#include <utils/PropertyMap.h>
Jeff Brown90655042010-12-02 13:50:46 -080034#include <utils/Vector.h>
Jeff Brown93fa9b32011-06-14 17:09:25 -070035#include <utils/KeyedVector.h>
Michael Wrightac6c78b2013-07-17 13:21:45 -070036#include <utils/BitSet.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037
38#include <linux/input.h>
Jeff Brown93fa9b32011-06-14 17:09:25 -070039#include <sys/epoll.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
Jeff Brown46b9ac02010-04-22 18:58:52 -070041/* Convenience constants. */
42
Jeff Brown49ccac52012-04-11 18:27:33 -070043#define BTN_FIRST 0x100 // first button code
44#define BTN_LAST 0x15f // last button code
Jeff Brown46b9ac02010-04-22 18:58:52 -070045
Jeff Brown4dac9012013-04-10 01:03:19 -070046/*
47 * These constants are used privately in Android to pass raw timestamps
48 * through evdev from uinput device drivers because there is currently no
49 * other way to transfer this information. The evdev driver automatically
50 * timestamps all input events with the time they were posted and clobbers
51 * whatever information was passed in.
52 *
53 * For the purposes of this hack, the timestamp is specified in the
54 * CLOCK_MONOTONIC timebase and is split into two EV_MSC events specifying
55 * seconds and microseconds.
56 */
57#define MSC_ANDROID_TIME_SEC 0x6
58#define MSC_ANDROID_TIME_USEC 0x7
59
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080060namespace android {
61
Jeff Brown9f25b7f2012-04-10 14:30:49 -070062enum {
63 // Device id of a special "virtual" keyboard that is always present.
64 VIRTUAL_KEYBOARD_ID = -1,
65 // Device id of the "built-in" keyboard if there is one.
66 BUILT_IN_KEYBOARD_ID = 0,
67};
68
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069/*
Jeff Brown6d0fec22010-07-23 21:28:06 -070070 * A raw event as retrieved from the EventHub.
71 */
72struct RawEvent {
73 nsecs_t when;
74 int32_t deviceId;
75 int32_t type;
Jeff Brown49ccac52012-04-11 18:27:33 -070076 int32_t code;
Jeff Brown6d0fec22010-07-23 21:28:06 -070077 int32_t value;
Jeff Brown6d0fec22010-07-23 21:28:06 -070078};
79
80/* Describes an absolute axis. */
81struct RawAbsoluteAxisInfo {
82 bool valid; // true if the information is valid, false otherwise
83
84 int32_t minValue; // minimum value
85 int32_t maxValue; // maximum value
86 int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8
87 int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
Jeff Brownb3a2d132011-06-12 18:14:50 -070088 int32_t resolution; // resolution in units per mm or radians per mm
Jeff Brown6d0fec22010-07-23 21:28:06 -070089
Jeff Brown8d608662010-08-30 03:02:23 -070090 inline void clear() {
91 valid = false;
92 minValue = 0;
93 maxValue = 0;
94 flat = 0;
95 fuzz = 0;
Jeff Brownb3a2d132011-06-12 18:14:50 -070096 resolution = 0;
Jeff Brown8d608662010-08-30 03:02:23 -070097 }
Jeff Brown6d0fec22010-07-23 21:28:06 -070098};
99
100/*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700101 * Input device classes.
102 */
103enum {
Jeff Browncb1404e2011-01-15 18:14:15 -0800104 /* The input device is a keyboard or has buttons. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700105 INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001,
106
107 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
108 INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002,
109
Jeff Brown58a2da82011-01-25 16:02:22 -0800110 /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
111 INPUT_DEVICE_CLASS_TOUCH = 0x00000004,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700112
Jeff Brown83c09682010-12-23 17:50:18 -0800113 /* The input device is a cursor device such as a trackball or mouse. */
114 INPUT_DEVICE_CLASS_CURSOR = 0x00000008,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700115
116 /* The input device is a multi-touch touchscreen. */
Jeff Brown58a2da82011-01-25 16:02:22 -0800117 INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700118
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700119 /* The input device is a directional pad (implies keyboard, has DPAD keys). */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700120 INPUT_DEVICE_CLASS_DPAD = 0x00000020,
121
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700122 /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700123 INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040,
124
125 /* The input device has switches. */
126 INPUT_DEVICE_CLASS_SWITCH = 0x00000080,
Jeff Browncb1404e2011-01-15 18:14:15 -0800127
128 /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
129 INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100,
Jeff Brown56194eb2011-03-02 19:23:13 -0800130
Jeff Browna47425a2012-04-13 04:09:27 -0700131 /* The input device has a vibrator (supports FF_RUMBLE). */
132 INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200,
133
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700134 /* The input device is virtual (not a real device, not part of UI configuration). */
135 INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000,
136
Jeff Brown56194eb2011-03-02 19:23:13 -0800137 /* The input device is external (not built-in). */
138 INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700139};
140
141/*
Jeff Brown9ee285a2011-08-31 12:56:34 -0700142 * Gets the class that owns an axis, in cases where multiple classes might claim
143 * the same axis for different purposes.
144 */
145extern uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses);
146
147/*
Jeff Brown46b9ac02010-04-22 18:58:52 -0700148 * Grand Central Station for events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800149 *
Jeff Brown46b9ac02010-04-22 18:58:52 -0700150 * The event hub aggregates input events received across all known input
151 * devices on the system, including devices that may be emulated by the simulator
152 * environment. In addition, the event hub generates fake input events to indicate
153 * when devices are added or removed.
154 *
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800155 * The event hub provides a stream of input events (via the getEvent function).
Jeff Brown46b9ac02010-04-22 18:58:52 -0700156 * It also supports querying the current actual state of input devices such as identifying
157 * which keys are currently down. Finally, the event hub keeps track of the capabilities of
158 * individual input devices, such as their class and the set of key codes that they support.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800159 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700160class EventHubInterface : public virtual RefBase {
161protected:
162 EventHubInterface() { }
163 virtual ~EventHubInterface() { }
164
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800165public:
Jeff Brown46b9ac02010-04-22 18:58:52 -0700166 // Synthetic raw event type codes produced when devices are added or removed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800167 enum {
Jeff Brown7342bb92010-10-01 18:55:43 -0700168 // Sent when a device is added.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800169 DEVICE_ADDED = 0x10000000,
Jeff Brown7342bb92010-10-01 18:55:43 -0700170 // Sent when a device is removed.
171 DEVICE_REMOVED = 0x20000000,
172 // Sent when all added/removed devices from the most recent scan have been reported.
173 // This event is always sent at least once.
174 FINISHED_DEVICE_SCAN = 0x30000000,
Jeff Brownb7198742011-03-18 18:14:26 -0700175
176 FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800177 };
Jeff Brown46b9ac02010-04-22 18:58:52 -0700178
179 virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0;
180
Jeff Browne38fdfa2012-04-06 14:51:01 -0700181 virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700182
Michael Wrightac6c78b2013-07-17 13:21:45 -0700183 virtual int32_t getDeviceControllerNumber(int32_t deviceId) const = 0;
184
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800185 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0;
186
Jeff Brown6d0fec22010-07-23 21:28:06 -0700187 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
188 RawAbsoluteAxisInfo* outAxisInfo) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700189
Jeff Browncc0c1592011-02-19 05:07:28 -0800190 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0;
191
Jeff Brown80fd47c2011-05-24 01:07:44 -0700192 virtual bool hasInputProperty(int32_t deviceId, int property) const = 0;
193
Jeff Brown49ccac52012-04-11 18:27:33 -0700194 virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700195 int32_t* outKeycode, uint32_t* outFlags) const = 0;
196
Jeff Brown49ccac52012-04-11 18:27:33 -0700197 virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
Jeff Brown3a22fa02011-03-04 13:07:49 -0800198 AxisInfo* outAxisInfo) const = 0;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800199
Jeff Brown1a84fd12011-06-02 01:26:32 -0700200 // Sets devices that are excluded from opening.
201 // This can be used to ignore input devices for sensors.
202 virtual void setExcludedDevices(const Vector<String8>& devices) = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700203
204 /*
Jeff Brownb7198742011-03-18 18:14:26 -0700205 * Wait for events to become available and returns them.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700206 * After returning, the EventHub holds onto a wake lock until the next call to getEvent.
207 * This ensures that the device will not go to sleep while the event is being processed.
208 * If the device needs to remain awake longer than that, then the caller is responsible
209 * for taking care of it (say, by poking the power manager user activity timer).
Jeff Brownaa3855d2011-03-17 01:34:19 -0700210 *
211 * The timeout is advisory only. If the device is asleep, it will not wake just to
212 * service the timeout.
213 *
Jeff Brownb7198742011-03-18 18:14:26 -0700214 * Returns the number of events obtained, or 0 if the timeout expired.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700215 */
Jeff Brownb7198742011-03-18 18:14:26 -0700216 virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700217
218 /*
219 * Query current input state.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700220 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700221 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0;
222 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0;
223 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0;
Jeff Brown2717eff2011-06-30 23:53:07 -0700224 virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
225 int32_t* outValue) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700226
227 /*
228 * Examine key input devices for specific framework keycode support
229 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700230 virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700231 uint8_t* outFlags) const = 0;
Jeff Brownf2f48712010-10-01 17:46:21 -0700232
Jeff Brown49754db2011-07-01 17:37:58 -0700233 virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
Michael Wright58f5a612013-10-18 15:26:48 -0700234
235 /* LED related functions expect Android LED constants, not scan codes or HID usages */
Jeff Brown497a92c2010-09-12 17:55:08 -0700236 virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
237 virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0;
238
Jeff Brown90655042010-12-02 13:50:46 -0800239 virtual void getVirtualKeyDefinitions(int32_t deviceId,
240 Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0;
241
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700242 virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700243 virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) = 0;
Jeff Brown1e08fe92011-11-15 17:48:10 -0800244
Jeff Browna47425a2012-04-13 04:09:27 -0700245 /* Control the vibrator. */
246 virtual void vibrate(int32_t deviceId, nsecs_t duration) = 0;
247 virtual void cancelVibrate(int32_t deviceId) = 0;
248
Jeff Brown93fa9b32011-06-14 17:09:25 -0700249 /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */
250 virtual void requestReopenDevices() = 0;
251
252 /* Wakes up getEvents() if it is blocked on a read. */
253 virtual void wake() = 0;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700254
Jeff Brown89ef0722011-08-10 16:25:21 -0700255 /* Dump EventHub state to a string. */
Jeff Brownf2f48712010-10-01 17:46:21 -0700256 virtual void dump(String8& dump) = 0;
Jeff Brown89ef0722011-08-10 16:25:21 -0700257
258 /* Called by the heatbeat to ensures that the reader has not deadlocked. */
259 virtual void monitor() = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700260};
261
262class EventHub : public EventHubInterface
263{
264public:
265 EventHub();
266
Jeff Brown46b9ac02010-04-22 18:58:52 -0700267 virtual uint32_t getDeviceClasses(int32_t deviceId) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700268
Jeff Browne38fdfa2012-04-06 14:51:01 -0700269 virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700270
Michael Wrightac6c78b2013-07-17 13:21:45 -0700271 virtual int32_t getDeviceControllerNumber(int32_t deviceId) const;
272
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800273 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const;
274
Jeff Brown6d0fec22010-07-23 21:28:06 -0700275 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
276 RawAbsoluteAxisInfo* outAxisInfo) const;
277
Jeff Browncc0c1592011-02-19 05:07:28 -0800278 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const;
279
Jeff Brown80fd47c2011-05-24 01:07:44 -0700280 virtual bool hasInputProperty(int32_t deviceId, int property) const;
281
Jeff Brown49ccac52012-04-11 18:27:33 -0700282 virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700283 int32_t* outKeycode, uint32_t* outFlags) const;
284
Jeff Brown49ccac52012-04-11 18:27:33 -0700285 virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
Jeff Brown3a22fa02011-03-04 13:07:49 -0800286 AxisInfo* outAxisInfo) const;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800287
Jeff Brown1a84fd12011-06-02 01:26:32 -0700288 virtual void setExcludedDevices(const Vector<String8>& devices);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700289
Jeff Brown6d0fec22010-07-23 21:28:06 -0700290 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const;
291 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const;
292 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const;
Jeff Brown2717eff2011-06-30 23:53:07 -0700293 virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700294
Jeff Brown6d0fec22010-07-23 21:28:06 -0700295 virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
296 const int32_t* keyCodes, uint8_t* outFlags) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800297
Jeff Brownb7198742011-03-18 18:14:26 -0700298 virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize);
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400299
Jeff Brown49754db2011-07-01 17:37:58 -0700300 virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700301 virtual bool hasLed(int32_t deviceId, int32_t led) const;
302 virtual void setLedState(int32_t deviceId, int32_t led, bool on);
303
Jeff Brown90655042010-12-02 13:50:46 -0800304 virtual void getVirtualKeyDefinitions(int32_t deviceId,
305 Vector<VirtualKeyDefinition>& outVirtualKeys) const;
306
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700307 virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700308 virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map);
Jeff Brown1e08fe92011-11-15 17:48:10 -0800309
Jeff Browna47425a2012-04-13 04:09:27 -0700310 virtual void vibrate(int32_t deviceId, nsecs_t duration);
311 virtual void cancelVibrate(int32_t deviceId);
312
Jeff Brown93fa9b32011-06-14 17:09:25 -0700313 virtual void requestReopenDevices();
314
315 virtual void wake();
Jeff Brown1a84fd12011-06-02 01:26:32 -0700316
Jeff Brownf2f48712010-10-01 17:46:21 -0700317 virtual void dump(String8& dump);
Jeff Brown89ef0722011-08-10 16:25:21 -0700318 virtual void monitor();
Jeff Brownf2f48712010-10-01 17:46:21 -0700319
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800320protected:
321 virtual ~EventHub();
Jeff Brown93fa9b32011-06-14 17:09:25 -0700322
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800323private:
Jeff Brown90655042010-12-02 13:50:46 -0800324 struct Device {
325 Device* next;
326
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700327 int fd; // may be -1 if device is virtual
Jeff Brown90655042010-12-02 13:50:46 -0800328 const int32_t id;
329 const String8 path;
330 const InputDeviceIdentifier identifier;
331
332 uint32_t classes;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700333
334 uint8_t keyBitmask[(KEY_MAX + 1) / 8];
335 uint8_t absBitmask[(ABS_MAX + 1) / 8];
336 uint8_t relBitmask[(REL_MAX + 1) / 8];
337 uint8_t swBitmask[(SW_MAX + 1) / 8];
338 uint8_t ledBitmask[(LED_MAX + 1) / 8];
Jeff Browna47425a2012-04-13 04:09:27 -0700339 uint8_t ffBitmask[(FF_MAX + 1) / 8];
Jeff Brown93fa9b32011-06-14 17:09:25 -0700340 uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8];
341
Jeff Brown90655042010-12-02 13:50:46 -0800342 String8 configurationFile;
343 PropertyMap* configuration;
344 VirtualKeyMap* virtualKeyMap;
345 KeyMap keyMap;
346
Jeff Brown6ec6f792012-04-17 16:52:41 -0700347 sp<KeyCharacterMap> overlayKeyMap;
348 sp<KeyCharacterMap> combinedKeyMap;
349
Jeff Browna47425a2012-04-13 04:09:27 -0700350 bool ffEffectPlaying;
351 int16_t ffEffectId; // initially -1
352
Michael Wrightac6c78b2013-07-17 13:21:45 -0700353 int32_t controllerNumber;
354
Jeff Brown4dac9012013-04-10 01:03:19 -0700355 int32_t timestampOverrideSec;
356 int32_t timestampOverrideUsec;
357
Jeff Brown90655042010-12-02 13:50:46 -0800358 Device(int fd, int32_t id, const String8& path, const InputDeviceIdentifier& identifier);
359 ~Device();
360
361 void close();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700362
363 inline bool isVirtual() const { return fd < 0; }
Jeff Brown4a3862f2012-04-17 18:50:05 -0700364
365 const sp<KeyCharacterMap>& getKeyCharacterMap() const {
366 if (combinedKeyMap != NULL) {
367 return combinedKeyMap;
368 }
369 return keyMap.keyCharacterMap;
370 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800371 };
372
Jeff Brown93fa9b32011-06-14 17:09:25 -0700373 status_t openDeviceLocked(const char *devicePath);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700374 void createVirtualKeyboardLocked();
375 void addDeviceLocked(Device* device);
RoboErik319107b2013-12-11 17:02:46 -0800376 void assignDescriptorLocked(InputDeviceIdentifier& identifier);
Jeff Brown93fa9b32011-06-14 17:09:25 -0700377
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700378 status_t closeDeviceByPathLocked(const char *devicePath);
Jeff Brown93fa9b32011-06-14 17:09:25 -0700379 void closeDeviceLocked(Device* device);
380 void closeAllDevicesLocked();
381
382 status_t scanDirLocked(const char *dirname);
383 void scanDevicesLocked();
384 status_t readNotifyLocked();
385
RoboErik319107b2013-12-11 17:02:46 -0800386 Device* getDeviceByDescriptorLocked(String8& descriptor) const;
Jeff Brown90655042010-12-02 13:50:46 -0800387 Device* getDeviceLocked(int32_t deviceId) const;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700388 Device* getDeviceByPathLocked(const char* devicePath) const;
389
Jeff Brown90655042010-12-02 13:50:46 -0800390 bool hasKeycodeLocked(Device* device, int keycode) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700391
Jeff Brown93fa9b32011-06-14 17:09:25 -0700392 void loadConfigurationLocked(Device* device);
393 status_t loadVirtualKeyMapLocked(Device* device);
394 status_t loadKeyMapLocked(Device* device);
Jeff Brown497a92c2010-09-12 17:55:08 -0700395
Jeff Brown93fa9b32011-06-14 17:09:25 -0700396 bool isExternalDeviceLocked(Device* device);
Jeff Brown56194eb2011-03-02 19:23:13 -0800397
Michael Wrightac6c78b2013-07-17 13:21:45 -0700398 int32_t getNextControllerNumberLocked(Device* device);
399 void releaseControllerNumberLocked(Device* device);
Michael Wright58f5a612013-10-18 15:26:48 -0700400 void setLedForController(Device* device);
401
402 status_t mapLed(Device* device, int32_t led, int32_t* outScanCode) const;
403 void setLedStateLocked(Device* device, int32_t led, bool on);
Michael Wrightac6c78b2013-07-17 13:21:45 -0700404
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800405 // Protect all internal state.
Jeff Brown90655042010-12-02 13:50:46 -0800406 mutable Mutex mLock;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400407
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700408 // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none.
Jeff Brown90655042010-12-02 13:50:46 -0800409 // EventHub remaps the built-in keyboard to id 0 externally as required by the API.
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700410 enum {
411 // Must not conflict with any other assigned device ids, including
412 // the virtual keyboard id (-1).
413 NO_BUILT_IN_KEYBOARD = -2,
414 };
Jeff Brown90655042010-12-02 13:50:46 -0800415 int32_t mBuiltInKeyboardId;
416
417 int32_t mNextDeviceId;
418
Michael Wrightac6c78b2013-07-17 13:21:45 -0700419 BitSet32 mControllerNumbers;
420
Jeff Brown93fa9b32011-06-14 17:09:25 -0700421 KeyedVector<int32_t, Device*> mDevices;
Jeff Brown90655042010-12-02 13:50:46 -0800422
423 Device *mOpeningDevices;
424 Device *mClosingDevices;
425
Jeff Brown90655042010-12-02 13:50:46 -0800426 bool mNeedToSendFinishedDeviceScan;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700427 bool mNeedToReopenDevices;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700428 bool mNeedToScanDevices;
429 Vector<String8> mExcludedDevices;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400430
Jeff Brown93fa9b32011-06-14 17:09:25 -0700431 int mEpollFd;
432 int mINotifyFd;
433 int mWakeReadPipeFd;
434 int mWakeWritePipeFd;
Jeff Browncc2e7172010-08-17 16:48:25 -0700435
Jeff Brown93fa9b32011-06-14 17:09:25 -0700436 // Ids used for epoll notifications not associated with devices.
437 static const uint32_t EPOLL_ID_INOTIFY = 0x80000001;
438 static const uint32_t EPOLL_ID_WAKE = 0x80000002;
439
440 // Epoll FD list size hint.
441 static const int EPOLL_SIZE_HINT = 8;
442
443 // Maximum number of signalled FDs to handle at a time.
444 static const int EPOLL_MAX_EVENTS = 16;
445
446 // The array of pending epoll events and the index of the next event to be handled.
447 struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS];
448 size_t mPendingEventCount;
449 size_t mPendingEventIndex;
450 bool mPendingINotify;
Michael Wright67774c72013-09-25 14:13:40 -0700451
452 bool mUsingEpollWakeup;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800453};
454
455}; // namespace android
456
457#endif // _RUNTIME_EVENT_HUB_H