EventHub.cpp revision 80fd47ce75253dcdc2cfa85d7a3f42634b923a47
1/* 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// Handle events, like key input and vsync. 19// 20// The goal is to provide an optimized solution for Linux, not an 21// implementation that works well across all platforms. We expect 22// events to arrive on file descriptors, so that we can use a select() 23// select() call to sleep. 24// 25// We can't select() on anything but network sockets in Windows, so we 26// provide an alternative implementation of waitEvent for that platform. 27// 28#define LOG_TAG "EventHub" 29 30//#define LOG_NDEBUG 0 31 32#include "EventHub.h" 33 34#include <hardware_legacy/power.h> 35 36#include <cutils/properties.h> 37#include <utils/Log.h> 38#include <utils/Timers.h> 39#include <utils/threads.h> 40#include <utils/Errors.h> 41 42#include <stdlib.h> 43#include <stdio.h> 44#include <unistd.h> 45#include <fcntl.h> 46#include <memory.h> 47#include <errno.h> 48#include <assert.h> 49 50#include <ui/KeyLayoutMap.h> 51#include <ui/KeyCharacterMap.h> 52#include <ui/VirtualKeyMap.h> 53 54#include <string.h> 55#include <stdint.h> 56#include <dirent.h> 57#ifdef HAVE_INOTIFY 58# include <sys/inotify.h> 59#endif 60#ifdef HAVE_ANDROID_OS 61# include <sys/limits.h> /* not part of Linux */ 62#endif 63#include <sys/poll.h> 64#include <sys/ioctl.h> 65 66/* this macro is used to tell if "bit" is set in "array" 67 * it selects a byte from the array, and does a boolean AND 68 * operation with a byte that only has the relevant bit set. 69 * eg. to check for the 12th bit, we do (array[1] & 1<<4) 70 */ 71#define test_bit(bit, array) (array[bit/8] & (1<<(bit%8))) 72 73/* this macro computes the number of bytes needed to represent a bit array of the specified size */ 74#define sizeof_bit_array(bits) ((bits + 7) / 8) 75 76// Fd at index 0 is always reserved for inotify 77#define FIRST_ACTUAL_DEVICE_INDEX 1 78 79#define INDENT " " 80#define INDENT2 " " 81#define INDENT3 " " 82 83namespace android { 84 85static const char *WAKE_LOCK_ID = "KeyEvents"; 86static const char *DEVICE_PATH = "/dev/input"; 87 88/* return the larger integer */ 89static inline int max(int v1, int v2) 90{ 91 return (v1 > v2) ? v1 : v2; 92} 93 94static inline const char* toString(bool value) { 95 return value ? "true" : "false"; 96} 97 98// --- EventHub::Device --- 99 100EventHub::Device::Device(int fd, int32_t id, const String8& path, 101 const InputDeviceIdentifier& identifier) : 102 next(NULL), 103 fd(fd), id(id), path(path), identifier(identifier), 104 classes(0), keyBitmask(NULL), relBitmask(NULL), propBitmask(NULL), 105 configuration(NULL), virtualKeyMap(NULL) { 106} 107 108EventHub::Device::~Device() { 109 close(); 110 delete[] keyBitmask; 111 delete[] relBitmask; 112 delete[] propBitmask; 113 delete configuration; 114 delete virtualKeyMap; 115} 116 117void EventHub::Device::close() { 118 if (fd >= 0) { 119 ::close(fd); 120 fd = -1; 121 } 122} 123 124 125// --- EventHub --- 126 127EventHub::EventHub(void) : 128 mError(NO_INIT), mBuiltInKeyboardId(-1), mNextDeviceId(1), 129 mOpeningDevices(0), mClosingDevices(0), 130 mOpened(false), mNeedToSendFinishedDeviceScan(false), 131 mInputFdIndex(1) { 132 acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); 133 134 memset(mSwitches, 0, sizeof(mSwitches)); 135 mNumCpus = sysconf(_SC_NPROCESSORS_ONLN); 136} 137 138EventHub::~EventHub(void) { 139 release_wake_lock(WAKE_LOCK_ID); 140 // we should free stuff here... 141} 142 143status_t EventHub::errorCheck() const { 144 return mError; 145} 146 147String8 EventHub::getDeviceName(int32_t deviceId) const { 148 AutoMutex _l(mLock); 149 Device* device = getDeviceLocked(deviceId); 150 if (device == NULL) return String8(); 151 return device->identifier.name; 152} 153 154uint32_t EventHub::getDeviceClasses(int32_t deviceId) const { 155 AutoMutex _l(mLock); 156 Device* device = getDeviceLocked(deviceId); 157 if (device == NULL) return 0; 158 return device->classes; 159} 160 161void EventHub::getConfiguration(int32_t deviceId, PropertyMap* outConfiguration) const { 162 AutoMutex _l(mLock); 163 Device* device = getDeviceLocked(deviceId); 164 if (device && device->configuration) { 165 *outConfiguration = *device->configuration; 166 } else { 167 outConfiguration->clear(); 168 } 169} 170 171status_t EventHub::getAbsoluteAxisInfo(int32_t deviceId, int axis, 172 RawAbsoluteAxisInfo* outAxisInfo) const { 173 outAxisInfo->clear(); 174 175 AutoMutex _l(mLock); 176 Device* device = getDeviceLocked(deviceId); 177 if (device == NULL) return -1; 178 179 struct input_absinfo info; 180 181 if(ioctl(device->fd, EVIOCGABS(axis), &info)) { 182 LOGW("Error reading absolute controller %d for device %s fd %d\n", 183 axis, device->identifier.name.string(), device->fd); 184 return -errno; 185 } 186 187 if (info.minimum != info.maximum) { 188 outAxisInfo->valid = true; 189 outAxisInfo->minValue = info.minimum; 190 outAxisInfo->maxValue = info.maximum; 191 outAxisInfo->flat = info.flat; 192 outAxisInfo->fuzz = info.fuzz; 193 } 194 return OK; 195} 196 197bool EventHub::hasRelativeAxis(int32_t deviceId, int axis) const { 198 if (axis >= 0 && axis <= REL_MAX) { 199 AutoMutex _l(mLock); 200 201 Device* device = getDeviceLocked(deviceId); 202 if (device && device->relBitmask) { 203 return test_bit(axis, device->relBitmask); 204 } 205 } 206 return false; 207} 208 209bool EventHub::hasInputProperty(int32_t deviceId, int property) const { 210 if (property >= 0 && property <= INPUT_PROP_MAX) { 211 AutoMutex _l(mLock); 212 213 Device* device = getDeviceLocked(deviceId); 214 if (device && device->propBitmask) { 215 return test_bit(property, device->propBitmask); 216 } 217 } 218 return false; 219} 220 221int32_t EventHub::getScanCodeState(int32_t deviceId, int32_t scanCode) const { 222 if (scanCode >= 0 && scanCode <= KEY_MAX) { 223 AutoMutex _l(mLock); 224 225 Device* device = getDeviceLocked(deviceId); 226 if (device != NULL) { 227 return getScanCodeStateLocked(device, scanCode); 228 } 229 } 230 return AKEY_STATE_UNKNOWN; 231} 232 233int32_t EventHub::getScanCodeStateLocked(Device* device, int32_t scanCode) const { 234 uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)]; 235 memset(key_bitmask, 0, sizeof(key_bitmask)); 236 if (ioctl(device->fd, 237 EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) { 238 return test_bit(scanCode, key_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP; 239 } 240 return AKEY_STATE_UNKNOWN; 241} 242 243int32_t EventHub::getKeyCodeState(int32_t deviceId, int32_t keyCode) const { 244 AutoMutex _l(mLock); 245 246 Device* device = getDeviceLocked(deviceId); 247 if (device != NULL) { 248 return getKeyCodeStateLocked(device, keyCode); 249 } 250 return AKEY_STATE_UNKNOWN; 251} 252 253int32_t EventHub::getKeyCodeStateLocked(Device* device, int32_t keyCode) const { 254 if (!device->keyMap.haveKeyLayout()) { 255 return AKEY_STATE_UNKNOWN; 256 } 257 258 Vector<int32_t> scanCodes; 259 device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes); 260 261 uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)]; 262 memset(key_bitmask, 0, sizeof(key_bitmask)); 263 if (ioctl(device->fd, EVIOCGKEY(sizeof(key_bitmask)), key_bitmask) >= 0) { 264 #if 0 265 for (size_t i=0; i<=KEY_MAX; i++) { 266 LOGI("(Scan code %d: down=%d)", i, test_bit(i, key_bitmask)); 267 } 268 #endif 269 const size_t N = scanCodes.size(); 270 for (size_t i=0; i<N && i<=KEY_MAX; i++) { 271 int32_t sc = scanCodes.itemAt(i); 272 //LOGI("Code %d: down=%d", sc, test_bit(sc, key_bitmask)); 273 if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, key_bitmask)) { 274 return AKEY_STATE_DOWN; 275 } 276 } 277 return AKEY_STATE_UP; 278 } 279 return AKEY_STATE_UNKNOWN; 280} 281 282int32_t EventHub::getSwitchState(int32_t deviceId, int32_t sw) const { 283 if (sw >= 0 && sw <= SW_MAX) { 284 AutoMutex _l(mLock); 285 286 Device* device = getDeviceLocked(deviceId); 287 if (device != NULL) { 288 return getSwitchStateLocked(device, sw); 289 } 290 } 291 return AKEY_STATE_UNKNOWN; 292} 293 294int32_t EventHub::getSwitchStateLocked(Device* device, int32_t sw) const { 295 uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)]; 296 memset(sw_bitmask, 0, sizeof(sw_bitmask)); 297 if (ioctl(device->fd, 298 EVIOCGSW(sizeof(sw_bitmask)), sw_bitmask) >= 0) { 299 return test_bit(sw, sw_bitmask) ? AKEY_STATE_DOWN : AKEY_STATE_UP; 300 } 301 return AKEY_STATE_UNKNOWN; 302} 303 304bool EventHub::markSupportedKeyCodes(int32_t deviceId, size_t numCodes, 305 const int32_t* keyCodes, uint8_t* outFlags) const { 306 AutoMutex _l(mLock); 307 308 Device* device = getDeviceLocked(deviceId); 309 if (device != NULL) { 310 return markSupportedKeyCodesLocked(device, numCodes, keyCodes, outFlags); 311 } 312 return false; 313} 314 315bool EventHub::markSupportedKeyCodesLocked(Device* device, size_t numCodes, 316 const int32_t* keyCodes, uint8_t* outFlags) const { 317 if (!device->keyMap.haveKeyLayout() || !device->keyBitmask) { 318 return false; 319 } 320 321 Vector<int32_t> scanCodes; 322 for (size_t codeIndex = 0; codeIndex < numCodes; codeIndex++) { 323 scanCodes.clear(); 324 325 status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey( 326 keyCodes[codeIndex], &scanCodes); 327 if (! err) { 328 // check the possible scan codes identified by the layout map against the 329 // map of codes actually emitted by the driver 330 for (size_t sc = 0; sc < scanCodes.size(); sc++) { 331 if (test_bit(scanCodes[sc], device->keyBitmask)) { 332 outFlags[codeIndex] = 1; 333 break; 334 } 335 } 336 } 337 } 338 return true; 339} 340 341status_t EventHub::mapKey(int32_t deviceId, int scancode, 342 int32_t* outKeycode, uint32_t* outFlags) const 343{ 344 AutoMutex _l(mLock); 345 Device* device = getDeviceLocked(deviceId); 346 347 if (device && device->keyMap.haveKeyLayout()) { 348 status_t err = device->keyMap.keyLayoutMap->mapKey(scancode, outKeycode, outFlags); 349 if (err == NO_ERROR) { 350 return NO_ERROR; 351 } 352 } 353 354 if (mBuiltInKeyboardId != -1) { 355 device = getDeviceLocked(mBuiltInKeyboardId); 356 357 if (device && device->keyMap.haveKeyLayout()) { 358 status_t err = device->keyMap.keyLayoutMap->mapKey(scancode, outKeycode, outFlags); 359 if (err == NO_ERROR) { 360 return NO_ERROR; 361 } 362 } 363 } 364 365 *outKeycode = 0; 366 *outFlags = 0; 367 return NAME_NOT_FOUND; 368} 369 370status_t EventHub::mapAxis(int32_t deviceId, int scancode, AxisInfo* outAxisInfo) const 371{ 372 AutoMutex _l(mLock); 373 Device* device = getDeviceLocked(deviceId); 374 375 if (device && device->keyMap.haveKeyLayout()) { 376 status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxisInfo); 377 if (err == NO_ERROR) { 378 return NO_ERROR; 379 } 380 } 381 382 if (mBuiltInKeyboardId != -1) { 383 device = getDeviceLocked(mBuiltInKeyboardId); 384 385 if (device && device->keyMap.haveKeyLayout()) { 386 status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxisInfo); 387 if (err == NO_ERROR) { 388 return NO_ERROR; 389 } 390 } 391 } 392 393 return NAME_NOT_FOUND; 394} 395 396void EventHub::addExcludedDevice(const char* deviceName) 397{ 398 AutoMutex _l(mLock); 399 400 String8 name(deviceName); 401 mExcludedDevices.push_back(name); 402} 403 404bool EventHub::hasLed(int32_t deviceId, int32_t led) const { 405 AutoMutex _l(mLock); 406 Device* device = getDeviceLocked(deviceId); 407 if (device) { 408 uint8_t bitmask[sizeof_bit_array(LED_MAX + 1)]; 409 memset(bitmask, 0, sizeof(bitmask)); 410 if (ioctl(device->fd, EVIOCGBIT(EV_LED, sizeof(bitmask)), bitmask) >= 0) { 411 if (test_bit(led, bitmask)) { 412 return true; 413 } 414 } 415 } 416 return false; 417} 418 419void EventHub::setLedState(int32_t deviceId, int32_t led, bool on) { 420 AutoMutex _l(mLock); 421 Device* device = getDeviceLocked(deviceId); 422 if (device) { 423 struct input_event ev; 424 ev.time.tv_sec = 0; 425 ev.time.tv_usec = 0; 426 ev.type = EV_LED; 427 ev.code = led; 428 ev.value = on ? 1 : 0; 429 430 ssize_t nWrite; 431 do { 432 nWrite = write(device->fd, &ev, sizeof(struct input_event)); 433 } while (nWrite == -1 && errno == EINTR); 434 } 435} 436 437void EventHub::getVirtualKeyDefinitions(int32_t deviceId, 438 Vector<VirtualKeyDefinition>& outVirtualKeys) const { 439 outVirtualKeys.clear(); 440 441 AutoMutex _l(mLock); 442 Device* device = getDeviceLocked(deviceId); 443 if (device && device->virtualKeyMap) { 444 outVirtualKeys.appendVector(device->virtualKeyMap->getVirtualKeys()); 445 } 446} 447 448EventHub::Device* EventHub::getDeviceLocked(int32_t deviceId) const { 449 if (deviceId == 0) { 450 deviceId = mBuiltInKeyboardId; 451 } 452 453 size_t numDevices = mDevices.size(); 454 for (size_t i = FIRST_ACTUAL_DEVICE_INDEX; i < numDevices; i++) { 455 Device* device = mDevices[i]; 456 if (device->id == deviceId) { 457 return device; 458 } 459 } 460 return NULL; 461} 462 463size_t EventHub::getEvents(int timeoutMillis, RawEvent* buffer, size_t bufferSize) { 464 // Note that we only allow one caller to getEvents(), so don't need 465 // to do locking here... only when adding/removing devices. 466 LOG_ASSERT(bufferSize >= 1); 467 468 if (!mOpened) { 469 mError = openPlatformInput() ? NO_ERROR : UNKNOWN_ERROR; 470 mOpened = true; 471 mNeedToSendFinishedDeviceScan = true; 472 } 473 474 struct input_event readBuffer[bufferSize]; 475 476 RawEvent* event = buffer; 477 size_t capacity = bufferSize; 478 for (;;) { 479 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); 480 481 // Report any devices that had last been added/removed. 482 while (mClosingDevices) { 483 Device* device = mClosingDevices; 484 LOGV("Reporting device closed: id=%d, name=%s\n", 485 device->id, device->path.string()); 486 mClosingDevices = device->next; 487 event->when = now; 488 event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id; 489 event->type = DEVICE_REMOVED; 490 event += 1; 491 delete device; 492 mNeedToSendFinishedDeviceScan = true; 493 if (--capacity == 0) { 494 break; 495 } 496 } 497 498 while (mOpeningDevices != NULL) { 499 Device* device = mOpeningDevices; 500 LOGV("Reporting device opened: id=%d, name=%s\n", 501 device->id, device->path.string()); 502 mOpeningDevices = device->next; 503 event->when = now; 504 event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id; 505 event->type = DEVICE_ADDED; 506 event += 1; 507 mNeedToSendFinishedDeviceScan = true; 508 if (--capacity == 0) { 509 break; 510 } 511 } 512 513 if (mNeedToSendFinishedDeviceScan) { 514 mNeedToSendFinishedDeviceScan = false; 515 event->when = now; 516 event->type = FINISHED_DEVICE_SCAN; 517 event += 1; 518 if (--capacity == 0) { 519 break; 520 } 521 } 522 523 // Grab the next input event. 524 // mInputFdIndex is initially 1 because index 0 is used for inotify. 525 bool deviceWasRemoved = false; 526 while (mInputFdIndex < mFds.size()) { 527 const struct pollfd& pfd = mFds[mInputFdIndex]; 528 if (pfd.revents & POLLIN) { 529 int32_t readSize = read(pfd.fd, readBuffer, sizeof(struct input_event) * capacity); 530 if (readSize < 0) { 531 if (errno == ENODEV) { 532 deviceWasRemoved = true; 533 break; 534 } 535 if (errno != EAGAIN && errno != EINTR) { 536 LOGW("could not get event (errno=%d)", errno); 537 } 538 } else if ((readSize % sizeof(struct input_event)) != 0) { 539 LOGE("could not get event (wrong size: %d)", readSize); 540 } else if (readSize == 0) { // eof 541 deviceWasRemoved = true; 542 break; 543 } else { 544 const Device* device = mDevices[mInputFdIndex]; 545 int32_t deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id; 546 547 size_t count = size_t(readSize) / sizeof(struct input_event); 548 for (size_t i = 0; i < count; i++) { 549 const struct input_event& iev = readBuffer[i]; 550 LOGV("%s got: t0=%d, t1=%d, type=%d, code=%d, value=%d", 551 device->path.string(), 552 (int) iev.time.tv_sec, (int) iev.time.tv_usec, 553 iev.type, iev.code, iev.value); 554 555#ifdef HAVE_POSIX_CLOCKS 556 // Use the time specified in the event instead of the current time 557 // so that downstream code can get more accurate estimates of 558 // event dispatch latency from the time the event is enqueued onto 559 // the evdev client buffer. 560 // 561 // The event's timestamp fortuitously uses the same monotonic clock 562 // time base as the rest of Android. The kernel event device driver 563 // (drivers/input/evdev.c) obtains timestamps using ktime_get_ts(). 564 // The systemTime(SYSTEM_TIME_MONOTONIC) function we use everywhere 565 // calls clock_gettime(CLOCK_MONOTONIC) which is implemented as a 566 // system call that also queries ktime_get_ts(). 567 event->when = nsecs_t(iev.time.tv_sec) * 1000000000LL 568 + nsecs_t(iev.time.tv_usec) * 1000LL; 569 LOGV("event time %lld, now %lld", event->when, now); 570#else 571 event->when = now; 572#endif 573 event->deviceId = deviceId; 574 event->type = iev.type; 575 event->scanCode = iev.code; 576 event->value = iev.value; 577 event->keyCode = AKEYCODE_UNKNOWN; 578 event->flags = 0; 579 if (iev.type == EV_KEY && device->keyMap.haveKeyLayout()) { 580 status_t err = device->keyMap.keyLayoutMap->mapKey(iev.code, 581 &event->keyCode, &event->flags); 582 LOGV("iev.code=%d keyCode=%d flags=0x%08x err=%d\n", 583 iev.code, event->keyCode, event->flags, err); 584 } 585 event += 1; 586 } 587 capacity -= count; 588 if (capacity == 0) { 589 break; 590 } 591 } 592 } 593 mInputFdIndex += 1; 594 } 595 596 // Handle the case where a device has been removed but INotify has not yet noticed. 597 if (deviceWasRemoved) { 598 AutoMutex _l(mLock); 599 closeDeviceAtIndexLocked(mInputFdIndex); 600 continue; // report added or removed devices immediately 601 } 602 603#if HAVE_INOTIFY 604 // readNotify() will modify mFDs and mFDCount, so this must be done after 605 // processing all other events. 606 if(mFds[0].revents & POLLIN) { 607 readNotify(mFds[0].fd); 608 mFds.editItemAt(0).revents = 0; 609 mInputFdIndex = mFds.size(); 610 continue; // report added or removed devices immediately 611 } 612#endif 613 614 // Return now if we have collected any events, otherwise poll. 615 if (event != buffer) { 616 break; 617 } 618 619 // Poll for events. Mind the wake lock dance! 620 // We hold a wake lock at all times except during poll(). This works due to some 621 // subtle choreography. When a device driver has pending (unread) events, it acquires 622 // a kernel wake lock. However, once the last pending event has been read, the device 623 // driver will release the kernel wake lock. To prevent the system from going to sleep 624 // when this happens, the EventHub holds onto its own user wake lock while the client 625 // is processing events. Thus the system can only sleep if there are no events 626 // pending or currently being processed. 627 // 628 // The timeout is advisory only. If the device is asleep, it will not wake just to 629 // service the timeout. 630 release_wake_lock(WAKE_LOCK_ID); 631 632 int pollResult = poll(mFds.editArray(), mFds.size(), timeoutMillis); 633 634 acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID); 635 636 if (pollResult == 0) { 637 break; // timed out 638 } 639 if (pollResult < 0) { 640 // Sleep after errors to avoid locking up the system. 641 // Hopefully the error is transient. 642 if (errno != EINTR) { 643 LOGW("poll failed (errno=%d)\n", errno); 644 usleep(100000); 645 } 646 } else { 647 // On an SMP system, it is possible for the framework to read input events 648 // faster than the kernel input device driver can produce a complete packet. 649 // Because poll() wakes up as soon as the first input event becomes available, 650 // the framework will often end up reading one event at a time until the 651 // packet is complete. Instead of one call to read() returning 71 events, 652 // it could take 71 calls to read() each returning 1 event. 653 // 654 // Sleep for a short period of time after waking up from the poll() to give 655 // the kernel time to finish writing the entire packet of input events. 656 if (mNumCpus > 1) { 657 usleep(250); 658 } 659 } 660 661 // Prepare to process all of the FDs we just polled. 662 mInputFdIndex = 1; 663 } 664 665 // All done, return the number of events we read. 666 return event - buffer; 667} 668 669/* 670 * Open the platform-specific input device. 671 */ 672bool EventHub::openPlatformInput(void) { 673 /* 674 * Open platform-specific input device(s). 675 */ 676 int res, fd; 677 678#ifdef HAVE_INOTIFY 679 fd = inotify_init(); 680 res = inotify_add_watch(fd, DEVICE_PATH, IN_DELETE | IN_CREATE); 681 if(res < 0) { 682 LOGE("could not add watch for %s, %s\n", DEVICE_PATH, strerror(errno)); 683 } 684#else 685 /* 686 * The code in EventHub::getEvent assumes that mFDs[0] is an inotify fd. 687 * We allocate space for it and set it to something invalid. 688 */ 689 fd = -1; 690#endif 691 692 // Reserve fd index 0 for inotify. 693 struct pollfd pollfd; 694 pollfd.fd = fd; 695 pollfd.events = POLLIN; 696 pollfd.revents = 0; 697 mFds.push(pollfd); 698 mDevices.push(NULL); 699 700 res = scanDir(DEVICE_PATH); 701 if(res < 0) { 702 LOGE("scan dir failed for %s\n", DEVICE_PATH); 703 } 704 705 return true; 706} 707 708// ---------------------------------------------------------------------------- 709 710static bool containsNonZeroByte(const uint8_t* array, uint32_t startIndex, uint32_t endIndex) { 711 const uint8_t* end = array + endIndex; 712 array += startIndex; 713 while (array != end) { 714 if (*(array++) != 0) { 715 return true; 716 } 717 } 718 return false; 719} 720 721static const int32_t GAMEPAD_KEYCODES[] = { 722 AKEYCODE_BUTTON_A, AKEYCODE_BUTTON_B, AKEYCODE_BUTTON_C, 723 AKEYCODE_BUTTON_X, AKEYCODE_BUTTON_Y, AKEYCODE_BUTTON_Z, 724 AKEYCODE_BUTTON_L1, AKEYCODE_BUTTON_R1, 725 AKEYCODE_BUTTON_L2, AKEYCODE_BUTTON_R2, 726 AKEYCODE_BUTTON_THUMBL, AKEYCODE_BUTTON_THUMBR, 727 AKEYCODE_BUTTON_START, AKEYCODE_BUTTON_SELECT, AKEYCODE_BUTTON_MODE, 728 AKEYCODE_BUTTON_1, AKEYCODE_BUTTON_2, AKEYCODE_BUTTON_3, AKEYCODE_BUTTON_4, 729 AKEYCODE_BUTTON_5, AKEYCODE_BUTTON_6, AKEYCODE_BUTTON_7, AKEYCODE_BUTTON_8, 730 AKEYCODE_BUTTON_9, AKEYCODE_BUTTON_10, AKEYCODE_BUTTON_11, AKEYCODE_BUTTON_12, 731 AKEYCODE_BUTTON_13, AKEYCODE_BUTTON_14, AKEYCODE_BUTTON_15, AKEYCODE_BUTTON_16, 732}; 733 734int EventHub::openDevice(const char *devicePath) { 735 char buffer[80]; 736 737 LOGV("Opening device: %s", devicePath); 738 739 AutoMutex _l(mLock); 740 741 int fd = open(devicePath, O_RDWR); 742 if(fd < 0) { 743 LOGE("could not open %s, %s\n", devicePath, strerror(errno)); 744 return -1; 745 } 746 747 InputDeviceIdentifier identifier; 748 749 // Get device name. 750 if(ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) { 751 //fprintf(stderr, "could not get device name for %s, %s\n", devicePath, strerror(errno)); 752 } else { 753 buffer[sizeof(buffer) - 1] = '\0'; 754 identifier.name.setTo(buffer); 755 } 756 757 // Check to see if the device is on our excluded list 758 List<String8>::iterator iter = mExcludedDevices.begin(); 759 List<String8>::iterator end = mExcludedDevices.end(); 760 for ( ; iter != end; iter++) { 761 const char* test = *iter; 762 if (identifier.name == test) { 763 LOGI("ignoring event id %s driver %s\n", devicePath, test); 764 close(fd); 765 return -1; 766 } 767 } 768 769 // Get device driver version. 770 int driverVersion; 771 if(ioctl(fd, EVIOCGVERSION, &driverVersion)) { 772 LOGE("could not get driver version for %s, %s\n", devicePath, strerror(errno)); 773 close(fd); 774 return -1; 775 } 776 777 // Get device identifier. 778 struct input_id inputId; 779 if(ioctl(fd, EVIOCGID, &inputId)) { 780 LOGE("could not get device input id for %s, %s\n", devicePath, strerror(errno)); 781 close(fd); 782 return -1; 783 } 784 identifier.bus = inputId.bustype; 785 identifier.product = inputId.product; 786 identifier.vendor = inputId.vendor; 787 identifier.version = inputId.version; 788 789 // Get device physical location. 790 if(ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { 791 //fprintf(stderr, "could not get location for %s, %s\n", devicePath, strerror(errno)); 792 } else { 793 buffer[sizeof(buffer) - 1] = '\0'; 794 identifier.location.setTo(buffer); 795 } 796 797 // Get device unique id. 798 if(ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) { 799 //fprintf(stderr, "could not get idstring for %s, %s\n", devicePath, strerror(errno)); 800 } else { 801 buffer[sizeof(buffer) - 1] = '\0'; 802 identifier.uniqueId.setTo(buffer); 803 } 804 805 // Make file descriptor non-blocking for use with poll(). 806 if (fcntl(fd, F_SETFL, O_NONBLOCK)) { 807 LOGE("Error %d making device file descriptor non-blocking.", errno); 808 close(fd); 809 return -1; 810 } 811 812 // Allocate device. (The device object takes ownership of the fd at this point.) 813 int32_t deviceId = mNextDeviceId++; 814 Device* device = new Device(fd, deviceId, String8(devicePath), identifier); 815 816#if 0 817 LOGI("add device %d: %s\n", deviceId, devicePath); 818 LOGI(" bus: %04x\n" 819 " vendor %04x\n" 820 " product %04x\n" 821 " version %04x\n", 822 identifier.bus, identifier.vendor, identifier.product, identifier.version); 823 LOGI(" name: \"%s\"\n", identifier.name.string()); 824 LOGI(" location: \"%s\"\n", identifier.location.string()); 825 LOGI(" unique id: \"%s\"\n", identifier.uniqueId.string()); 826 LOGI(" driver: v%d.%d.%d\n", 827 driverVersion >> 16, (driverVersion >> 8) & 0xff, driverVersion & 0xff); 828#endif 829 830 // Load the configuration file for the device. 831 loadConfiguration(device); 832 833 // Figure out the kinds of events the device reports. 834 uint8_t key_bitmask[sizeof_bit_array(KEY_MAX + 1)]; 835 memset(key_bitmask, 0, sizeof(key_bitmask)); 836 ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask); 837 838 uint8_t abs_bitmask[sizeof_bit_array(ABS_MAX + 1)]; 839 memset(abs_bitmask, 0, sizeof(abs_bitmask)); 840 ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bitmask)), abs_bitmask); 841 842 uint8_t rel_bitmask[sizeof_bit_array(REL_MAX + 1)]; 843 memset(rel_bitmask, 0, sizeof(rel_bitmask)); 844 ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask); 845 846 uint8_t sw_bitmask[sizeof_bit_array(SW_MAX + 1)]; 847 memset(sw_bitmask, 0, sizeof(sw_bitmask)); 848 ioctl(fd, EVIOCGBIT(EV_SW, sizeof(sw_bitmask)), sw_bitmask); 849 850 uint8_t prop_bitmask[sizeof_bit_array(INPUT_PROP_MAX + 1)]; 851 memset(prop_bitmask, 0, sizeof(prop_bitmask)); 852 ioctl(fd, EVIOCGPROP(sizeof(prop_bitmask)), prop_bitmask); 853 854 device->keyBitmask = new uint8_t[sizeof(key_bitmask)]; 855 device->relBitmask = new uint8_t[sizeof(rel_bitmask)]; 856 device->propBitmask = new uint8_t[sizeof(prop_bitmask)]; 857 858 if (!device->keyBitmask || !device->relBitmask || !device->propBitmask) { 859 delete device; 860 LOGE("out of memory allocating bitmasks"); 861 return -1; 862 } 863 864 memcpy(device->keyBitmask, key_bitmask, sizeof(key_bitmask)); 865 memcpy(device->relBitmask, rel_bitmask, sizeof(rel_bitmask)); 866 memcpy(device->propBitmask, prop_bitmask, sizeof(prop_bitmask)); 867 868 // See if this is a keyboard. Ignore everything in the button range except for 869 // joystick and gamepad buttons which are handled like keyboards for the most part. 870 bool haveKeyboardKeys = containsNonZeroByte(key_bitmask, 0, sizeof_bit_array(BTN_MISC)) 871 || containsNonZeroByte(key_bitmask, sizeof_bit_array(KEY_OK), 872 sizeof_bit_array(KEY_MAX + 1)); 873 bool haveGamepadButtons = containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_MISC), 874 sizeof_bit_array(BTN_MOUSE)) 875 || containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_JOYSTICK), 876 sizeof_bit_array(BTN_DIGI)); 877 if (haveKeyboardKeys || haveGamepadButtons) { 878 device->classes |= INPUT_DEVICE_CLASS_KEYBOARD; 879 } 880 881 // See if this is a cursor device such as a trackball or mouse. 882 if (test_bit(BTN_MOUSE, key_bitmask) 883 && test_bit(REL_X, rel_bitmask) 884 && test_bit(REL_Y, rel_bitmask)) { 885 device->classes |= INPUT_DEVICE_CLASS_CURSOR; 886 } 887 888 // See if this is a touch pad. 889 // Is this a new modern multi-touch driver? 890 if (test_bit(ABS_MT_POSITION_X, abs_bitmask) 891 && test_bit(ABS_MT_POSITION_Y, abs_bitmask)) { 892 // Some joysticks such as the PS3 controller report axes that conflict 893 // with the ABS_MT range. Try to confirm that the device really is 894 // a touch screen. 895 if (test_bit(BTN_TOUCH, key_bitmask) || !haveGamepadButtons) { 896 device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT; 897 } 898 // Is this an old style single-touch driver? 899 } else if (test_bit(BTN_TOUCH, key_bitmask) 900 && test_bit(ABS_X, abs_bitmask) 901 && test_bit(ABS_Y, abs_bitmask)) { 902 device->classes |= INPUT_DEVICE_CLASS_TOUCH; 903 } 904 905 // See if this device is a joystick. 906 // Ignore touchscreens because they use the same absolute axes for other purposes. 907 // Assumes that joysticks always have gamepad buttons in order to distinguish them 908 // from other devices such as accelerometers that also have absolute axes. 909 if (haveGamepadButtons 910 && !(device->classes & INPUT_DEVICE_CLASS_TOUCH) 911 && containsNonZeroByte(abs_bitmask, 0, sizeof_bit_array(ABS_MAX + 1))) { 912 device->classes |= INPUT_DEVICE_CLASS_JOYSTICK; 913 } 914 915 // figure out the switches this device reports 916 bool haveSwitches = false; 917 for (int i=0; i<EV_SW; i++) { 918 //LOGI("Device %d sw %d: has=%d", device->id, i, test_bit(i, sw_bitmask)); 919 if (test_bit(i, sw_bitmask)) { 920 haveSwitches = true; 921 if (mSwitches[i] == 0) { 922 mSwitches[i] = device->id; 923 } 924 } 925 } 926 if (haveSwitches) { 927 device->classes |= INPUT_DEVICE_CLASS_SWITCH; 928 } 929 930 if ((device->classes & INPUT_DEVICE_CLASS_TOUCH)) { 931 // Load the virtual keys for the touch screen, if any. 932 // We do this now so that we can make sure to load the keymap if necessary. 933 status_t status = loadVirtualKeyMap(device); 934 if (!status) { 935 device->classes |= INPUT_DEVICE_CLASS_KEYBOARD; 936 } 937 } 938 939 // Load the key map. 940 // We need to do this for joysticks too because the key layout may specify axes. 941 status_t keyMapStatus = NAME_NOT_FOUND; 942 if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) { 943 // Load the keymap for the device. 944 keyMapStatus = loadKeyMap(device); 945 } 946 947 // Configure the keyboard, gamepad or virtual keyboard. 948 if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) { 949 // Set system properties for the keyboard. 950 setKeyboardProperties(device, false); 951 952 // Register the keyboard as a built-in keyboard if it is eligible. 953 if (!keyMapStatus 954 && mBuiltInKeyboardId == -1 955 && isEligibleBuiltInKeyboard(device->identifier, 956 device->configuration, &device->keyMap)) { 957 mBuiltInKeyboardId = device->id; 958 setKeyboardProperties(device, true); 959 } 960 961 // 'Q' key support = cheap test of whether this is an alpha-capable kbd 962 if (hasKeycodeLocked(device, AKEYCODE_Q)) { 963 device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY; 964 } 965 966 // See if this device has a DPAD. 967 if (hasKeycodeLocked(device, AKEYCODE_DPAD_UP) && 968 hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) && 969 hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) && 970 hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) && 971 hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) { 972 device->classes |= INPUT_DEVICE_CLASS_DPAD; 973 } 974 975 // See if this device has a gamepad. 976 for (size_t i = 0; i < sizeof(GAMEPAD_KEYCODES)/sizeof(GAMEPAD_KEYCODES[0]); i++) { 977 if (hasKeycodeLocked(device, GAMEPAD_KEYCODES[i])) { 978 device->classes |= INPUT_DEVICE_CLASS_GAMEPAD; 979 break; 980 } 981 } 982 } 983 984 // If the device isn't recognized as something we handle, don't monitor it. 985 if (device->classes == 0) { 986 LOGV("Dropping device: id=%d, path='%s', name='%s'", 987 deviceId, devicePath, device->identifier.name.string()); 988 delete device; 989 return -1; 990 } 991 992 // Determine whether the device is external or internal. 993 if (isExternalDevice(device)) { 994 device->classes |= INPUT_DEVICE_CLASS_EXTERNAL; 995 } 996 997 LOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, " 998 "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s", 999 deviceId, fd, devicePath, device->identifier.name.string(), 1000 device->classes, 1001 device->configurationFile.string(), 1002 device->keyMap.keyLayoutFile.string(), 1003 device->keyMap.keyCharacterMapFile.string(), 1004 toString(mBuiltInKeyboardId == deviceId)); 1005 1006 struct pollfd pollfd; 1007 pollfd.fd = fd; 1008 pollfd.events = POLLIN; 1009 pollfd.revents = 0; 1010 mFds.push(pollfd); 1011 mDevices.push(device); 1012 1013 device->next = mOpeningDevices; 1014 mOpeningDevices = device; 1015 return 0; 1016} 1017 1018void EventHub::loadConfiguration(Device* device) { 1019 device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier( 1020 device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION); 1021 if (device->configurationFile.isEmpty()) { 1022 LOGD("No input device configuration file found for device '%s'.", 1023 device->identifier.name.string()); 1024 } else { 1025 status_t status = PropertyMap::load(device->configurationFile, 1026 &device->configuration); 1027 if (status) { 1028 LOGE("Error loading input device configuration file for device '%s'. " 1029 "Using default configuration.", 1030 device->identifier.name.string()); 1031 } 1032 } 1033} 1034 1035status_t EventHub::loadVirtualKeyMap(Device* device) { 1036 // The virtual key map is supplied by the kernel as a system board property file. 1037 String8 path; 1038 path.append("/sys/board_properties/virtualkeys."); 1039 path.append(device->identifier.name); 1040 if (access(path.string(), R_OK)) { 1041 return NAME_NOT_FOUND; 1042 } 1043 return VirtualKeyMap::load(path, &device->virtualKeyMap); 1044} 1045 1046status_t EventHub::loadKeyMap(Device* device) { 1047 return device->keyMap.load(device->identifier, device->configuration); 1048} 1049 1050void EventHub::setKeyboardProperties(Device* device, bool builtInKeyboard) { 1051 int32_t id = builtInKeyboard ? 0 : device->id; 1052 android::setKeyboardProperties(id, device->identifier, 1053 device->keyMap.keyLayoutFile, device->keyMap.keyCharacterMapFile); 1054} 1055 1056void EventHub::clearKeyboardProperties(Device* device, bool builtInKeyboard) { 1057 int32_t id = builtInKeyboard ? 0 : device->id; 1058 android::clearKeyboardProperties(id); 1059} 1060 1061bool EventHub::isExternalDevice(Device* device) { 1062 if (device->configuration) { 1063 bool value; 1064 if (device->configuration->tryGetProperty(String8("device.internal"), value) 1065 && value) { 1066 return false; 1067 } 1068 } 1069 return device->identifier.bus == BUS_USB || device->identifier.bus == BUS_BLUETOOTH; 1070} 1071 1072bool EventHub::hasKeycodeLocked(Device* device, int keycode) const { 1073 if (!device->keyMap.haveKeyLayout() || !device->keyBitmask) { 1074 return false; 1075 } 1076 1077 Vector<int32_t> scanCodes; 1078 device->keyMap.keyLayoutMap->findScanCodesForKey(keycode, &scanCodes); 1079 const size_t N = scanCodes.size(); 1080 for (size_t i=0; i<N && i<=KEY_MAX; i++) { 1081 int32_t sc = scanCodes.itemAt(i); 1082 if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, device->keyBitmask)) { 1083 return true; 1084 } 1085 } 1086 1087 return false; 1088} 1089 1090int EventHub::closeDevice(const char *devicePath) { 1091 AutoMutex _l(mLock); 1092 1093 for (size_t i = FIRST_ACTUAL_DEVICE_INDEX; i < mDevices.size(); i++) { 1094 Device* device = mDevices[i]; 1095 if (device->path == devicePath) { 1096 return closeDeviceAtIndexLocked(i); 1097 } 1098 } 1099 LOGV("Remove device: %s not found, device may already have been removed.", devicePath); 1100 return -1; 1101} 1102 1103int EventHub::closeDeviceAtIndexLocked(int index) { 1104 Device* device = mDevices[index]; 1105 LOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x\n", 1106 device->path.string(), device->identifier.name.string(), device->id, 1107 device->fd, device->classes); 1108 1109 for (int j=0; j<EV_SW; j++) { 1110 if (mSwitches[j] == device->id) { 1111 mSwitches[j] = 0; 1112 } 1113 } 1114 1115 if (device->id == mBuiltInKeyboardId) { 1116 LOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this", 1117 device->path.string(), mBuiltInKeyboardId); 1118 mBuiltInKeyboardId = -1; 1119 clearKeyboardProperties(device, true); 1120 } 1121 clearKeyboardProperties(device, false); 1122 1123 mFds.removeAt(index); 1124 mDevices.removeAt(index); 1125 device->close(); 1126 1127 // Unlink for opening devices list if it is present. 1128 Device* pred = NULL; 1129 bool found = false; 1130 for (Device* entry = mOpeningDevices; entry != NULL; ) { 1131 if (entry == device) { 1132 found = true; 1133 break; 1134 } 1135 pred = entry; 1136 entry = entry->next; 1137 } 1138 if (found) { 1139 // Unlink the device from the opening devices list then delete it. 1140 // We don't need to tell the client that the device was closed because 1141 // it does not even know it was opened in the first place. 1142 LOGI("Device %s was immediately closed after opening.", device->path.string()); 1143 if (pred) { 1144 pred->next = device->next; 1145 } else { 1146 mOpeningDevices = device->next; 1147 } 1148 delete device; 1149 } else { 1150 // Link into closing devices list. 1151 // The device will be deleted later after we have informed the client. 1152 device->next = mClosingDevices; 1153 mClosingDevices = device; 1154 } 1155 return 0; 1156} 1157 1158int EventHub::readNotify(int nfd) { 1159#ifdef HAVE_INOTIFY 1160 int res; 1161 char devname[PATH_MAX]; 1162 char *filename; 1163 char event_buf[512]; 1164 int event_size; 1165 int event_pos = 0; 1166 struct inotify_event *event; 1167 1168 LOGV("EventHub::readNotify nfd: %d\n", nfd); 1169 res = read(nfd, event_buf, sizeof(event_buf)); 1170 if(res < (int)sizeof(*event)) { 1171 if(errno == EINTR) 1172 return 0; 1173 LOGW("could not get event, %s\n", strerror(errno)); 1174 return 1; 1175 } 1176 //printf("got %d bytes of event information\n", res); 1177 1178 strcpy(devname, DEVICE_PATH); 1179 filename = devname + strlen(devname); 1180 *filename++ = '/'; 1181 1182 while(res >= (int)sizeof(*event)) { 1183 event = (struct inotify_event *)(event_buf + event_pos); 1184 //printf("%d: %08x \"%s\"\n", event->wd, event->mask, event->len ? event->name : ""); 1185 if(event->len) { 1186 strcpy(filename, event->name); 1187 if(event->mask & IN_CREATE) { 1188 openDevice(devname); 1189 } 1190 else { 1191 closeDevice(devname); 1192 } 1193 } 1194 event_size = sizeof(*event) + event->len; 1195 res -= event_size; 1196 event_pos += event_size; 1197 } 1198#endif 1199 return 0; 1200} 1201 1202int EventHub::scanDir(const char *dirname) 1203{ 1204 char devname[PATH_MAX]; 1205 char *filename; 1206 DIR *dir; 1207 struct dirent *de; 1208 dir = opendir(dirname); 1209 if(dir == NULL) 1210 return -1; 1211 strcpy(devname, dirname); 1212 filename = devname + strlen(devname); 1213 *filename++ = '/'; 1214 while((de = readdir(dir))) { 1215 if(de->d_name[0] == '.' && 1216 (de->d_name[1] == '\0' || 1217 (de->d_name[1] == '.' && de->d_name[2] == '\0'))) 1218 continue; 1219 strcpy(filename, de->d_name); 1220 openDevice(devname); 1221 } 1222 closedir(dir); 1223 return 0; 1224} 1225 1226void EventHub::dump(String8& dump) { 1227 dump.append("Event Hub State:\n"); 1228 1229 { // acquire lock 1230 AutoMutex _l(mLock); 1231 1232 dump.appendFormat(INDENT "BuiltInKeyboardId: %d\n", mBuiltInKeyboardId); 1233 1234 dump.append(INDENT "Devices:\n"); 1235 1236 for (size_t i = FIRST_ACTUAL_DEVICE_INDEX; i < mDevices.size(); i++) { 1237 const Device* device = mDevices[i]; 1238 if (device) { 1239 if (mBuiltInKeyboardId == device->id) { 1240 dump.appendFormat(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n", 1241 device->id, device->identifier.name.string()); 1242 } else { 1243 dump.appendFormat(INDENT2 "%d: %s\n", device->id, 1244 device->identifier.name.string()); 1245 } 1246 dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes); 1247 dump.appendFormat(INDENT3 "Path: %s\n", device->path.string()); 1248 dump.appendFormat(INDENT3 "Location: %s\n", device->identifier.location.string()); 1249 dump.appendFormat(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string()); 1250 dump.appendFormat(INDENT3 "Identifier: bus=0x%04x, vendor=0x%04x, " 1251 "product=0x%04x, version=0x%04x\n", 1252 device->identifier.bus, device->identifier.vendor, 1253 device->identifier.product, device->identifier.version); 1254 dump.appendFormat(INDENT3 "KeyLayoutFile: %s\n", 1255 device->keyMap.keyLayoutFile.string()); 1256 dump.appendFormat(INDENT3 "KeyCharacterMapFile: %s\n", 1257 device->keyMap.keyCharacterMapFile.string()); 1258 dump.appendFormat(INDENT3 "ConfigurationFile: %s\n", 1259 device->configurationFile.string()); 1260 } 1261 } 1262 } // release lock 1263} 1264 1265}; // namespace android 1266