blob: daa1bea8ca19515aad13a9ddd4b30ae5a7e9a0b0 [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>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036
37#include <linux/input.h>
Jeff Brown93fa9b32011-06-14 17:09:25 -070038#include <sys/epoll.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080039
Jeff Brown46b9ac02010-04-22 18:58:52 -070040/* Convenience constants. */
41
Jeff Brown49ccac52012-04-11 18:27:33 -070042#define BTN_FIRST 0x100 // first button code
43#define BTN_LAST 0x15f // last button code
Jeff Brown46b9ac02010-04-22 18:58:52 -070044
Jeff Brown4dac9012013-04-10 01:03:19 -070045/*
46 * These constants are used privately in Android to pass raw timestamps
47 * through evdev from uinput device drivers because there is currently no
48 * other way to transfer this information. The evdev driver automatically
49 * timestamps all input events with the time they were posted and clobbers
50 * whatever information was passed in.
51 *
52 * For the purposes of this hack, the timestamp is specified in the
53 * CLOCK_MONOTONIC timebase and is split into two EV_MSC events specifying
54 * seconds and microseconds.
55 */
56#define MSC_ANDROID_TIME_SEC 0x6
57#define MSC_ANDROID_TIME_USEC 0x7
58
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080059namespace android {
60
Jeff Brown9f25b7f2012-04-10 14:30:49 -070061enum {
62 // Device id of a special "virtual" keyboard that is always present.
63 VIRTUAL_KEYBOARD_ID = -1,
64 // Device id of the "built-in" keyboard if there is one.
65 BUILT_IN_KEYBOARD_ID = 0,
66};
67
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068/*
Jeff Brown6d0fec22010-07-23 21:28:06 -070069 * A raw event as retrieved from the EventHub.
70 */
71struct RawEvent {
72 nsecs_t when;
73 int32_t deviceId;
74 int32_t type;
Jeff Brown49ccac52012-04-11 18:27:33 -070075 int32_t code;
Jeff Brown6d0fec22010-07-23 21:28:06 -070076 int32_t value;
Jeff Brown6d0fec22010-07-23 21:28:06 -070077};
78
79/* Describes an absolute axis. */
80struct RawAbsoluteAxisInfo {
81 bool valid; // true if the information is valid, false otherwise
82
83 int32_t minValue; // minimum value
84 int32_t maxValue; // maximum value
85 int32_t flat; // center flat position, eg. flat == 8 means center is between -8 and 8
86 int32_t fuzz; // error tolerance, eg. fuzz == 4 means value is +/- 4 due to noise
Jeff Brownb3a2d132011-06-12 18:14:50 -070087 int32_t resolution; // resolution in units per mm or radians per mm
Jeff Brown6d0fec22010-07-23 21:28:06 -070088
Jeff Brown8d608662010-08-30 03:02:23 -070089 inline void clear() {
90 valid = false;
91 minValue = 0;
92 maxValue = 0;
93 flat = 0;
94 fuzz = 0;
Jeff Brownb3a2d132011-06-12 18:14:50 -070095 resolution = 0;
Jeff Brown8d608662010-08-30 03:02:23 -070096 }
Jeff Brown6d0fec22010-07-23 21:28:06 -070097};
98
99/*
Jeff Brownc5ed5912010-07-14 18:48:53 -0700100 * Input device classes.
101 */
102enum {
Jeff Browncb1404e2011-01-15 18:14:15 -0800103 /* The input device is a keyboard or has buttons. */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700104 INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001,
105
106 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
107 INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002,
108
Jeff Brown58a2da82011-01-25 16:02:22 -0800109 /* The input device is a touchscreen or a touchpad (either single-touch or multi-touch). */
110 INPUT_DEVICE_CLASS_TOUCH = 0x00000004,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700111
Jeff Brown83c09682010-12-23 17:50:18 -0800112 /* The input device is a cursor device such as a trackball or mouse. */
113 INPUT_DEVICE_CLASS_CURSOR = 0x00000008,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700114
115 /* The input device is a multi-touch touchscreen. */
Jeff Brown58a2da82011-01-25 16:02:22 -0800116 INPUT_DEVICE_CLASS_TOUCH_MT = 0x00000010,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700117
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700118 /* The input device is a directional pad (implies keyboard, has DPAD keys). */
Jeff Brownc5ed5912010-07-14 18:48:53 -0700119 INPUT_DEVICE_CLASS_DPAD = 0x00000020,
120
Jeff Browndc1ab4b2010-09-14 18:03:38 -0700121 /* The input device is a gamepad (implies keyboard, has BUTTON keys). */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700122 INPUT_DEVICE_CLASS_GAMEPAD = 0x00000040,
123
124 /* The input device has switches. */
125 INPUT_DEVICE_CLASS_SWITCH = 0x00000080,
Jeff Browncb1404e2011-01-15 18:14:15 -0800126
127 /* The input device is a joystick (implies gamepad, has joystick absolute axes). */
128 INPUT_DEVICE_CLASS_JOYSTICK = 0x00000100,
Jeff Brown56194eb2011-03-02 19:23:13 -0800129
Jeff Browna47425a2012-04-13 04:09:27 -0700130 /* The input device has a vibrator (supports FF_RUMBLE). */
131 INPUT_DEVICE_CLASS_VIBRATOR = 0x00000200,
132
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700133 /* The input device is virtual (not a real device, not part of UI configuration). */
134 INPUT_DEVICE_CLASS_VIRTUAL = 0x40000000,
135
Jeff Brown56194eb2011-03-02 19:23:13 -0800136 /* The input device is external (not built-in). */
137 INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000,
Jeff Brownc5ed5912010-07-14 18:48:53 -0700138};
139
140/*
Jeff Brown9ee285a2011-08-31 12:56:34 -0700141 * Gets the class that owns an axis, in cases where multiple classes might claim
142 * the same axis for different purposes.
143 */
144extern uint32_t getAbsAxisUsage(int32_t axis, uint32_t deviceClasses);
145
146/*
Jeff Brown46b9ac02010-04-22 18:58:52 -0700147 * Grand Central Station for events.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800148 *
Jeff Brown46b9ac02010-04-22 18:58:52 -0700149 * The event hub aggregates input events received across all known input
150 * devices on the system, including devices that may be emulated by the simulator
151 * environment. In addition, the event hub generates fake input events to indicate
152 * when devices are added or removed.
153 *
Jeff Brownb4ff35d2011-01-02 16:37:43 -0800154 * The event hub provides a stream of input events (via the getEvent function).
Jeff Brown46b9ac02010-04-22 18:58:52 -0700155 * It also supports querying the current actual state of input devices such as identifying
156 * which keys are currently down. Finally, the event hub keeps track of the capabilities of
157 * 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 -0800158 */
Jeff Brown46b9ac02010-04-22 18:58:52 -0700159class EventHubInterface : public virtual RefBase {
160protected:
161 EventHubInterface() { }
162 virtual ~EventHubInterface() { }
163
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800164public:
Jeff Brown46b9ac02010-04-22 18:58:52 -0700165 // Synthetic raw event type codes produced when devices are added or removed.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800166 enum {
Jeff Brown7342bb92010-10-01 18:55:43 -0700167 // Sent when a device is added.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800168 DEVICE_ADDED = 0x10000000,
Jeff Brown7342bb92010-10-01 18:55:43 -0700169 // Sent when a device is removed.
170 DEVICE_REMOVED = 0x20000000,
171 // Sent when all added/removed devices from the most recent scan have been reported.
172 // This event is always sent at least once.
173 FINISHED_DEVICE_SCAN = 0x30000000,
Jeff Brownb7198742011-03-18 18:14:26 -0700174
175 FIRST_SYNTHETIC_EVENT = DEVICE_ADDED,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800176 };
Jeff Brown46b9ac02010-04-22 18:58:52 -0700177
178 virtual uint32_t getDeviceClasses(int32_t deviceId) const = 0;
179
Jeff Browne38fdfa2012-04-06 14:51:01 -0700180 virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700181
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800182 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const = 0;
183
Jeff Brown6d0fec22010-07-23 21:28:06 -0700184 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
185 RawAbsoluteAxisInfo* outAxisInfo) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700186
Jeff Browncc0c1592011-02-19 05:07:28 -0800187 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const = 0;
188
Jeff Brown80fd47c2011-05-24 01:07:44 -0700189 virtual bool hasInputProperty(int32_t deviceId, int property) const = 0;
190
Jeff Brown49ccac52012-04-11 18:27:33 -0700191 virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700192 int32_t* outKeycode, uint32_t* outFlags) const = 0;
193
Jeff Brown49ccac52012-04-11 18:27:33 -0700194 virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
Jeff Brown3a22fa02011-03-04 13:07:49 -0800195 AxisInfo* outAxisInfo) const = 0;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800196
Jeff Brown1a84fd12011-06-02 01:26:32 -0700197 // Sets devices that are excluded from opening.
198 // This can be used to ignore input devices for sensors.
199 virtual void setExcludedDevices(const Vector<String8>& devices) = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700200
201 /*
Jeff Brownb7198742011-03-18 18:14:26 -0700202 * Wait for events to become available and returns them.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700203 * After returning, the EventHub holds onto a wake lock until the next call to getEvent.
204 * This ensures that the device will not go to sleep while the event is being processed.
205 * If the device needs to remain awake longer than that, then the caller is responsible
206 * for taking care of it (say, by poking the power manager user activity timer).
Jeff Brownaa3855d2011-03-17 01:34:19 -0700207 *
208 * The timeout is advisory only. If the device is asleep, it will not wake just to
209 * service the timeout.
210 *
Jeff Brownb7198742011-03-18 18:14:26 -0700211 * Returns the number of events obtained, or 0 if the timeout expired.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700212 */
Jeff Brownb7198742011-03-18 18:14:26 -0700213 virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700214
215 /*
216 * Query current input state.
Jeff Brown46b9ac02010-04-22 18:58:52 -0700217 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700218 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const = 0;
219 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const = 0;
220 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const = 0;
Jeff Brown2717eff2011-06-30 23:53:07 -0700221 virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis,
222 int32_t* outValue) const = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700223
224 /*
225 * Examine key input devices for specific framework keycode support
226 */
Jeff Brown6d0fec22010-07-23 21:28:06 -0700227 virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes, const int32_t* keyCodes,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700228 uint8_t* outFlags) const = 0;
Jeff Brownf2f48712010-10-01 17:46:21 -0700229
Jeff Brown49754db2011-07-01 17:37:58 -0700230 virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const = 0;
Jeff Brown497a92c2010-09-12 17:55:08 -0700231 virtual bool hasLed(int32_t deviceId, int32_t led) const = 0;
232 virtual void setLedState(int32_t deviceId, int32_t led, bool on) = 0;
233
Jeff Brown90655042010-12-02 13:50:46 -0800234 virtual void getVirtualKeyDefinitions(int32_t deviceId,
235 Vector<VirtualKeyDefinition>& outVirtualKeys) const = 0;
236
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700237 virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const = 0;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700238 virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map) = 0;
Jeff Brown1e08fe92011-11-15 17:48:10 -0800239
Jeff Browna47425a2012-04-13 04:09:27 -0700240 /* Control the vibrator. */
241 virtual void vibrate(int32_t deviceId, nsecs_t duration) = 0;
242 virtual void cancelVibrate(int32_t deviceId) = 0;
243
Jeff Brown93fa9b32011-06-14 17:09:25 -0700244 /* Requests the EventHub to reopen all input devices on the next call to getEvents(). */
245 virtual void requestReopenDevices() = 0;
246
247 /* Wakes up getEvents() if it is blocked on a read. */
248 virtual void wake() = 0;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700249
Jeff Brown89ef0722011-08-10 16:25:21 -0700250 /* Dump EventHub state to a string. */
Jeff Brownf2f48712010-10-01 17:46:21 -0700251 virtual void dump(String8& dump) = 0;
Jeff Brown89ef0722011-08-10 16:25:21 -0700252
253 /* Called by the heatbeat to ensures that the reader has not deadlocked. */
254 virtual void monitor() = 0;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700255};
256
257class EventHub : public EventHubInterface
258{
259public:
260 EventHub();
261
Jeff Brown46b9ac02010-04-22 18:58:52 -0700262 virtual uint32_t getDeviceClasses(int32_t deviceId) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700263
Jeff Browne38fdfa2012-04-06 14:51:01 -0700264 virtual InputDeviceIdentifier getDeviceIdentifier(int32_t deviceId) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700265
Jeff Brown47e6b1b2010-11-29 17:37:49 -0800266 virtual void getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const;
267
Jeff Brown6d0fec22010-07-23 21:28:06 -0700268 virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
269 RawAbsoluteAxisInfo* outAxisInfo) const;
270
Jeff Browncc0c1592011-02-19 05:07:28 -0800271 virtual bool hasRelativeAxis(int32_t deviceId, int axis) const;
272
Jeff Brown80fd47c2011-05-24 01:07:44 -0700273 virtual bool hasInputProperty(int32_t deviceId, int property) const;
274
Jeff Brown49ccac52012-04-11 18:27:33 -0700275 virtual status_t mapKey(int32_t deviceId, int32_t scanCode, int32_t usageCode,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700276 int32_t* outKeycode, uint32_t* outFlags) const;
277
Jeff Brown49ccac52012-04-11 18:27:33 -0700278 virtual status_t mapAxis(int32_t deviceId, int32_t scanCode,
Jeff Brown3a22fa02011-03-04 13:07:49 -0800279 AxisInfo* outAxisInfo) const;
Jeff Brown6f2fba42011-02-19 01:08:02 -0800280
Jeff Brown1a84fd12011-06-02 01:26:32 -0700281 virtual void setExcludedDevices(const Vector<String8>& devices);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700282
Jeff Brown6d0fec22010-07-23 21:28:06 -0700283 virtual int32_t getScanCodeState(int32_t deviceId, int32_t scanCode) const;
284 virtual int32_t getKeyCodeState(int32_t deviceId, int32_t keyCode) const;
285 virtual int32_t getSwitchState(int32_t deviceId, int32_t sw) const;
Jeff Brown2717eff2011-06-30 23:53:07 -0700286 virtual status_t getAbsoluteAxisValue(int32_t deviceId, int32_t axis, int32_t* outValue) const;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700287
Jeff Brown6d0fec22010-07-23 21:28:06 -0700288 virtual bool markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
289 const int32_t* keyCodes, uint8_t* outFlags) const;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800290
Jeff Brownb7198742011-03-18 18:14:26 -0700291 virtual size_t getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize);
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400292
Jeff Brown49754db2011-07-01 17:37:58 -0700293 virtual bool hasScanCode(int32_t deviceId, int32_t scanCode) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700294 virtual bool hasLed(int32_t deviceId, int32_t led) const;
295 virtual void setLedState(int32_t deviceId, int32_t led, bool on);
296
Jeff Brown90655042010-12-02 13:50:46 -0800297 virtual void getVirtualKeyDefinitions(int32_t deviceId,
298 Vector<VirtualKeyDefinition>& outVirtualKeys) const;
299
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700300 virtual sp<KeyCharacterMap> getKeyCharacterMap(int32_t deviceId) const;
Jeff Brown6ec6f792012-04-17 16:52:41 -0700301 virtual bool setKeyboardLayoutOverlay(int32_t deviceId, const sp<KeyCharacterMap>& map);
Jeff Brown1e08fe92011-11-15 17:48:10 -0800302
Jeff Browna47425a2012-04-13 04:09:27 -0700303 virtual void vibrate(int32_t deviceId, nsecs_t duration);
304 virtual void cancelVibrate(int32_t deviceId);
305
Jeff Brown93fa9b32011-06-14 17:09:25 -0700306 virtual void requestReopenDevices();
307
308 virtual void wake();
Jeff Brown1a84fd12011-06-02 01:26:32 -0700309
Jeff Brownf2f48712010-10-01 17:46:21 -0700310 virtual void dump(String8& dump);
Jeff Brown89ef0722011-08-10 16:25:21 -0700311 virtual void monitor();
Jeff Brownf2f48712010-10-01 17:46:21 -0700312
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313protected:
314 virtual ~EventHub();
Jeff Brown93fa9b32011-06-14 17:09:25 -0700315
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316private:
Jeff Brown90655042010-12-02 13:50:46 -0800317 struct Device {
318 Device* next;
319
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700320 int fd; // may be -1 if device is virtual
Jeff Brown90655042010-12-02 13:50:46 -0800321 const int32_t id;
322 const String8 path;
323 const InputDeviceIdentifier identifier;
324
325 uint32_t classes;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700326
327 uint8_t keyBitmask[(KEY_MAX + 1) / 8];
328 uint8_t absBitmask[(ABS_MAX + 1) / 8];
329 uint8_t relBitmask[(REL_MAX + 1) / 8];
330 uint8_t swBitmask[(SW_MAX + 1) / 8];
331 uint8_t ledBitmask[(LED_MAX + 1) / 8];
Jeff Browna47425a2012-04-13 04:09:27 -0700332 uint8_t ffBitmask[(FF_MAX + 1) / 8];
Jeff Brown93fa9b32011-06-14 17:09:25 -0700333 uint8_t propBitmask[(INPUT_PROP_MAX + 1) / 8];
334
Jeff Brown90655042010-12-02 13:50:46 -0800335 String8 configurationFile;
336 PropertyMap* configuration;
337 VirtualKeyMap* virtualKeyMap;
338 KeyMap keyMap;
339
Jeff Brown6ec6f792012-04-17 16:52:41 -0700340 sp<KeyCharacterMap> overlayKeyMap;
341 sp<KeyCharacterMap> combinedKeyMap;
342
Jeff Browna47425a2012-04-13 04:09:27 -0700343 bool ffEffectPlaying;
344 int16_t ffEffectId; // initially -1
345
Jeff Brown4dac9012013-04-10 01:03:19 -0700346 int32_t timestampOverrideSec;
347 int32_t timestampOverrideUsec;
348
Jeff Brown90655042010-12-02 13:50:46 -0800349 Device(int fd, int32_t id, const String8& path, const InputDeviceIdentifier& identifier);
350 ~Device();
351
352 void close();
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700353
354 inline bool isVirtual() const { return fd < 0; }
Jeff Brown4a3862f2012-04-17 18:50:05 -0700355
356 const sp<KeyCharacterMap>& getKeyCharacterMap() const {
357 if (combinedKeyMap != NULL) {
358 return combinedKeyMap;
359 }
360 return keyMap.keyCharacterMap;
361 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 };
363
Jeff Brown93fa9b32011-06-14 17:09:25 -0700364 status_t openDeviceLocked(const char *devicePath);
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700365 void createVirtualKeyboardLocked();
366 void addDeviceLocked(Device* device);
Jeff Brown93fa9b32011-06-14 17:09:25 -0700367
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700368 status_t closeDeviceByPathLocked(const char *devicePath);
Jeff Brown93fa9b32011-06-14 17:09:25 -0700369 void closeDeviceLocked(Device* device);
370 void closeAllDevicesLocked();
371
372 status_t scanDirLocked(const char *dirname);
373 void scanDevicesLocked();
374 status_t readNotifyLocked();
375
Jeff Brown90655042010-12-02 13:50:46 -0800376 Device* getDeviceLocked(int32_t deviceId) const;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700377 Device* getDeviceByPathLocked(const char* devicePath) const;
378
Jeff Brown90655042010-12-02 13:50:46 -0800379 bool hasKeycodeLocked(Device* device, int keycode) const;
Jeff Brown497a92c2010-09-12 17:55:08 -0700380
Jeff Brown93fa9b32011-06-14 17:09:25 -0700381 void loadConfigurationLocked(Device* device);
382 status_t loadVirtualKeyMapLocked(Device* device);
383 status_t loadKeyMapLocked(Device* device);
Jeff Brown497a92c2010-09-12 17:55:08 -0700384
Jeff Brown93fa9b32011-06-14 17:09:25 -0700385 bool isExternalDeviceLocked(Device* device);
Jeff Brown56194eb2011-03-02 19:23:13 -0800386
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 // Protect all internal state.
Jeff Brown90655042010-12-02 13:50:46 -0800388 mutable Mutex mLock;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400389
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700390 // The actual id of the built-in keyboard, or NO_BUILT_IN_KEYBOARD if none.
Jeff Brown90655042010-12-02 13:50:46 -0800391 // EventHub remaps the built-in keyboard to id 0 externally as required by the API.
Jeff Brown9f25b7f2012-04-10 14:30:49 -0700392 enum {
393 // Must not conflict with any other assigned device ids, including
394 // the virtual keyboard id (-1).
395 NO_BUILT_IN_KEYBOARD = -2,
396 };
Jeff Brown90655042010-12-02 13:50:46 -0800397 int32_t mBuiltInKeyboardId;
398
399 int32_t mNextDeviceId;
400
Jeff Brown93fa9b32011-06-14 17:09:25 -0700401 KeyedVector<int32_t, Device*> mDevices;
Jeff Brown90655042010-12-02 13:50:46 -0800402
403 Device *mOpeningDevices;
404 Device *mClosingDevices;
405
Jeff Brown90655042010-12-02 13:50:46 -0800406 bool mNeedToSendFinishedDeviceScan;
Jeff Brown93fa9b32011-06-14 17:09:25 -0700407 bool mNeedToReopenDevices;
Jeff Brown1a84fd12011-06-02 01:26:32 -0700408 bool mNeedToScanDevices;
409 Vector<String8> mExcludedDevices;
Mike Lockwood1d9dfc52009-07-16 11:11:18 -0400410
Jeff Brown93fa9b32011-06-14 17:09:25 -0700411 int mEpollFd;
412 int mINotifyFd;
413 int mWakeReadPipeFd;
414 int mWakeWritePipeFd;
Jeff Browncc2e7172010-08-17 16:48:25 -0700415
Jeff Brown93fa9b32011-06-14 17:09:25 -0700416 // Ids used for epoll notifications not associated with devices.
417 static const uint32_t EPOLL_ID_INOTIFY = 0x80000001;
418 static const uint32_t EPOLL_ID_WAKE = 0x80000002;
419
420 // Epoll FD list size hint.
421 static const int EPOLL_SIZE_HINT = 8;
422
423 // Maximum number of signalled FDs to handle at a time.
424 static const int EPOLL_MAX_EVENTS = 16;
425
426 // The array of pending epoll events and the index of the next event to be handled.
427 struct epoll_event mPendingEventItems[EPOLL_MAX_EVENTS];
428 size_t mPendingEventCount;
429 size_t mPendingEventIndex;
430 bool mPendingINotify;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800431};
432
433}; // namespace android
434
435#endif // _RUNTIME_EVENT_HUB_H