Refactor how timeouts are calculated. (DO NOT MERGE)

Added a timeout mechanism to EventHub and InputReader so that
InputMappers can request timeouts to perform delayed processing of
input when needed.

Change-Id: I89c1171c9326c6e413042e3ee13aa9f7f1fc0454
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp
index 853dda4..41993fd 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);