Refactor how timeouts are calculated.
Added a timeout mechanism to EventHub and InputReader so that
InputMappers can request timeouts to perform delayed processing of
input when needed.
Change-Id: Iec2045baaf4e67690b15eef3c09a58d5cac76897
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
index e2da740..b90571b 100644
--- a/services/input/EventHub.cpp
+++ b/services/input/EventHub.cpp
@@ -445,7 +445,7 @@
return NULL;
}
-bool EventHub::getEvent(RawEvent* outEvent) {
+bool EventHub::getEvent(int timeoutMillis, RawEvent* outEvent) {
outEvent->deviceId = 0;
outEvent->type = 0;
outEvent->scanCode = 0;
@@ -598,13 +598,20 @@
// when this happens, the EventHub holds onto its own user wake lock while the client
// is processing events. Thus the system can only sleep if there are no events
// pending or currently being processed.
+ //
+ // The timeout is advisory only. If the device is asleep, it will not wake just to
+ // service the timeout.
release_wake_lock(WAKE_LOCK_ID);
- int pollResult = poll(mFds.editArray(), mFds.size(), -1);
+ int pollResult = poll(mFds.editArray(), mFds.size(), timeoutMillis);
acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_ID);
- if (pollResult <= 0) {
+ if (pollResult == 0) {
+ // Timed out.
+ return false;
+ }
+ if (pollResult < 0) {
if (errno != EINTR) {
LOGW("poll failed (errno=%d)\n", errno);
usleep(100000);