return errors properly in BitTube and SensorEventQueue

Change-Id: Idf31179f9fcc666e287c7b01b2007431cb60127d
diff --git a/libs/gui/SensorEventQueue.cpp b/libs/gui/SensorEventQueue.cpp
index 04ba640..8a1bf41 100644
--- a/libs/gui/SensorEventQueue.cpp
+++ b/libs/gui/SensorEventQueue.cpp
@@ -79,14 +79,21 @@
     const int fd = getFd();
     sp<Looper> looper(getLooper());
 
+    int events;
     int32_t result;
     do {
-        result = looper->pollOnce(-1);
-        if (result == ALOOPER_EVENT_ERROR) {
+        result = looper->pollOnce(-1, NULL, &events, NULL);
+        if (result == ALOOPER_POLL_ERROR) {
             ALOGE("SensorEventQueue::waitForEvent error (errno=%d)", errno);
             result = -EPIPE; // unknown error, so we make up one
             break;
         }
+        if (events & ALOOPER_EVENT_HANGUP) {
+            // the other-side has died
+            ALOGE("SensorEventQueue::waitForEvent error HANGUP");
+            result = -EPIPE; // unknown error, so we make up one
+            break;
+        }
     } while (result != fd);
 
     return  (result == fd) ? status_t(NO_ERROR) : result;