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