diff options
Diffstat (limited to 'services/input')
-rw-r--r-- | services/input/EventHub.cpp | 31 | ||||
-rw-r--r-- | services/input/EventHub.h | 2 | ||||
-rw-r--r-- | services/input/InputReader.h | 2 |
3 files changed, 28 insertions, 7 deletions
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp index 4d70d5f..cd313c4 100644 --- a/services/input/EventHub.cpp +++ b/services/input/EventHub.cpp @@ -49,6 +49,7 @@ #include <sys/ioctl.h> #include <sys/limits.h> #include <sys/sha1.h> +#include <sys/utsname.h> /* this macro is used to tell if "bit" is set in "array" * it selects a byte from the array, and does a boolean AND @@ -93,6 +94,14 @@ static String8 sha1(const String8& in) { return out; } +static void getLinuxRelease(int* major, int* minor) { + struct utsname info; + if (uname(&info) || sscanf(info.release, "%d.%d", major, minor) <= 0) { + *major = 0, *minor = 0; + ALOGE("Could not get linux version: %s", strerror(errno)); + } +} + static void setDescriptor(InputDeviceIdentifier& identifier) { // Compute a device descriptor that uniquely identifies the device. // The descriptor is assumed to be a stable identifier. Its value should not @@ -236,6 +245,11 @@ EventHub::EventHub(void) : result = epoll_ctl(mEpollFd, EPOLL_CTL_ADD, mWakeReadPipeFd, &eventItem); LOG_ALWAYS_FATAL_IF(result != 0, "Could not add wake read pipe to epoll instance. errno=%d", errno); + + int major, minor; + getLinuxRelease(&major, &minor); + // EPOLLWAKEUP was introduced in kernel 3.5 + mUsingEpollWakeup = major > 3 || (major == 3 && minor >= 5); } EventHub::~EventHub(void) { @@ -1244,7 +1258,7 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { // Register with epoll. struct epoll_event eventItem; memset(&eventItem, 0, sizeof(eventItem)); - eventItem.events = EPOLLIN; + eventItem.events = mUsingEpollWakeup ? EPOLLIN : EPOLLIN | EPOLLWAKEUP; eventItem.data.u32 = deviceId; if (epoll_ctl(mEpollFd, EPOLL_CTL_ADD, fd, &eventItem)) { ALOGE("Could not add device fd to epoll instance. errno=%d", errno); @@ -1252,9 +1266,14 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { return -1; } - // Enable wake-lock behavior on kernels that support it. - // TODO: Only need this for devices that can really wake the system. - bool usingSuspendBlockIoctl = !ioctl(fd, EVIOCSSUSPENDBLOCK, 1); + String8 wakeMechanism("EPOLLWAKEUP"); + if (!mUsingEpollWakeup) { + if (ioctl(fd, EVIOCSSUSPENDBLOCK, 1)) { + wakeMechanism = "<none>"; + } else { + wakeMechanism = "EVIOCSSUSPENDBLOCK"; + } + } // Tell the kernel that we want to use the monotonic clock for reporting timestamps // associated with input events. This is important because the input system @@ -1276,14 +1295,14 @@ status_t EventHub::openDeviceLocked(const char *devicePath) { ALOGI("New device: id=%d, fd=%d, path='%s', name='%s', classes=0x%x, " "configuration='%s', keyLayout='%s', keyCharacterMap='%s', builtinKeyboard=%s, " - "usingSuspendBlockIoctl=%s, usingClockIoctl=%s", + "wakeMechanism=%s, usingClockIoctl=%s", deviceId, fd, devicePath, device->identifier.name.string(), device->classes, device->configurationFile.string(), device->keyMap.keyLayoutFile.string(), device->keyMap.keyCharacterMapFile.string(), toString(mBuiltInKeyboardId == deviceId), - toString(usingSuspendBlockIoctl), toString(usingClockIoctl)); + wakeMechanism.string(), toString(usingClockIoctl)); addDeviceLocked(device); return 0; diff --git a/services/input/EventHub.h b/services/input/EventHub.h index ae28f01..e54b9fc 100644 --- a/services/input/EventHub.h +++ b/services/input/EventHub.h @@ -440,6 +440,8 @@ private: size_t mPendingEventCount; size_t mPendingEventIndex; bool mPendingINotify; + + bool mUsingEpollWakeup; }; }; // namespace android diff --git a/services/input/InputReader.h b/services/input/InputReader.h index a8bb636..e6f45b6 100644 --- a/services/input/InputReader.h +++ b/services/input/InputReader.h @@ -574,8 +574,8 @@ public: private: InputReaderContext* mContext; int32_t mId; - int32_t mControllerNumber; int32_t mGeneration; + int32_t mControllerNumber; InputDeviceIdentifier mIdentifier; String8 mAlias; uint32_t mClasses; |