Lines Matching refs:device

97     // Compute a device descriptor that uniquely identifies the device.
107 // If we don't know the vendor and product id, then the device is probably
109 // the input device. Usually we try to avoid relying on the device name or
110 // location but for built-in input device, they are unlikely to ever change.
245 Device* device = mClosingDevices;
246 mClosingDevices = device->next;
247 delete device;
260 Device* device = getDeviceLocked(deviceId);
261 if (device == NULL) return InputDeviceIdentifier();
262 return device->identifier;
267 Device* device = getDeviceLocked(deviceId);
268 if (device == NULL) return 0;
269 return device->classes;
274 Device* device = getDeviceLocked(deviceId);
275 if (device == NULL) return 0;
276 return device->controllerNumber;
281 Device* device = getDeviceLocked(deviceId);
282 if (device && device->configuration) {
283 *outConfiguration = *device->configuration;
296 Device* device = getDeviceLocked(deviceId);
297 if (device && !device->isVirtual() && test_bit(axis, device->absBitmask)) {
299 if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
300 ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
301 axis, device->identifier.name.string(), device->fd, errno);
323 Device* device = getDeviceLocked(deviceId);
324 if (device) {
325 return test_bit(axis, device->relBitmask);
335 Device* device = getDeviceLocked(deviceId);
336 if (device) {
337 return test_bit(property, device->propBitmask);
347 Device* device = getDeviceLocked(deviceId);
348 if (device && !device->isVirtual() && test_bit(scanCode, device->keyBitmask)) {
351 if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
362 Device* device = getDeviceLocked(deviceId);
363 if (device && !device->isVirtual() && device->keyMap.haveKeyLayout()) {
365 device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes);
369 if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
387 Device* device = getDeviceLocked(deviceId);
388 if (device && !device->isVirtual() && test_bit(sw, device->swBitmask)) {
391 if (ioctl(device->fd, EVIOCGSW(sizeof(swState)), swState) >= 0) {
405 Device* device = getDeviceLocked(deviceId);
406 if (device && !device->isVirtual() && test_bit(axis, device->absBitmask)) {
408 if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
409 ALOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
410 axis, device->identifier.name.string(), device->fd, errno);
425 Device* device = getDeviceLocked(deviceId);
426 if (device && device->keyMap.haveKeyLayout()) {
431 status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey(
437 if (test_bit(scanCodes[sc], device->keyBitmask)) {
452 Device* device = getDeviceLocked(deviceId);
454 if (device) {
456 sp<KeyCharacterMap> kcm = device->getKeyCharacterMap();
465 if (device->keyMap.haveKeyLayout()) {
466 if (!device->keyMap.keyLayoutMap->mapKey(
480 Device* device = getDeviceLocked(deviceId);
482 if (device && device->keyMap.haveKeyLayout()) {
483 status_t err = device->keyMap.keyLayoutMap->mapAxis(scanCode, outAxisInfo);
500 Device* device = getDeviceLocked(deviceId);
501 if (device && scanCode >= 0 && scanCode <= KEY_MAX) {
502 if (test_bit(scanCode, device->keyBitmask)) {
511 Device* device = getDeviceLocked(deviceId);
512 if (device && led >= 0 && led <= LED_MAX) {
513 if (test_bit(led, device->ledBitmask)) {
522 Device* device = getDeviceLocked(deviceId);
523 if (device && !device->isVirtual() && led >= 0 && led <= LED_MAX) {
533 nWrite = write(device->fd, &ev, sizeof(struct input_event));
543 Device* device = getDeviceLocked(deviceId);
544 if (device && device->virtualKeyMap) {
545 outVirtualKeys.appendVector(device->virtualKeyMap->getVirtualKeys());
551 Device* device = getDeviceLocked(deviceId);
552 if (device) {
553 return device->getKeyCharacterMap();
561 Device* device = getDeviceLocked(deviceId);
562 if (device) {
563 if (map != device->overlayKeyMap) {
564 device->overlayKeyMap = map;
565 device->combinedKeyMap = KeyCharacterMap::combine(
566 device->keyMap.keyCharacterMap, map);
575 Device* device = getDeviceLocked(deviceId);
576 if (device && !device->isVirtual()) {
580 effect.id = device->ffEffectId;
585 if (ioctl(device->fd, EVIOCSFF, &effect)) {
586 ALOGW("Could not upload force feedback effect to device %s due to error %d.",
587 device->identifier.name.string(), errno);
590 device->ffEffectId = effect.id;
596 ev.code = device->ffEffectId;
598 if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) {
599 ALOGW("Could not start force feedback effect on device %s due to error %d.",
600 device->identifier.name.string(), errno);
603 device->ffEffectPlaying = true;
609 Device* device = getDeviceLocked(deviceId);
610 if (device && !device->isVirtual()) {
611 if (device->ffEffectPlaying) {
612 device->ffEffectPlaying = false;
618 ev.code = device->ffEffectId;
620 if (write(device->fd, &ev, sizeof(ev)) != sizeof(ev)) {
621 ALOGW("Could not stop force feedback effect on device %s due to error %d.",
622 device->identifier.name.string(), errno);
639 Device* device = mDevices.valueAt(i);
640 if (device->path == devicePath) {
641 return device;
673 Device* device = mClosingDevices;
674 ALOGV("Reporting device closed: id=%d, name=%s\n",
675 device->id, device->path.string());
676 mClosingDevices = device->next;
678 event->deviceId = device->id == mBuiltInKeyboardId ? BUILT_IN_KEYBOARD_ID : device->id;
681 delete device;
695 Device* device = mOpeningDevices;
696 ALOGV("Reporting device opened: id=%d, name=%s\n",
697 device->id, device->path.string());
698 mOpeningDevices = device->next;
700 event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
750 ALOGW("Received unexpected epoll event 0x%08x for unknown device id %d.",
755 Device* device = mDevices.valueAt(deviceIndex);
757 int32_t readSize = read(device->fd, readBuffer,
763 device->fd, readSize, bufferSize, capacity, errno);
765 closeDeviceLocked(device);
773 int32_t deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
779 device->path.string(),
787 // mainly intended for use with uinput based device drivers.
790 device->timestampOverrideSec = iev.value;
793 device->timestampOverrideUsec = iev.value;
797 if (device->timestampOverrideSec || device->timestampOverrideUsec) {
798 iev.time.tv_sec = device->timestampOverrideSec;
799 iev.time.tv_usec = device->timestampOverrideUsec;
801 device->timestampOverrideSec = 0;
802 device->timestampOverrideUsec = 0;
815 // time base as the rest of Android. The kernel event device driver
828 // This can happen because when the input device is initially opened
830 // enqueued right after the device is opened will have timestamps
848 device->path.string(), event->when, time, now);
869 // so we will try to read the device again on the next iteration.
875 ALOGI("Removing device %s due to epoll hang-up event.",
876 device->identifier.name.string());
878 closeDeviceLocked(device);
880 ALOGW("Received unexpected epoll event 0x%08x for device %s.",
881 eventItem.events, device->identifier.name.string());
906 // subtle choreography. When a device driver has pending (unread) events, it acquires
907 // a kernel wake lock. However, once the last pending event has been read, the device
913 // The timeout is advisory only. If the device is asleep, it will not wake just to
1003 ALOGV("Opening device: %s", devicePath);
1013 // Get device name.
1015 //fprintf(stderr, "could not get device name for %s, %s\n", devicePath, strerror(errno));
1021 // Check to see if the device is on our excluded list
1031 // Get device driver version.
1039 // Get device identifier.
1042 ALOGE("could not get device input id for %s, %s\n", devicePath, strerror(errno));
1051 // Get device physical location.
1059 // Get device unique id.
1072 ALOGE("Error %d making device file descriptor non-blocking.", errno);
1077 // Allocate device. (The device object takes ownership of the fd at this point.)
1079 Device* device = new Device(fd, deviceId, String8(devicePath), identifier);
1081 ALOGV("add device %d: %s\n", deviceId, devicePath);
1094 // Load the configuration file for the device.
1095 loadConfigurationLocked(device);
1097 // Figure out the kinds of events the device reports.
1098 ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(device->keyBitmask)), device->keyBitmask);
1099 ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(device->absBitmask)), device->absBitmask);
1100 ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask);
1101 ioctl(fd, EVIOCGBIT(EV_SW, sizeof(device->swBitmask)), device->swBitmask);
1102 ioctl(fd, EVIOCGBIT(EV_LED, sizeof(device->ledBitmask)), device->ledBitmask);
1103 ioctl(fd, EVIOCGBIT(EV_FF, sizeof(device->ffBitmask)), device->ffBitmask);
1104 ioctl(fd, EVIOCGPROP(sizeof(device->propBitmask)), device->propBitmask);
1108 bool haveKeyboardKeys = containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC))
1109 || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(KEY_OK),
1111 bool haveGamepadButtons = containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_MISC),
1113 || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_JOYSTICK),
1116 device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
1119 // See if this is a cursor device such as a trackball or mouse.
1120 if (test_bit(BTN_MOUSE, device->keyBitmask)
1121 && test_bit(REL_X, device->relBitmask)
1122 && test_bit(REL_Y, device->relBitmask)) {
1123 device->classes |= INPUT_DEVICE_CLASS_CURSOR;
1128 if (test_bit(ABS_MT_POSITION_X, device->absBitmask)
1129 && test_bit(ABS_MT_POSITION_Y, device->absBitmask)) {
1131 // with the ABS_MT range. Try to confirm that the device really is
1133 if (test_bit(BTN_TOUCH, device->keyBitmask) || !haveGamepadButtons) {
1134 device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
1137 } else if (test_bit(BTN_TOUCH, device->keyBitmask)
1138 && test_bit(ABS_X, device->absBitmask)
1139 && test_bit(ABS_Y, device->absBitmask)) {
1140 device->classes |= INPUT_DEVICE_CLASS_TOUCH;
1143 // See if this device is a joystick.
1147 uint32_t assumedClasses = device->classes | INPUT_DEVICE_CLASS_JOYSTICK;
1149 if (test_bit(i, device->absBitmask)
1151 device->classes = assumedClasses;
1157 // Check whether this device has switches.
1159 if (test_bit(i, device->swBitmask)) {
1160 device->classes |= INPUT_DEVICE_CLASS_SWITCH;
1165 // Check whether this device supports the vibrator.
1166 if (test_bit(FF_RUMBLE, device->ffBitmask)) {
1167 device->classes |= INPUT_DEVICE_CLASS_VIBRATOR;
1171 if ((device->classes & INPUT_DEVICE_CLASS_TOUCH)) {
1174 status_t status = loadVirtualKeyMapLocked(device);
1176 device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
1183 if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) {
1184 // Load the keymap for the device.
1185 keyMapStatus = loadKeyMapLocked(device);
1189 if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) {
1193 && isEligibleBuiltInKeyboard(device->identifier,
1194 device->configuration, &device->keyMap)) {
1195 mBuiltInKeyboardId = device->id;
1199 if (hasKeycodeLocked(device, AKEYCODE_Q)) {
1200 device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
1203 // See if this device has a DPAD.
1204 if (hasKeycodeLocked(device, AKEYCODE_DPAD_UP) &&
1205 hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) &&
1206 hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) &&
1207 hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) &&
1208 hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) {
1209 device->classes |= INPUT_DEVICE_CLASS_DPAD;
1212 // See if this device has a gamepad.
1214 if (hasKeycodeLocked(device, GAMEPAD_KEYCODES[i])) {
1215 device->classes |= INPUT_DEVICE_CLASS_GAMEPAD;
1227 // If the device isn't recognized as something we handle, don't monitor it.
1228 if (device->classes == 0) {
1229 ALOGV("Dropping device: id=%d, path='%s', name='%s'",
1230 deviceId, devicePath, device->identifier.name.string());
1231 delete device;
1235 // Determine whether the device is external or internal.
1236 if (isExternalDeviceLocked(device)) {
1237 device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
1240 if (device->classes & (INPUT_DEVICE_CLASS_JOYSTICK | INPUT_DEVICE_CLASS_GAMEPAD)) {
1241 device->controllerNumber = getNextControllerNumberLocked(device);
1250 ALOGE("Could not add device fd to epoll instance. errno=%d", errno);
1251 delete device;
1277 ALOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, "
1280 deviceId, fd, devicePath, device->identifier.name.string(),
1281 device->classes,
1282 device->configurationFile.string(),
1283 device->keyMap.keyLayoutFile.string(),
1284 device->keyMap.keyCharacterMapFile.string(),
1288 addDeviceLocked(device);
1298 Device* device = new Device(-1, VIRTUAL_KEYBOARD_ID, String8("<virtual>"), identifier);
1299 device->classes = INPUT_DEVICE_CLASS_KEYBOARD
1303 loadKeyMapLocked(device);
1304 addDeviceLocked(device);
1307 void EventHub::addDeviceLocked(Device* device) {
1308 mDevices.add(device->id, device);
1309 device->next = mOpeningDevices;
1310 mOpeningDevices = device;
1313 void EventHub::loadConfigurationLocked(Device* device) {
1314 device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(
1315 device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);
1316 if (device->configurationFile.isEmpty()) {
1317 ALOGD("No input device configuration file found for device '%s'.",
1318 device->identifier.name.string());
1320 status_t status = PropertyMap::load(device->configurationFile,
1321 &device->configuration);
1323 ALOGE("Error loading input device configuration file for device '%s'. "
1325 device->identifier.name.string());
1330 status_t EventHub::loadVirtualKeyMapLocked(Device* device) {
1334 path.append(device->identifier.name);
1338 return VirtualKeyMap::load(path, &device->virtualKeyMap);
1341 status_t EventHub::loadKeyMapLocked(Device* device) {
1342 return device->keyMap.load(device->identifier, device->configuration);
1345 bool EventHub::isExternalDeviceLocked(Device* device) {
1346 if (device->configuration) {
1348 if (device->configuration->tryGetProperty(String8("device.internal"), value)) {
1352 return device->identifier.bus == BUS_USB || device->identifier.bus == BUS_BLUETOOTH;
1355 int32_t EventHub::getNextControllerNumberLocked(Device* device) {
1357 ALOGI("Maximum number of controllers reached, assigning controller number 0 to device %s",
1358 device->identifier.name.string());
1366 void EventHub::releaseControllerNumberLocked(Device* device) {
1367 int32_t num = device->controllerNumber;
1368 device->controllerNumber= 0;
1376 bool EventHub::hasKeycodeLocked(Device* device, int keycode) const {
1377 if (!device->keyMap.haveKeyLayout() || !device->keyBitmask) {
1382 device->keyMap.keyLayoutMap->findScanCodesForKey(keycode, &scanCodes);
1386 if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, device->keyBitmask)) {
1395 Device* device = getDeviceByPathLocked(devicePath);
1396 if (device) {
1397 closeDeviceLocked(device);
1400 ALOGV("Remove device: %s not found, device may already have been removed.", devicePath);
1410 void EventHub::closeDeviceLocked(Device* device) {
1411 ALOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x\n",
1412 device->path.string(), device->identifier.name.string(), device->id,
1413 device->fd, device->classes);
1415 if (device->id == mBuiltInKeyboardId) {
1416 ALOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this",
1417 device->path.string(), mBuiltInKeyboardId);
1421 if (!device->isVirtual()) {
1422 if (epoll_ctl(mEpollFd, EPOLL_CTL_DEL, device->fd, NULL)) {
1423 ALOGW("Could not remove device fd from epoll instance. errno=%d", errno);
1427 releaseControllerNumberLocked(device);
1429 mDevices.removeItem(device->id);
1430 device->close();
1436 if (entry == device) {
1444 // Unlink the device from the opening devices list then delete it.
1445 // We don't need to tell the client that the device was closed because
1447 ALOGI("Device %s was immediately closed after opening.", device->path.string());
1449 pred->next = device->next;
1451 mOpeningDevices = device->next;
1453 delete device;
1456 // The device will be deleted later after we have informed the client.
1457 device->next = mClosingDevices;
1458 mClosingDevices = device;
1493 ALOGI("Removing device '%s' due to inotify event\n", devname);
1546 const Device* device = mDevices.valueAt(i);
1547 if (mBuiltInKeyboardId == device->id) {
1548 dump.appendFormat(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n",
1549 device->id, device->identifier.name.string());
1551 dump.appendFormat(INDENT2 "%d: %s\n", device->id,
1552 device->identifier.name.string());
1554 dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes);
1555 dump.appendFormat(INDENT3 "Path: %s\n", device->path.string());
1556 dump.appendFormat(INDENT3 "Descriptor: %s\n", device->identifier.descriptor.string());
1557 dump.appendFormat(INDENT3 "Location: %s\n", device->identifier.location.string());
1558 dump.appendFormat(INDENT3 "ControllerNumber: %d\n", device->controllerNumber);
1559 dump.appendFormat(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string());
1562 device->identifier.bus, device->identifier.vendor,
1563 device->identifier.product, device->identifier.version);
1565 device->keyMap.keyLayoutFile.string());
1567 device->keyMap.keyCharacterMapFile.string());
1569 device->configurationFile.string());
1571 toString(device->overlayKeyMap != NULL));