Home | History | Annotate | Download | only in input

Lines Matching full:device

115 // --- EventHub::Device ---
117 EventHub::Device::Device(int fd, int32_t id, const String8& path,
130 EventHub::Device::~Device() {
136 void EventHub::Device::close() {
201 Device* device = mClosingDevices;
202 mClosingDevices = device->next;
203 delete device;
216 Device* device = getDeviceLocked(deviceId);
217 if (device == NULL) return String8();
218 return device->identifier.name;
223 Device* device = getDeviceLocked(deviceId);
224 if (device == NULL) return 0;
225 return device->classes;
230 Device* device = getDeviceLocked(deviceId);
231 if (device && device->configuration) {
232 *outConfiguration = *device->configuration;
245 Device* device = getDeviceLocked(deviceId);
246 if (device && test_bit(axis, device->absBitmask)) {
248 if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
249 LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
250 axis, device->identifier.name.string(), device->fd, errno);
272 Device* device = getDeviceLocked(deviceId);
273 if (device) {
274 return test_bit(axis, device->relBitmask);
284 Device* device = getDeviceLocked(deviceId);
285 if (device) {
286 return test_bit(property, device->propBitmask);
296 Device* device = getDeviceLocked(deviceId);
297 if (device && test_bit(scanCode, device->keyBitmask)) {
300 if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
311 Device* device = getDeviceLocked(deviceId);
312 if (device && device->keyMap.haveKeyLayout()) {
314 device->keyMap.keyLayoutMap->findScanCodesForKey(keyCode, &scanCodes);
318 if (ioctl(device->fd, EVIOCGKEY(sizeof(keyState)), keyState) >= 0) {
336 Device* device = getDeviceLocked(deviceId);
337 if (device && test_bit(sw, device->swBitmask)) {
340 if (ioctl(device->fd, EVIOCGSW(sizeof(swState)), swState) >= 0) {
354 Device* device = getDeviceLocked(deviceId);
355 if (device && test_bit(axis, device->absBitmask)) {
357 if(ioctl(device->fd, EVIOCGABS(axis), &info)) {
358 LOGW("Error reading absolute controller %d for device %s fd %d, errno=%d",
359 axis, device->identifier.name.string(), device->fd, errno);
374 Device* device = getDeviceLocked(deviceId);
375 if (device && device->keyMap.haveKeyLayout()) {
380 status_t err = device->keyMap.keyLayoutMap->findScanCodesForKey(
386 if (test_bit(scanCodes[sc], device->keyBitmask)) {
402 Device* device = getDeviceLocked(deviceId);
404 if (device && device->keyMap.haveKeyLayout()) {
405 status_t err = device->keyMap.keyLayoutMap->mapKey(scancode, outKeycode, outFlags);
412 device = getDeviceLocked(mBuiltInKeyboardId);
414 if (device && device->keyMap.haveKeyLayout()) {
415 status_t err = device->keyMap.keyLayoutMap->mapKey(scancode, outKeycode, outFlags);
430 Device* device = getDeviceLocked(deviceId);
432 if (device && device->keyMap.haveKeyLayout()) {
433 status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxisInfo);
440 device = getDeviceLocked(mBuiltInKeyboardId);
442 if (device && device->keyMap.haveKeyLayout()) {
443 status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxisInfo);
461 Device* device = getDeviceLocked(deviceId);
462 if (device && scanCode >= 0 && scanCode <= KEY_MAX) {
463 if (test_bit(scanCode, device->keyBitmask)) {
472 Device* device = getDeviceLocked(deviceId);
473 if (device && led >= 0 && led <= LED_MAX) {
474 if (test_bit(led, device->ledBitmask)) {
483 Device* device = getDeviceLocked(deviceId);
484 if (device && led >= 0 && led <= LED_MAX) {
494 nWrite = write(device->fd, &ev, sizeof(struct input_event));
504 Device* device = getDeviceLocked(deviceId);
505 if (device && device->virtualKeyMap) {
506 outVirtualKeys.appendVector(device->virtualKeyMap->getVirtualKeys());
510 EventHub::Device* EventHub::getDeviceLocked(int32_t deviceId) const {
518 EventHub::Device* EventHub::getDeviceByPathLocked(const char* devicePath) const {
520 Device* device = mDevices.valueAt(i);
521 if (device->path == devicePath) {
522 return device;
554 Device* device = mClosingDevices;
555 LOGV("Reporting device closed: id=%d, name=%s\n",
556 device->id, device->path.string());
557 mClosingDevices = device->next;
559 event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
562 delete device;
576 Device* device = mOpeningDevices;
577 LOGV("Reporting device opened: id=%d, name=%s\n",
578 device->id, device->path.string());
579 mOpeningDevices = device->next;
581 event->deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
631 LOGW("Received unexpected epoll event 0x%08x for unknown device id %d.",
636 Device* device = mDevices.valueAt(deviceIndex);
638 int32_t readSize = read(device->fd, readBuffer,
641 // Device was removed before INotify noticed.
643 device->fd, readSize, bufferSize, capacity, errno);
645 closeDeviceLocked(device);
653 int32_t deviceId = device->id == mBuiltInKeyboardId ? 0 : device->id;
659 device->path.string(),
670 // time base as the rest of Android. The kernel event device driver
687 if (iev.type == EV_KEY && device->keyMap.haveKeyLayout()) {
688 status_t err = device->keyMap.keyLayoutMap->mapKey(iev.code,
698 // so we will try to read the device again on the next iteration.
704 LOGW("Received unexpected epoll event 0x%08x for device %s.",
705 eventItem.events, device->identifier.name.string());
730 // subtle choreography. When a device driver has pending (unread) events, it acquires
731 // a kernel wake lock. However, once the last pending event has been read, the device
737 // The timeout is advisory only. If the device is asleep, it will not wake just to
770 // faster than the kernel input device driver can produce a complete packet.
837 LOGV("Opening device: %s", devicePath);
847 // Get device name.
849 //fprintf(stderr, "could not get device name for %s, %s\n", devicePath, strerror(errno));
855 // Check to see if the device is on our excluded list
865 // Get device driver version.
873 // Get device identifier.
876 LOGE("could not get device input id for %s, %s\n", devicePath, strerror(errno));
885 // Get device physical location.
893 // Get device unique id.
903 LOGE("Error %d making device file descriptor non-blocking.", errno);
908 // Allocate device. (The device object takes ownership of the fd at this point.)
910 Device* device = new Device(fd, deviceId, String8(devicePath), identifier);
913 LOGI("add device %d: %s\n", deviceId, devicePath);
926 // Load the configuration file for the device.
927 loadConfigurationLocked(device);
929 // Figure out the kinds of events the device reports.
930 ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(device->keyBitmask)), device->keyBitmask);
931 ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(devicedevice->absBitmask);
932 ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask);
933 ioctl(fd, EVIOCGBIT(EV_SW, sizeof(device->swBitmask)), device->swBitmask);
934 ioctl(fd, EVIOCGBIT(EV_LED, sizeof(device->ledBitmask)), device->ledBitmask);
935 ioctl(fd, EVIOCGPROP(sizeof(device->propBitmask)), device->propBitmask);
939 bool haveKeyboardKeys = containsNonZeroByte(device->keyBitmask, 0, sizeof_bit_array(BTN_MISC))
940 || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(KEY_OK),
942 bool haveGamepadButtons = containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_MISC),
944 || containsNonZeroByte(device->keyBitmask, sizeof_bit_array(BTN_JOYSTICK),
947 device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
950 // See if this is a cursor device such as a trackball or mouse.
951 if (test_bit(BTN_MOUSE, device->keyBitmask)
952 && test_bit(REL_X, device->relBitmask)
953 && test_bit(REL_Y, device->relBitmask)) {
954 device->classes |= INPUT_DEVICE_CLASS_CURSOR;
959 if (test_bit(ABS_MT_POSITION_X, device->absBitmask)
960 && test_bit(ABS_MT_POSITION_Y, device->absBitmask)) {
962 // with the ABS_MT range. Try to confirm that the device really is
964 if (test_bit(BTN_TOUCH, device->keyBitmask) || !haveGamepadButtons) {
965 device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
968 } else if (test_bit(BTN_TOUCH, device->keyBitmask)
969 && test_bit(ABS_X, device->absBitmask)
970 && test_bit(ABS_Y, device->absBitmask)) {
971 device->classes |= INPUT_DEVICE_CLASS_TOUCH;
974 // See if this device is a joystick.
978 uint32_t assumedClasses = device->classes | INPUT_DEVICE_CLASS_JOYSTICK;
980 if (test_bit(i, device->absBitmask)
982 device->classes = assumedClasses;
988 // Check whether this device has switches.
990 if (test_bit(i, device->swBitmask)) {
991 device->classes |= INPUT_DEVICE_CLASS_SWITCH;
997 if ((device->classes & INPUT_DEVICE_CLASS_TOUCH)) {
1000 status_t status = loadVirtualKeyMapLocked(device);
1002 device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
1009 if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) {
1010 // Load the keymap for the device.
1011 keyMapStatus = loadKeyMapLocked(device);
1015 if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) {
1017 setKeyboardPropertiesLocked(device, false);
1022 && isEligibleBuiltInKeyboard(device->identifier,
1023 device->configuration, &device->keyMap)) {
1024 mBuiltInKeyboardId = device->id;
1025 setKeyboardPropertiesLocked(device, true);
1029 if (hasKeycodeLocked(device, AKEYCODE_Q)) {
1030 device->classes |= INPUT_DEVICE_CLASS_ALPHAKEY;
1033 // See if this device has a DPAD.
1034 if (hasKeycodeLocked(device, AKEYCODE_DPAD_UP) &&
1035 hasKeycodeLocked(device, AKEYCODE_DPAD_DOWN) &&
1036 hasKeycodeLocked(device, AKEYCODE_DPAD_LEFT) &&
1037 hasKeycodeLocked(device, AKEYCODE_DPAD_RIGHT) &&
1038 hasKeycodeLocked(device, AKEYCODE_DPAD_CENTER)) {
1039 device->classes |= INPUT_DEVICE_CLASS_DPAD;
1042 // See if this device has a gamepad.
1044 if (hasKeycodeLocked(device, GAMEPAD_KEYCODES[i])) {
1045 device->classes |= INPUT_DEVICE_CLASS_GAMEPAD;
1051 // If the device isn't recognized as something we handle, don't monitor it.
1052 if (device->classes == 0) {
1053 LOGV("Dropping device: id=%d, path='%s', name='%s'",
1054 deviceId, devicePath, device->identifier.name.string());
1055 delete device;
1059 // Determine whether the device is external or internal.
1060 if (isExternalDeviceLocked(device)) {
1061 device->classes |= INPUT_DEVICE_CLASS_EXTERNAL;
1070 LOGE("Could not add device fd to epoll instance. errno=%d", errno);
1071 delete device;
1075 LOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, "
1077 deviceId, fd, devicePath, device->identifier.name.string(),
1078 device->classes,
1079 device->configurationFile.string(),
1080 device->keyMap.keyLayoutFile.string(),
1081 device->keyMap.keyCharacterMapFile.string(),
1084 mDevices.add(deviceId, device);
1086 device->next = mOpeningDevices;
1087 mOpeningDevices = device;
1091 void EventHub::loadConfigurationLocked(Device* device) {
1092 device->configurationFile = getInputDeviceConfigurationFilePathByDeviceIdentifier(
1093 device->identifier, INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION);
1094 if (device->configurationFile.isEmpty()) {
1095 LOGD("No input device configuration file found for device '%s'.",
1096 device->identifier.name.string());
1098 status_t status = PropertyMap::load(device->configurationFile,
1099 &device->configuration);
1101 LOGE("Error loading input device configuration file for device '%s'. "
1103 device->identifier.name.string());
1108 status_t EventHub::loadVirtualKeyMapLocked(Device* device) {
1112 path.append(device->identifier.name);
1116 return VirtualKeyMap::load(path, &device->virtualKeyMap);
1119 status_t EventHub::loadKeyMapLocked(Device* device) {
1120 return device->keyMap.load(device->identifier, device->configuration);
1123 void EventHub::setKeyboardPropertiesLocked(Device* device, bool builtInKeyboard) {
1124 int32_t id = builtInKeyboard ? 0 : device->id;
1125 android::setKeyboardProperties(id, device->identifier,
1126 device->keyMap.keyLayoutFile, device->keyMap.keyCharacterMapFile);
1129 void EventHub::clearKeyboardPropertiesLocked(Device* device, bool builtInKeyboard) {
1130 int32_t id = builtInKeyboard ? 0 : device->id;
1134 bool EventHub::isExternalDeviceLocked(Device* device) {
1135 if (device->configuration) {
1137 if (device->configuration->tryGetProperty(String8("device.internal"), value)) {
1141 return device->identifier.bus == BUS_USB || device->identifier.bus == BUS_BLUETOOTH;
1144 bool EventHub::hasKeycodeLocked(Device* device, int keycode) const {
1145 if (!device->keyMap.haveKeyLayout() || !device->keyBitmask) {
1150 device->keyMap.keyLayoutMap->findScanCodesForKey(keycode, &scanCodes);
1154 if (sc >= 0 && sc <= KEY_MAX && test_bit(sc, device->keyBitmask)) {
1163 Device* device = getDeviceByPathLocked(devicePath);
1164 if (device) {
1165 closeDeviceLocked(device);
1168 LOGV("Remove device: %s not found, device may already have been removed.", devicePath);
1178 void EventHub::closeDeviceLocked(Device* device) {
1179 LOGI("Removed device: path=%s name=%s id=%d fd=%d classes=0x%x\n",
1180 device->path.string(), device->identifier.name.string(), device->id,
1181 device->fd, device->classes);
1183 if (device->id == mBuiltInKeyboardId) {
1184 LOGW("built-in keyboard device %s (id=%d) is closing! the apps will not like this",
1185 device->path.string(), mBuiltInKeyboardId);
1187 clearKeyboardPropertiesLocked(device, true);
1189 clearKeyboardPropertiesLocked(device, false);
1191 if (epoll_ctl(mEpollFd, EPOLL_CTL_DEL, device->fd, NULL)) {
1192 LOGW("Could not remove device fd from epoll instance. errno=%d", errno);
1195 mDevices.removeItem(device->id);
1196 device->close();
1199 Device* pred = NULL;
1201 for (Device* entry = mOpeningDevices; entry != NULL; ) {
1202 if (entry == device) {
1210 // Unlink the device from the opening devices list then delete it.
1211 // We don't need to tell the client that the device was closed because
1213 LOGI("Device %s was immediately closed after opening.", device->path.string());
1215 pred->next = device->next;
1217 mOpeningDevices = device->next;
1219 delete device;
1222 // The device will be deleted later after we have informed the client.
1223 device->next = mClosingDevices;
1224 mClosingDevices = device;
1259 LOGI("Removing device '%s' due to inotify event\n", devname);
1312 const Device* device = mDevices.valueAt(i);
1313 if (mBuiltInKeyboardId == device->id) {
1314 dump.appendFormat(INDENT2 "%d: %s (aka device 0 - built-in keyboard)\n",
1315 device->id, device->identifier.name.string());
1317 dump.appendFormat(INDENT2 "%d: %s\n", device->id,
1318 device->identifier.name.string());
1320 dump.appendFormat(INDENT3 "Classes: 0x%08x\n", device->classes);
1321 dump.appendFormat(INDENT3 "Path: %s\n", device->path.string());
1322 dump.appendFormat(INDENT3 "Location: %s\n", device->identifier.location.string());
1323 dump.appendFormat(INDENT3 "UniqueId: %s\n", device->identifier.uniqueId.string());
1326 device->identifier.bus, device->identifier.vendor,
1327 device->identifier.product, device->identifier.version);
1329 device->keyMap.keyLayoutFile.string());
1331 device->keyMap.keyCharacterMapFile.string());
1333 device->configurationFile.string());