blob: b1284fedbfb232bdd20cf9abf9bb7606bd8bd5ed [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001//
2// Copyright 2005 The Android Open Source Project
3//
4// Handle events, like key input and vsync.
5//
6// The goal is to provide an optimized solution for Linux, not an
7// implementation that works well across all platforms. We expect
8// events to arrive on file descriptors, so that we can use a select()
9// select() call to sleep.
10//
11// We can't select() on anything but network sockets in Windows, so we
12// provide an alternative implementation of waitEvent for that platform.
13//
14#define LOG_TAG "EventHub"
15
16//#define LOG_NDEBUG 0
17
18#include <ui/EventHub.h>
Dianne Hackbornc5917362009-08-04 05:49:43 -070019#include <ui/KeycodeLabels.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080020#include <hardware_legacy/power.h>
21
22#include <cutils/properties.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080023#include <utils/Log.h>
24#include <utils/Timers.h>
Mathias Agopiane0c32202009-05-31 19:13:00 -070025#include <utils/threads.h>
Mathias Agopiane0c32202009-05-31 19:13:00 -070026#include <utils/Errors.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080027
28#include <stdlib.h>
29#include <stdio.h>
30#include <unistd.h>
31#include <fcntl.h>
32#include <memory.h>
33#include <errno.h>
34#include <assert.h>
35
36#include "KeyLayoutMap.h"
37
38#include <string.h>
39#include <stdint.h>
40#include <dirent.h>
41#ifdef HAVE_INOTIFY
42# include <sys/inotify.h>
43#endif
44#ifdef HAVE_ANDROID_OS
45# include <sys/limits.h> /* not part of Linux */
46#endif
47#include <sys/poll.h>
48#include <sys/ioctl.h>
49
50/* this macro is used to tell if "bit" is set in "array"
51 * it selects a byte from the array, and does a boolean AND
52 * operation with a byte that only has the relevant bit set.
53 * eg. to check for the 12th bit, we do (array[1] & 1<<4)
54 */
55#define test_bit(bit, array) (array[bit/8] & (1<<(bit%8)))
56
Jeff Brown8575a872010-06-30 16:10:35 -070057/* this macro computes the number of bytes needed to represent a bit array of the specified size */
58#define sizeof_bit_array(bits) ((bits + 7) / 8)
59
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060#define ID_MASK 0x0000ffff
61#define SEQ_MASK 0x7fff0000
62#define SEQ_SHIFT 16
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063
Dianne Hackbornc5917362009-08-04 05:49:43 -070064#ifndef ABS_MT_TOUCH_MAJOR
65#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
66#endif
67
68#ifndef ABS_MT_POSITION_X
69#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
70#endif
71
72#ifndef ABS_MT_POSITION_Y
73#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
74#endif
75
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080076namespace android {
77
78static const char *WAKE_LOCK_ID = "KeyEvents";
79static const char *device_path = "/dev/input";
80
81/* return the larger integer */
82static inline int max(int v1, int v2)
83{
84 return (v1 > v2) ? v1 : v2;
85}
86
Iliyan Malchev34193b32009-08-06 14:50:08 -070087EventHub::device_t::device_t(int32_t _id, const char* _path, const char* name)
88 : id(_id), path(_path), name(name), classes(0)
Jens Gulinaf997c42010-06-22 22:21:57 +020089 , keyBitmask(NULL), layoutMap(new KeyLayoutMap()), fd(-1), next(NULL) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080090}
91
92EventHub::device_t::~device_t() {
93 delete [] keyBitmask;
94 delete layoutMap;
95}
96
97EventHub::EventHub(void)
98 : mError(NO_INIT), mHaveFirstKeyboard(false), mFirstKeyboardId(0)
99 , mDevicesById(0), mNumDevicesById(0)
100 , mOpeningDevices(0), mClosingDevices(0)
Mike Lockwoodb4411062009-07-16 11:11:18 -0400101 , mDevices(0), mFDs(0), mFDCount(0), mOpened(false)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102{
103 acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
104#ifdef EV_SW
105 memset(mSwitches, 0, sizeof(mSwitches));
106#endif
107}
108
109/*
110 * Clean up.
111 */
112EventHub::~EventHub(void)
113{
114 release_wake_lock(WAKE_LOCK_ID);
115 // we should free stuff here...
116}
117
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118status_t EventHub::errorCheck() const
119{
120 return mError;
121}
122
123String8 EventHub::getDeviceName(int32_t deviceId) const
124{
125 AutoMutex _l(mLock);
126 device_t* device = getDevice(deviceId);
127 if (device == NULL) return String8();
128 return device->name;
129}
130
131uint32_t EventHub::getDeviceClasses(int32_t deviceId) const
132{
133 AutoMutex _l(mLock);
134 device_t* device = getDevice(deviceId);
135 if (device == NULL) return 0;
136 return device->classes;
137}
138
Jeff Browne57e8952010-07-23 21:28:06 -0700139status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis,
140 RawAbsoluteAxisInfo* outAxisInfo) const {
141 outAxisInfo->valid = false;
142 outAxisInfo->minValue = 0;
143 outAxisInfo->maxValue = 0;
144 outAxisInfo->flat = 0;
145 outAxisInfo->fuzz = 0;
146
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800147 AutoMutex _l(mLock);
148 device_t* device = getDevice(deviceId);
149 if (device == NULL) return -1;
150
151 struct input_absinfo info;
152
Jens Gulinaf997c42010-06-22 22:21:57 +0200153 if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
Jeff Browne57e8952010-07-23 21:28:06 -0700154 LOGW("Error reading absolute controller %d for device %s fd %d\n",
Jens Gulinaf997c42010-06-22 22:21:57 +0200155 axis, device->name.string(), device->fd);
Jeff Browne57e8952010-07-23 21:28:06 -0700156 return -errno;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800157 }
Jeff Browne57e8952010-07-23 21:28:06 -0700158
159 if (info.minimum != info.maximum) {
160 outAxisInfo->valid = true;
161 outAxisInfo->minValue = info.minimum;
162 outAxisInfo->maxValue = info.maximum;
163 outAxisInfo->flat = info.flat;
164 outAxisInfo->fuzz = info.fuzz;
165 }
166 return OK;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800167}
168
Jeff Browne57e8952010-07-23 21:28:06 -0700169int32_t EventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const {
Jeff Browne839a582010-04-22 18:58:52 -0700170 if (scanCode >= 0 && scanCode <= KEY_MAX) {
171 AutoMutex _l(mLock);
172
Jeff Browne57e8952010-07-23 21:28:06 -0700173 device_t* device = getDevice(deviceId);
174 if (device != NULL) {
175 return getScanCodeStateLocked(device, scanCode);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800176 }
177 }
Jeff Brown5c1ed842010-07-14 18:48:53 -0700178 return AKEY_STATE_UNKNOWN;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800179}
180
Jeff Browne839a582010-04-22 18:58:52 -0700181int32_t EventHub::getScanCodeStateLocked(device_t* device, int32_t scanCode) const {
Jeff Brown8575a872010-06-30 16:10:35 -0700182 uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)];
Jeff Browne839a582010-04-22 18:58:52 -0700183 memset(key_bitmask, 0, sizeof(key_bitmask));
Jean-Baptiste Queru28a989b2010-08-17 09:01:26 -0700184 if (ioctl(device->fd,
Jeff Browne839a582010-04-22 18:58:52 -0700185 EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
Jeff Brown5c1ed842010-07-14 18:48:53 -0700186 return test_bit(scanCode, key_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
Jeff Browne839a582010-04-22 18:58:52 -0700187 }
Jeff Brown5c1ed842010-07-14 18:48:53 -0700188 return AKEY_STATE_UNKNOWN;
Jeff Browne839a582010-04-22 18:58:52 -0700189}
190
Jeff Browne57e8952010-07-23 21:28:06 -0700191int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const {
192 AutoMutex _l(mLock);
Jeff Browne839a582010-04-22 18:58:52 -0700193
Jeff Browne57e8952010-07-23 21:28:06 -0700194 device_t* device = getDevice(deviceId);
195 if (device != NULL) {
196 return getKeyCodeStateLocked(device, keyCode);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800197 }
Jeff Brown5c1ed842010-07-14 18:48:53 -0700198 return AKEY_STATE_UNKNOWN;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800199}
200
Jeff Browne839a582010-04-22 18:58:52 -0700201int32_t EventHub::getKeyCodeStateLocked(device_t* device, int32_t keyCode) const {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202 Vector<int32_t> scanCodes;
Jeff Browne839a582010-04-22 18:58:52 -0700203 device->layoutMap->findScancodes(keyCode, &scanCodes);
204
Jeff Brown8575a872010-06-30 16:10:35 -0700205 uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206 memset(key_bitmask, 0, sizeof(key_bitmask));
Jens Gulinaf997c42010-06-22 22:21:57 +0200207 if (ioctl(device->fd, EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208 #if 0
209 for (size_t i=0; i<=KEY_MAX; i++) {
210 LOGI("(Scan code %d: down=%d)", i, test_bit(i, key_bitmask));
211 }
212 #endif
213 const size_t N = scanCodes.size();
214 for (size_t i=0; i<N && i<=KEY_MAX; i++) {
215 int32_t sc = scanCodes.itemAt(i);
216 //LOGI("Code %d: down=%d", sc, test_bit(sc, key_bitmask));
217 if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, key_bitmask)) {
Jeff Brown5c1ed842010-07-14 18:48:53 -0700218 return AKEY_STATE_DOWN;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800219 }
220 }
Jeff Brown5c1ed842010-07-14 18:48:53 -0700221 return AKEY_STATE_UP;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800222 }
Jeff Brown5c1ed842010-07-14 18:48:53 -0700223 return AKEY_STATE_UNKNOWN;
Jeff Browne839a582010-04-22 18:58:52 -0700224}
225
Jeff Browne57e8952010-07-23 21:28:06 -0700226int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const {
Jeff Browne839a582010-04-22 18:58:52 -0700227#ifdef EV_SW
228 if (sw >= 0 && sw <= SW_MAX) {
229 AutoMutex _l(mLock);
230
Jeff Browne839a582010-04-22 18:58:52 -0700231 device_t* device = getDevice(deviceId);
Jeff Browne57e8952010-07-23 21:28:06 -0700232 if (device != NULL) {
233 return getSwitchStateLocked(device, sw);
Jeff Browne839a582010-04-22 18:58:52 -0700234 }
Jeff Browne839a582010-04-22 18:58:52 -0700235 }
236#endif
Jeff Brown5c1ed842010-07-14 18:48:53 -0700237 return AKEY_STATE_UNKNOWN;
Jeff Browne839a582010-04-22 18:58:52 -0700238}
239
240int32_t EventHub::getSwitchStateLocked(device_t* device, int32_t sw) const {
Jeff Brown8575a872010-06-30 16:10:35 -0700241 uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)];
Jeff Browne839a582010-04-22 18:58:52 -0700242 memset(sw_bitmask, 0, sizeof(sw_bitmask));
Jean-Baptiste Queru28a989b2010-08-17 09:01:26 -0700243 if (ioctl(device->fd,
Jeff Browne839a582010-04-22 18:58:52 -0700244 EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) {
Jeff Brown5c1ed842010-07-14 18:48:53 -0700245 return test_bit(sw, sw_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP;
Jeff Browne839a582010-04-22 18:58:52 -0700246 }
Jeff Brown5c1ed842010-07-14 18:48:53 -0700247 return AKEY_STATE_UNKNOWN;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800248}
249
Jeff Browne57e8952010-07-23 21:28:06 -0700250bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes,
251 const int32_t* keyCodes, uint8_t* outFlags) const {
252 AutoMutex _l(mLock);
253
254 device_t* device = getDevice(deviceId);
255 if (device != NULL) {
256 return markSupportedKeyCodesLocked(device, numCodes, keyCodes, outFlags);
257 }
258 return false;
259}
260
261bool EventHub::markSupportedKeyCodesLocked(device_t* device, size_t numCodes,
262 const int32_t* keyCodes, uint8_t* outFlags) const {
263 if (device->layoutMap == NULL || device->keyBitmask == NULL) {
264 return false;
265 }
266
267 Vector<int32_t> scanCodes;
268 for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) {
269 scanCodes.clear();
270
271 status_t err = device->layoutMap->findScancodes(keyCodes[codeIndex], &scanCodes);
272 if (! err) {
273 // check the possible scan codes identified by the layout map against the
274 // map of codes actually emitted by the driver
275 for (size_t sc = 0; sc < scanCodes.size(); sc++) {
276 if (test_bit(scanCodes[sc], device->keyBitmask)) {
277 outFlags[codeIndex] = 1;
278 break;
279 }
280 }
281 }
282 }
283 return true;
284}
285
Dianne Hackbornc968c3a2009-07-14 12:06:54 -0700286status_t EventHub::scancodeToKeycode(int32_t deviceId, int scancode,
287 int32_t* outKeycode, uint32_t* outFlags) const
288{
289 AutoMutex _l(mLock);
290 device_t* device = getDevice(deviceId);
291
292 if (device != NULL && device->layoutMap != NULL) {
293 status_t err = device->layoutMap->map(scancode, outKeycode, outFlags);
294 if (err == NO_ERROR) {
295 return NO_ERROR;
296 }
297 }
298
299 if (mHaveFirstKeyboard) {
300 device = getDevice(mFirstKeyboardId);
301
302 if (device != NULL && device->layoutMap != NULL) {
303 status_t err = device->layoutMap->map(scancode, outKeycode, outFlags);
304 if (err == NO_ERROR) {
305 return NO_ERROR;
306 }
307 }
308 }
309
310 *outKeycode = 0;
311 *outFlags = 0;
312 return NAME_NOT_FOUND;
313}
314
Mike Lockwoodb4411062009-07-16 11:11:18 -0400315void EventHub::addExcludedDevice(const char* deviceName)
316{
317 String8 name(deviceName);
318 mExcludedDevices.push_back(name);
319}
320
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800321EventHub::device_t* EventHub::getDevice(int32_t deviceId) const
322{
323 if (deviceId == 0) deviceId = mFirstKeyboardId;
324 int32_t id = deviceId & ID_MASK;
325 if (id >= mNumDevicesById || id < 0) return NULL;
326 device_t* dev = mDevicesById[id].device;
Dianne Hackbornc3aa00b2009-03-25 16:21:55 -0700327 if (dev == NULL) return NULL;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800328 if (dev->id == deviceId) {
329 return dev;
330 }
331 return NULL;
332}
333
Jeff Browne57e8952010-07-23 21:28:06 -0700334bool EventHub::getEvent(RawEvent* outEvent)
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800335{
Jeff Browne57e8952010-07-23 21:28:06 -0700336 outEvent->deviceId = 0;
337 outEvent->type = 0;
338 outEvent->scanCode = 0;
339 outEvent->keyCode = 0;
340 outEvent->flags = 0;
341 outEvent->value = 0;
342 outEvent->when = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800343
344 status_t err;
345
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800346 int i;
347 int res;
348 int pollres;
349 struct input_event iev;
350
351 // Note that we only allow one caller to getEvent(), so don't need
352 // to do locking here... only when adding/removing devices.
Mike Lockwoodb4411062009-07-16 11:11:18 -0400353
354 if (!mOpened) {
355 mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR;
356 mOpened = true;
357 }
358
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800359 while(1) {
360
361 // First, report any devices that had last been added/removed.
362 if (mClosingDevices != NULL) {
363 device_t* device = mClosingDevices;
364 LOGV("Reporting device closed: id=0x%x, name=%s\n",
365 device->id, device->path.string());
366 mClosingDevices = device->next;
Jeff Browne57e8952010-07-23 21:28:06 -0700367 if (device->id == mFirstKeyboardId) {
368 outEvent->deviceId = 0;
369 } else {
370 outEvent->deviceId = device->id;
371 }
372 outEvent->type = DEVICE_REMOVED;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800373 delete device;
374 return true;
375 }
Jeff Browne57e8952010-07-23 21:28:06 -0700376
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800377 if (mOpeningDevices != NULL) {
378 device_t* device = mOpeningDevices;
379 LOGV("Reporting device opened: id=0x%x, name=%s\n",
380 device->id, device->path.string());
381 mOpeningDevices = device->next;
Jeff Browne57e8952010-07-23 21:28:06 -0700382 if (device->id == mFirstKeyboardId) {
383 outEvent->deviceId = 0;
384 } else {
385 outEvent->deviceId = device->id;
386 }
387 outEvent->type = DEVICE_ADDED;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800388 return true;
389 }
390
391 release_wake_lock(WAKE_LOCK_ID);
392
393 pollres = poll(mFDs, mFDCount, -1);
394
395 acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
396
397 if (pollres <= 0) {
398 if (errno != EINTR) {
399 LOGW("select failed (errno=%d)\n", errno);
400 usleep(100000);
401 }
402 continue;
403 }
404
405 //printf("poll %d, returned %d\n", mFDCount, pollres);
406
407 // mFDs[0] is used for inotify, so process regular events starting at mFDs[1]
408 for(i = 1; i < mFDCount; i++) {
409 if(mFDs[i].revents) {
410 LOGV("revents for %d = 0x%08x", i, mFDs[i].revents);
411 if(mFDs[i].revents & POLLIN) {
412 res = read(mFDs[i].fd, &iev, sizeof(iev));
413 if (res == sizeof(iev)) {
Jeff Browne57e8952010-07-23 21:28:06 -0700414 device_t* device = mDevices[i];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800415 LOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, v=%d",
Jeff Browne57e8952010-07-23 21:28:06 -0700416 device->path.string(),
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800417 (int) iev.time.tv_sec, (int) iev.time.tv_usec,
418 iev.type, iev.code, iev.value);
Jeff Browne57e8952010-07-23 21:28:06 -0700419 if (device->id == mFirstKeyboardId) {
420 outEvent->deviceId = 0;
421 } else {
422 outEvent->deviceId = device->id;
423 }
424 outEvent->type = iev.type;
425 outEvent->scanCode = iev.code;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800426 if (iev.type == EV_KEY) {
Jeff Browne57e8952010-07-23 21:28:06 -0700427 err = device->layoutMap->map(iev.code,
428 & outEvent->keyCode, & outEvent->flags);
429 LOGV("iev.code=%d keyCode=%d flags=0x%08x err=%d\n",
430 iev.code, outEvent->keyCode, outEvent->flags, err);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800431 if (err != 0) {
Jeff Browne57e8952010-07-23 21:28:06 -0700432 outEvent->keyCode = AKEYCODE_UNKNOWN;
433 outEvent->flags = 0;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800434 }
435 } else {
Jeff Browne57e8952010-07-23 21:28:06 -0700436 outEvent->keyCode = iev.code;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800437 }
Jeff Browne57e8952010-07-23 21:28:06 -0700438 outEvent->value = iev.value;
439
440 // Use an event timestamp in the same timebase as
441 // java.lang.System.nanoTime() and android.os.SystemClock.uptimeMillis()
442 // as expected by the rest of the system.
443 outEvent->when = systemTime(SYSTEM_TIME_MONOTONIC);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800444 return true;
445 } else {
446 if (res<0) {
447 LOGW("could not get event (errno=%d)", errno);
448 } else {
449 LOGE("could not get event (wrong size: %d)", res);
450 }
451 continue;
452 }
453 }
454 }
455 }
456
457 // read_notify() will modify mFDs and mFDCount, so this must be done after
458 // processing all other events.
459 if(mFDs[0].revents & POLLIN) {
460 read_notify(mFDs[0].fd);
461 }
462 }
463}
464
465/*
466 * Open the platform-specific input device.
467 */
468bool EventHub::openPlatformInput(void)
469{
470 /*
471 * Open platform-specific input device(s).
472 */
473 int res;
474
475 mFDCount = 1;
476 mFDs = (pollfd *)calloc(1, sizeof(mFDs[0]));
477 mDevices = (device_t **)calloc(1, sizeof(mDevices[0]));
478 mFDs[0].events = POLLIN;
479 mDevices[0] = NULL;
480#ifdef HAVE_INOTIFY
481 mFDs[0].fd = inotify_init();
482 res = inotify_add_watch(mFDs[0].fd, device_path, IN_DELETE | IN_CREATE);
483 if(res < 0) {
484 LOGE("could not add watch for %s, %s\n", device_path, strerror(errno));
485 }
486#else
487 /*
488 * The code in EventHub::getEvent assumes that mFDs[0] is an inotify fd.
489 * We allocate space for it and set it to something invalid.
490 */
491 mFDs[0].fd = -1;
492#endif
493
494 res = scan_dir(device_path);
495 if(res < 0) {
496 LOGE("scan dir failed for %s\n", device_path);
497 //open_device("/dev/input/event0");
498 }
499
500 return true;
501}
502
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800503// ----------------------------------------------------------------------------
504
Jeff Brown8575a872010-06-30 16:10:35 -0700505static bool containsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint32_t endIndex) {
506 const uint8_t* end = array + endIndex;
507 array += startIndex;
508 while (array != end) {
509 if (*(array++) != 0) {
510 return true;
511 }
512 }
513 return false;
514}
515
516static const int32_t GAMEPAD_KEYCODES[] = {
517 AKEYCODE_BUTTON_A, AKEYCODE_BUTTON_B, AKEYCODE_BUTTON_C,
518 AKEYCODE_BUTTON_X, AKEYCODE_BUTTON_Y, AKEYCODE_BUTTON_Z,
519 AKEYCODE_BUTTON_L1, AKEYCODE_BUTTON_R1,
520 AKEYCODE_BUTTON_L2, AKEYCODE_BUTTON_R2,
521 AKEYCODE_BUTTON_THUMBL, AKEYCODE_BUTTON_THUMBR,
522 AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE
523};
524
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800525int EventHub::open_device(const char *deviceName)
526{
527 int version;
528 int fd;
529 struct pollfd *new_mFDs;
530 device_t **new_devices;
531 char **new_device_names;
532 char name[80];
533 char location[80];
534 char idstr[80];
535 struct input_id id;
536
537 LOGV("Opening device: %s", deviceName);
538
539 AutoMutex _l(mLock);
Nick Pellyc81bb202010-01-20 19:36:49 -0800540
Nick Pelly1b5cf322010-01-26 10:27:15 -0800541 fd = open(deviceName, O_RDWR);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800542 if(fd < 0) {
543 LOGE("could not open %s, %s\n", deviceName, strerror(errno));
544 return -1;
545 }
546
547 if(ioctl(fd, EVIOCGVERSION, &version)) {
548 LOGE("could not get driver version for %s, %s\n", deviceName, strerror(errno));
549 return -1;
550 }
551 if(ioctl(fd, EVIOCGID, &id)) {
552 LOGE("could not get driver id for %s, %s\n", deviceName, strerror(errno));
553 return -1;
554 }
555 name[sizeof(name) - 1] = '\0';
556 location[sizeof(location) - 1] = '\0';
557 idstr[sizeof(idstr) - 1] = '\0';
558 if(ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
559 //fprintf(stderr, "could not get device name for %s, %s\n", deviceName, strerror(errno));
560 name[0] = '\0';
561 }
Mike Lockwood24a7e042009-07-17 00:10:10 -0400562
563 // check to see if the device is on our excluded list
564 List<String8>::iterator iter = mExcludedDevices.begin();
565 List<String8>::iterator end = mExcludedDevices.end();
566 for ( ; iter != end; iter++) {
567 const char* test = *iter;
568 if (strcmp(name, test) == 0) {
569 LOGI("ignoring event id %s driver %s\n", deviceName, test);
570 close(fd);
571 fd = -1;
572 return -1;
573 }
574 }
575
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800576 if(ioctl(fd, EVIOCGPHYS(sizeof(location) - 1), &location) < 1) {
577 //fprintf(stderr, "could not get location for %s, %s\n", deviceName, strerror(errno));
578 location[0] = '\0';
579 }
580 if(ioctl(fd, EVIOCGUNIQ(sizeof(idstr) - 1), &idstr) < 1) {
581 //fprintf(stderr, "could not get idstring for %s, %s\n", deviceName, strerror(errno));
582 idstr[0] = '\0';
583 }
584
585 int devid = 0;
586 while (devid < mNumDevicesById) {
587 if (mDevicesById[devid].device == NULL) {
588 break;
589 }
590 devid++;
591 }
592 if (devid >= mNumDevicesById) {
593 device_ent* new_devids = (device_ent*)realloc(mDevicesById,
594 sizeof(mDevicesById[0]) * (devid + 1));
595 if (new_devids == NULL) {
596 LOGE("out of memory");
597 return -1;
598 }
599 mDevicesById = new_devids;
600 mNumDevicesById = devid+1;
601 mDevicesById[devid].device = NULL;
602 mDevicesById[devid].seq = 0;
603 }
604
605 mDevicesById[devid].seq = (mDevicesById[devid].seq+(1<<SEQ_SHIFT))&SEQ_MASK;
606 if (mDevicesById[devid].seq == 0) {
607 mDevicesById[devid].seq = 1<<SEQ_SHIFT;
608 }
609
610 new_mFDs = (pollfd*)realloc(mFDs, sizeof(mFDs[0]) * (mFDCount + 1));
611 new_devices = (device_t**)realloc(mDevices, sizeof(mDevices[0]) * (mFDCount + 1));
612 if (new_mFDs == NULL || new_devices == NULL) {
613 LOGE("out of memory");
614 return -1;
615 }
616 mFDs = new_mFDs;
617 mDevices = new_devices;
618
619#if 0
620 LOGI("add device %d: %s\n", mFDCount, deviceName);
621 LOGI(" bus: %04x\n"
622 " vendor %04x\n"
623 " product %04x\n"
624 " version %04x\n",
625 id.bustype, id.vendor, id.product, id.version);
626 LOGI(" name: \"%s\"\n", name);
627 LOGI(" location: \"%s\"\n"
628 " id: \"%s\"\n", location, idstr);
629 LOGI(" version: %d.%d.%d\n",
630 version >> 16, (version >> 8) & 0xff, version & 0xff);
631#endif
632
Iliyan Malchev34193b32009-08-06 14:50:08 -0700633 device_t* device = new device_t(devid|mDevicesById[devid].seq, deviceName, name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800634 if (device == NULL) {
635 LOGE("out of memory");
636 return -1;
637 }
638
Jens Gulinaf997c42010-06-22 22:21:57 +0200639 device->fd = fd;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800640 mFDs[mFDCount].fd = fd;
641 mFDs[mFDCount].events = POLLIN;
642
Jeff Brown8575a872010-06-30 16:10:35 -0700643 // Figure out the kinds of events the device reports.
Dianne Hackbornc5917362009-08-04 05:49:43 -0700644
Jeff Brown8575a872010-06-30 16:10:35 -0700645 uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800646 memset(key_bitmask, 0, sizeof(key_bitmask));
Jeff Brown8575a872010-06-30 16:10:35 -0700647
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800648 LOGV("Getting keys...");
649 if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask) >= 0) {
650 //LOGI("MAP\n");
Jeff Brown8575a872010-06-30 16:10:35 -0700651 //for (int i = 0; i < sizeof(key_bitmask); i++) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800652 // LOGI("%d: 0x%02x\n", i, key_bitmask[i]);
653 //}
Jeff Brown8575a872010-06-30 16:10:35 -0700654
655 // See if this is a keyboard. Ignore everything in the button range except for
656 // gamepads which are also considered keyboards.
657 if (containsNonZeroByte(key_bitmask, 0, sizeof_bit_array(BTN_MISC))
658 || containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_GAMEPAD),
659 sizeof_bit_array(BTN_DIGI))
660 || containsNonZeroByte(key_bitmask, sizeof_bit_array(KEY_OK),
661 sizeof_bit_array(KEY_MAX + 1))) {
662 device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
663
Dianne Hackbornc5917362009-08-04 05:49:43 -0700664 device->keyBitmask = new uint8_t[sizeof(key_bitmask)];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800665 if (device->keyBitmask != NULL) {
666 memcpy(device->keyBitmask, key_bitmask, sizeof(key_bitmask));
667 } else {
668 delete device;
669 LOGE("out of memory allocating key bitmask");
670 return -1;
671 }
672 }
673 }
Dianne Hackbornc5917362009-08-04 05:49:43 -0700674
Jeff Brown8575a872010-06-30 16:10:35 -0700675 // See if this is a trackball (or mouse).
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800676 if (test_bit(BTN_MOUSE, key_bitmask)) {
Jeff Brown8575a872010-06-30 16:10:35 -0700677 uint8_t rel_bitmask[sizeof_bit_array(REL_MAX + 1)];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800678 memset(rel_bitmask, 0, sizeof(rel_bitmask));
679 LOGV("Getting relative controllers...");
Jeff Brown8575a872010-06-30 16:10:35 -0700680 if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) >= 0) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800681 if (test_bit(REL_X, rel_bitmask) && test_bit(REL_Y, rel_bitmask)) {
Jeff Browne839a582010-04-22 18:58:52 -0700682 device->classes |= INPUT_DEVICE_CLASS_TRACKBALL;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800683 }
684 }
685 }
Jeff Brown8575a872010-06-30 16:10:35 -0700686
687 // See if this is a touch pad.
688 uint8_t abs_bitmask[sizeof_bit_array(ABS_MAX + 1)];
Dianne Hackbornc5917362009-08-04 05:49:43 -0700689 memset(abs_bitmask, 0, sizeof(abs_bitmask));
690 LOGV("Getting absolute controllers...");
Jeff Brown8575a872010-06-30 16:10:35 -0700691 if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask) >= 0) {
692 // Is this a new modern multi-touch driver?
693 if (test_bit(ABS_MT_TOUCH_MAJOR, abs_bitmask)
694 && test_bit(ABS_MT_POSITION_X, abs_bitmask)
695 && test_bit(ABS_MT_POSITION_Y, abs_bitmask)) {
696 device->classes |= INPUT_DEVICE_CLASS_TOUCHSCREEN | INPUT_DEVICE_CLASS_TOUCHSCREEN_MT;
697
698 // Is this an old style single-touch driver?
699 } else if (test_bit(BTN_TOUCH, key_bitmask)
700 && test_bit(ABS_X, abs_bitmask) && test_bit(ABS_Y, abs_bitmask)) {
701 device->classes |= INPUT_DEVICE_CLASS_TOUCHSCREEN;
702 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800703 }
704
705#ifdef EV_SW
706 // figure out the switches this device reports
Jeff Brown8575a872010-06-30 16:10:35 -0700707 uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800708 memset(sw_bitmask, 0, sizeof(sw_bitmask));
Jeff Browne57e8952010-07-23 21:28:06 -0700709 bool hasSwitches = false;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800710 if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof(sw_bitmask)), sw_bitmask) >= 0) {
711 for (int i=0; i<EV_SW; i++) {
712 //LOGI("Device 0x%x sw %d: has=%d", device->id, i, test_bit(i, sw_bitmask));
713 if (test_bit(i, sw_bitmask)) {
Jeff Browne57e8952010-07-23 21:28:06 -0700714 hasSwitches = true;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800715 if (mSwitches[i] == 0) {
716 mSwitches[i] = device->id;
717 }
718 }
719 }
720 }
Jeff Browne57e8952010-07-23 21:28:06 -0700721 if (hasSwitches) {
722 device->classes |= INPUT_DEVICE_CLASS_SWITCH;
723 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800724#endif
725
Jeff Browne839a582010-04-22 18:58:52 -0700726 if ((device->classes & INPUT_DEVICE_CLASS_KEYBOARD) != 0) {
Iliyan Malchev34193b32009-08-06 14:50:08 -0700727 char tmpfn[sizeof(name)];
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800728 char keylayoutFilename[300];
729
730 // a more descriptive name
Iliyan Malchev34193b32009-08-06 14:50:08 -0700731 device->name = name;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800732
733 // replace all the spaces with underscores
Iliyan Malchev34193b32009-08-06 14:50:08 -0700734 strcpy(tmpfn, name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800735 for (char *p = strchr(tmpfn, ' '); p && *p; p = strchr(tmpfn, ' '))
736 *p = '_';
737
738 // find the .kl file we need for this device
739 const char* root = getenv("ANDROID_ROOT");
740 snprintf(keylayoutFilename, sizeof(keylayoutFilename),
741 "%s/usr/keylayout/%s.kl", root, tmpfn);
742 bool defaultKeymap = false;
743 if (access(keylayoutFilename, R_OK)) {
744 snprintf(keylayoutFilename, sizeof(keylayoutFilename),
745 "%s/usr/keylayout/%s", root, "qwerty.kl");
746 defaultKeymap = true;
747 }
Jeff Brown8575a872010-06-30 16:10:35 -0700748 status_t status = device->layoutMap->load(keylayoutFilename);
749 if (status) {
750 LOGE("Error %d loading key layout.", status);
751 }
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800752
753 // tell the world about the devname (the descriptive name)
Dianne Hackborn71c3eb22010-03-02 17:19:29 -0800754 if (!mHaveFirstKeyboard && !defaultKeymap && strstr(name, "-keypad")) {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800755 // the built-in keyboard has a well-known device ID of 0,
756 // this device better not go away.
757 mHaveFirstKeyboard = true;
758 mFirstKeyboardId = device->id;
Dianne Hackborn71c3eb22010-03-02 17:19:29 -0800759 property_set("hw.keyboards.0.devname", name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800760 } else {
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800761 // ensure mFirstKeyboardId is set to -something-.
762 if (mFirstKeyboardId == 0) {
763 mFirstKeyboardId = device->id;
764 }
765 }
766 char propName[100];
Dianne Hackborn71c3eb22010-03-02 17:19:29 -0800767 sprintf(propName, "hw.keyboards.%u.devname", device->id);
Iliyan Malchev34193b32009-08-06 14:50:08 -0700768 property_set(propName, name);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800769
Dianne Hackbornc5917362009-08-04 05:49:43 -0700770 // 'Q' key support = cheap test of whether this is an alpha-capable kbd
Jeff Brown8575a872010-06-30 16:10:35 -0700771 if (hasKeycode(device, AKEYCODE_Q)) {
Jeff Browne839a582010-04-22 18:58:52 -0700772 device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
Dianne Hackbornc5917362009-08-04 05:49:43 -0700773 }
774
Jeff Brown8575a872010-06-30 16:10:35 -0700775 // See if this device has a DPAD.
776 if (hasKeycode(device, AKEYCODE_DPAD_UP) &&
777 hasKeycode(device, AKEYCODE_DPAD_DOWN) &&
778 hasKeycode(device, AKEYCODE_DPAD_LEFT) &&
779 hasKeycode(device, AKEYCODE_DPAD_RIGHT) &&
780 hasKeycode(device, AKEYCODE_DPAD_CENTER)) {
Jeff Browne839a582010-04-22 18:58:52 -0700781 device->classes |= INPUT_DEVICE_CLASS_DPAD;
Dianne Hackbornc5917362009-08-04 05:49:43 -0700782 }
783
Jeff Brown8575a872010-06-30 16:10:35 -0700784 // See if this device has a gamepad.
785 for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES); i++) {
786 if (hasKeycode(device, GAMEPAD_KEYCODES[i])) {
787 device->classes |= INPUT_DEVICE_CLASS_GAMEPAD;
788 break;
789 }
790 }
791
Dianne Hackborn71c3eb22010-03-02 17:19:29 -0800792 LOGI("New keyboard: device->id=0x%x devname='%s' propName='%s' keylayout='%s'\n",
793 device->id, name, propName, keylayoutFilename);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800794 }
795
Dianne Hackbornc5917362009-08-04 05:49:43 -0700796 LOGI("New device: path=%s name=%s id=0x%x (of 0x%x) index=%d fd=%d classes=0x%x\n",
797 deviceName, name, device->id, mNumDevicesById, mFDCount, fd, device->classes);
798
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800799 LOGV("Adding device %s %p at %d, id = %d, classes = 0x%x\n",
800 deviceName, device, mFDCount, devid, device->classes);
801
802 mDevicesById[devid].device = device;
803 device->next = mOpeningDevices;
804 mOpeningDevices = device;
805 mDevices[mFDCount] = device;
806
807 mFDCount++;
808 return 0;
809}
810
Dianne Hackbornc5917362009-08-04 05:49:43 -0700811bool EventHub::hasKeycode(device_t* device, int keycode) const
812{
813 if (device->keyBitmask == NULL || device->layoutMap == NULL) {
814 return false;
815 }
816
817 Vector<int32_t> scanCodes;
818 device->layoutMap->findScancodes(keycode, &scanCodes);
819 const size_t N = scanCodes.size();
820 for (size_t i=0; i<N && i<=KEY_MAX; i++) {
821 int32_t sc = scanCodes.itemAt(i);
822 if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, device->keyBitmask)) {
823 return true;
824 }
825 }
826
827 return false;
828}
829
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800830int EventHub::close_device(const char *deviceName)
831{
832 AutoMutex _l(mLock);
833
834 int i;
835 for(i = 1; i < mFDCount; i++) {
836 if(strcmp(mDevices[i]->path.string(), deviceName) == 0) {
837 //LOGD("remove device %d: %s\n", i, deviceName);
838 device_t* device = mDevices[i];
Dianne Hackborn39bf9182009-09-01 19:01:50 -0700839
840 LOGI("Removed device: path=%s name=%s id=0x%x (of 0x%x) index=%d fd=%d classes=0x%x\n",
841 device->path.string(), device->name.string(), device->id,
842 mNumDevicesById, mFDCount, mFDs[i].fd, device->classes);
843
844 // Clear this device's entry.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800845 int index = (device->id&ID_MASK);
846 mDevicesById[index].device = NULL;
Dianne Hackborn39bf9182009-09-01 19:01:50 -0700847
848 // Close the file descriptor and compact the fd array.
Mike Lockwood07549f92009-08-28 13:29:06 -0700849 close(mFDs[i].fd);
Dianne Hackborn39bf9182009-09-01 19:01:50 -0700850 int count = mFDCount - i - 1;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800851 memmove(mDevices + i, mDevices + i + 1, sizeof(mDevices[0]) * count);
852 memmove(mFDs + i, mFDs + i + 1, sizeof(mFDs[0]) * count);
Dianne Hackborn39bf9182009-09-01 19:01:50 -0700853 mFDCount--;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800854
855#ifdef EV_SW
856 for (int j=0; j<EV_SW; j++) {
857 if (mSwitches[j] == device->id) {
858 mSwitches[j] = 0;
859 }
860 }
861#endif
862
863 device->next = mClosingDevices;
864 mClosingDevices = device;
865
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800866 if (device->id == mFirstKeyboardId) {
867 LOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this",
868 device->path.string(), mFirstKeyboardId);
869 mFirstKeyboardId = 0;
Dianne Hackborn71c3eb22010-03-02 17:19:29 -0800870 property_set("hw.keyboards.0.devname", NULL);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800871 }
872 // clear the property
873 char propName[100];
Dianne Hackborn71c3eb22010-03-02 17:19:29 -0800874 sprintf(propName, "hw.keyboards.%u.devname", device->id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800875 property_set(propName, NULL);
876 return 0;
877 }
878 }
Dianne Hackborn39bf9182009-09-01 19:01:50 -0700879 LOGE("remove device: %s not found\n", deviceName);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800880 return -1;
881}
882
883int EventHub::read_notify(int nfd)
884{
885#ifdef HAVE_INOTIFY
886 int res;
887 char devname[PATH_MAX];
888 char *filename;
889 char event_buf[512];
890 int event_size;
891 int event_pos = 0;
892 struct inotify_event *event;
893
Dianne Hackborn39bf9182009-09-01 19:01:50 -0700894 LOGV("EventHub::read_notify nfd: %d\n", nfd);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800895 res = read(nfd, event_buf, sizeof(event_buf));
896 if(res < (int)sizeof(*event)) {
897 if(errno == EINTR)
898 return 0;
899 LOGW("could not get event, %s\n", strerror(errno));
900 return 1;
901 }
902 //printf("got %d bytes of event information\n", res);
903
904 strcpy(devname, device_path);
905 filename = devname + strlen(devname);
906 *filename++ = '/';
907
908 while(res >= (int)sizeof(*event)) {
909 event = (struct inotify_event *)(event_buf + event_pos);
910 //printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : "");
911 if(event->len) {
912 strcpy(filename, event->name);
913 if(event->mask & IN_CREATE) {
914 open_device(devname);
915 }
916 else {
917 close_device(devname);
918 }
919 }
920 event_size = sizeof(*event) + event->len;
921 res -= event_size;
922 event_pos += event_size;
923 }
924#endif
925 return 0;
926}
927
928
929int EventHub::scan_dir(const char *dirname)
930{
931 char devname[PATH_MAX];
932 char *filename;
933 DIR *dir;
934 struct dirent *de;
935 dir = opendir(dirname);
936 if(dir == NULL)
937 return -1;
938 strcpy(devname, dirname);
939 filename = devname + strlen(devname);
940 *filename++ = '/';
941 while((de = readdir(dir))) {
942 if(de->d_name[0] == '.' &&
943 (de->d_name[1] == '\0' ||
944 (de->d_name[1] == '.' && de->d_name[2] == '\0')))
945 continue;
946 strcpy(filename, de->d_name);
947 open_device(devname);
948 }
949 closedir(dir);
950 return 0;
951}
952
953}; // namespace android