diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java index 04351da6dff70..afc53611c4b94 100644 --- a/core/java/com/android/internal/os/ZygoteInit.java +++ b/core/java/com/android/internal/os/ZygoteInit.java @@ -484,6 +484,7 @@ public class ZygoteInit { private static boolean startSystemServer() throws MethodAndArgsCaller, RuntimeException { long capabilities = posixCapabilitiesAsBits( + OsConstants.CAP_BLOCK_SUSPEND, OsConstants.CAP_KILL, OsConstants.CAP_NET_ADMIN, OsConstants.CAP_NET_BIND_SERVICE, diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp index 4d70d5f1ee081..cd313c43ecfcb 100644 --- a/services/input/EventHub.cpp +++ b/services/input/EventHub.cpp @@ -49,6 +49,7 @@ #include #include #include +#include /* 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 = ""; + } 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 ae28f016f7260..e54b9fcf9c95c 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 a8bb63671b609..e6f45b6c8d400 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;