Merge changes I2d3fef08,Idb828aa4,Ica764b1f,I9ae8887b,I376fad86,I4d00a9dd

* changes:
  libion: update to latest uapi header
  libion: return -errno from ion_close
  libion: add include for size_t
  libion: add NULL checks
  libion: clean up whitespace
  libion: move ion.h into local include directory
diff --git a/adb/adb.c b/adb/adb.c
index 72b7484..41270f9 100644
--- a/adb/adb.c
+++ b/adb/adb.c
@@ -562,7 +562,7 @@
         break;
 
     case A_OPEN: /* OPEN(local-id, 0, "destination") */
-        if (t->online) {
+        if (t->online && p->msg.arg0 != 0 && p->msg.arg1 == 0) {
             char *name = (char*) p->data;
             name[p->msg.data_length > 0 ? p->msg.data_length - 1 : 0] = 0;
             s = create_local_service_socket(name);
@@ -578,28 +578,50 @@
         break;
 
     case A_OKAY: /* READY(local-id, remote-id, "") */
-        if (t->online) {
-            if((s = find_local_socket(p->msg.arg1))) {
+        if (t->online && p->msg.arg0 != 0 && p->msg.arg1 != 0) {
+            if((s = find_local_socket(p->msg.arg1, 0))) {
                 if(s->peer == 0) {
+                    /* On first READY message, create the connection. */
                     s->peer = create_remote_socket(p->msg.arg0, t);
                     s->peer->peer = s;
+                    s->ready(s);
+                } else if (s->peer->id == p->msg.arg0) {
+                    /* Other READY messages must use the same local-id */
+                    s->ready(s);
+                } else {
+                    D("Invalid A_OKAY(%d,%d), expected A_OKAY(%d,%d) on transport %s\n",
+                      p->msg.arg0, p->msg.arg1, s->peer->id, p->msg.arg1, t->serial);
                 }
-                s->ready(s);
             }
         }
         break;
 
-    case A_CLSE: /* CLOSE(local-id, remote-id, "") */
-        if (t->online) {
-            if((s = find_local_socket(p->msg.arg1))) {
-                s->close(s);
+    case A_CLSE: /* CLOSE(local-id, remote-id, "") or CLOSE(0, remote-id, "") */
+        if (t->online && p->msg.arg1 != 0) {
+            if((s = find_local_socket(p->msg.arg1, p->msg.arg0))) {
+                /* According to protocol.txt, p->msg.arg0 might be 0 to indicate
+                 * a failed OPEN only. However, due to a bug in previous ADB
+                 * versions, CLOSE(0, remote-id, "") was also used for normal
+                 * CLOSE() operations.
+                 *
+                 * This is bad because it means a compromised adbd could
+                 * send packets to close connections between the host and
+                 * other devices. To avoid this, only allow this if the local
+                 * socket has a peer on the same transport.
+                 */
+                if (p->msg.arg0 == 0 && s->peer && s->peer->transport != t) {
+                    D("Invalid A_CLSE(0, %u) from transport %s, expected transport %s\n",
+                      p->msg.arg1, t->serial, s->peer->transport->serial);
+                } else {
+                    s->close(s);
+                }
             }
         }
         break;
 
-    case A_WRTE:
-        if (t->online) {
-            if((s = find_local_socket(p->msg.arg1))) {
+    case A_WRTE: /* WRITE(local-id, remote-id, <data>) */
+        if (t->online && p->msg.arg0 != 0 && p->msg.arg1 != 0) {
+            if((s = find_local_socket(p->msg.arg1, p->msg.arg0))) {
                 unsigned rid = p->msg.arg0;
                 p->len = p->msg.data_length;
 
diff --git a/adb/adb.h b/adb/adb.h
index 622ca70..c85b02a 100644
--- a/adb/adb.h
+++ b/adb/adb.h
@@ -122,6 +122,12 @@
         */
     void (*ready)(asocket *s);
 
+        /* shutdown is called by the peer before it goes away.
+        ** the socket should not do any further calls on its peer.
+        ** Always followed by a call to close. Optional, i.e. can be NULL.
+        */
+    void (*shutdown)(asocket *s);
+
         /* close is called by the peer when it has gone away.
         ** we are not allowed to make any further calls on the
         ** peer once our close method is called.
@@ -233,7 +239,7 @@
 
 void print_packet(const char *label, apacket *p);
 
-asocket *find_local_socket(unsigned id);
+asocket *find_local_socket(unsigned local_id, unsigned remote_id);
 void install_local_socket(asocket *s);
 void remove_socket(asocket *s);
 void close_all_sockets(atransport *t);
diff --git a/adb/sockets.c b/adb/sockets.c
index f17608b..7f54ad9 100644
--- a/adb/sockets.c
+++ b/adb/sockets.c
@@ -59,17 +59,22 @@
     .prev = &local_socket_closing_list,
 };
 
-asocket *find_local_socket(unsigned id)
+// Parse the global list of sockets to find one with id |local_id|.
+// If |peer_id| is not 0, also check that it is connected to a peer
+// with id |peer_id|. Returns an asocket handle on success, NULL on failure.
+asocket *find_local_socket(unsigned local_id, unsigned peer_id)
 {
     asocket *s;
     asocket *result = NULL;
 
     adb_mutex_lock(&socket_list_lock);
     for (s = local_socket_list.next; s != &local_socket_list; s = s->next) {
-        if (s->id == id) {
+        if (s->id != local_id)
+            continue;
+        if (peer_id == 0 || (s->peer && s->peer->id == peer_id)) {
             result = s;
-            break;
         }
+        break;
     }
     adb_mutex_unlock(&socket_list_lock);
 
@@ -91,6 +96,11 @@
     adb_mutex_lock(&socket_list_lock);
 
     s->id = local_socket_next_id++;
+
+    // Socket ids should never be 0.
+    if (local_socket_next_id == 0)
+      local_socket_next_id = 1;
+
     insert_local_socket(s, &local_socket_list);
 
     adb_mutex_unlock(&socket_list_lock);
@@ -230,6 +240,12 @@
     if(s->peer) {
         D("LS(%d): closing peer. peer->id=%d peer->fd=%d\n",
           s->id, s->peer->id, s->peer->fd);
+        /* Note: it's important to call shutdown before disconnecting from
+         * the peer, this ensures that remote sockets can still get the id
+         * of the local socket they're connected to, to send a CLOSE()
+         * protocol event. */
+        if (s->peer->shutdown)
+          s->peer->shutdown(s->peer);
         s->peer->peer = 0;
         // tweak to avoid deadlock
         if (s->peer->close == local_socket_close) {
@@ -397,6 +413,7 @@
     s->fd = fd;
     s->enqueue = local_socket_enqueue;
     s->ready = local_socket_ready;
+    s->shutdown = NULL;
     s->close = local_socket_close;
     install_local_socket(s);
 
@@ -485,21 +502,29 @@
     send_packet(p, s->transport);
 }
 
-static void remote_socket_close(asocket *s)
+static void remote_socket_shutdown(asocket *s)
 {
-    D("entered remote_socket_close RS(%d) CLOSE fd=%d peer->fd=%d\n",
+    D("entered remote_socket_shutdown RS(%d) CLOSE fd=%d peer->fd=%d\n",
       s->id, s->fd, s->peer?s->peer->fd:-1);
     apacket *p = get_apacket();
     p->msg.command = A_CLSE;
     if(s->peer) {
         p->msg.arg0 = s->peer->id;
+    }
+    p->msg.arg1 = s->id;
+    send_packet(p, s->transport);
+}
+
+static void remote_socket_close(asocket *s)
+{
+    if (s->peer) {
         s->peer->peer = 0;
         D("RS(%d) peer->close()ing peer->id=%d peer->fd=%d\n",
           s->id, s->peer->id, s->peer->fd);
         s->peer->close(s->peer);
     }
-    p->msg.arg1 = s->id;
-    send_packet(p, s->transport);
+    D("entered remote_socket_close RS(%d) CLOSE fd=%d peer->fd=%d\n",
+      s->id, s->fd, s->peer?s->peer->fd:-1);
     D("RS(%d): closed\n", s->id);
     remove_transport_disconnect( s->transport, &((aremotesocket*)s)->disconnect );
     free(s);
@@ -519,15 +544,24 @@
     free(s);
 }
 
+/* Create an asocket to exchange packets with a remote service through transport
+  |t|. Where |id| is the socket id of the corresponding service on the other
+   side of the transport (it is allocated by the remote side and _cannot_ be 0).
+   Returns a new non-NULL asocket handle. */
 asocket *create_remote_socket(unsigned id, atransport *t)
 {
-    asocket *s = calloc(1, sizeof(aremotesocket));
-    adisconnect*  dis = &((aremotesocket*)s)->disconnect;
+    asocket* s;
+    adisconnect* dis;
+
+    if (id == 0) fatal("invalid remote socket id (0)");
+    s = calloc(1, sizeof(aremotesocket));
+    dis = &((aremotesocket*)s)->disconnect;
 
     if (s == NULL) fatal("cannot allocate socket");
     s->id = id;
     s->enqueue = remote_socket_enqueue;
     s->ready = remote_socket_ready;
+    s->shutdown = remote_socket_shutdown;
     s->close = remote_socket_close;
     s->transport = t;
 
@@ -562,6 +596,7 @@
 static void local_socket_ready_notify(asocket *s)
 {
     s->ready = local_socket_ready;
+    s->shutdown = NULL;
     s->close = local_socket_close;
     adb_write(s->fd, "OKAY", 4);
     s->ready(s);
@@ -573,6 +608,7 @@
 static void local_socket_close_notify(asocket *s)
 {
     s->ready = local_socket_ready;
+    s->shutdown = NULL;
     s->close = local_socket_close;
     sendfailmsg(s->fd, "closed");
     s->close(s);
@@ -767,6 +803,7 @@
         adb_write(s->peer->fd, "OKAY", 4);
 
         s->peer->ready = local_socket_ready;
+        s->peer->shutdown = NULL;
         s->peer->close = local_socket_close;
         s->peer->peer = s2;
         s2->peer = s->peer;
@@ -806,6 +843,7 @@
         ** tear down
         */
     s->peer->ready = local_socket_ready_notify;
+    s->peer->shutdown = NULL;
     s->peer->close = local_socket_close_notify;
     s->peer->peer = 0;
         /* give him our transport and upref it */
@@ -851,6 +889,7 @@
     if (s == NULL) fatal("cannot allocate socket");
     s->enqueue = smart_socket_enqueue;
     s->ready = smart_socket_ready;
+    s->shutdown = NULL;
     s->close = smart_socket_close;
 
     D("SS(%d)\n", s->id);
diff --git a/include/utils/Looper.h b/include/utils/Looper.h
index 2e0651a..15c9891 100644
--- a/include/utils/Looper.h
+++ b/include/utils/Looper.h
@@ -22,18 +22,28 @@
 #include <utils/KeyedVector.h>
 #include <utils/Timers.h>
 
-#include <android/looper.h>
-
 #include <sys/epoll.h>
 
-/*
- * Declare a concrete type for the NDK's looper forward declaration.
- */
-struct ALooper {
-};
-
 namespace android {
 
+/*
+ * NOTE: Since Looper is used to implement the NDK ALooper, the Looper
+ * enums and the signature of Looper_callbackFunc need to align with
+ * that implementation.
+ */
+
+/**
+ * For callback-based event loops, this is the prototype of the function
+ * that is called when a file descriptor event occurs.
+ * It is given the file descriptor it is associated with,
+ * a bitmask of the poll events that were triggered (typically EVENT_INPUT),
+ * and the data pointer that was originally supplied.
+ *
+ * Implementations should return 1 to continue receiving callbacks, or 0
+ * to have this file descriptor and callback unregistered from the looper.
+ */
+typedef int (*Looper_callbackFunc)(int fd, int events, void* data);
+
 /**
  * A message that can be posted to a Looper.
  */
@@ -93,7 +103,7 @@
     /**
      * Handles a poll event for the given file descriptor.
      * It is given the file descriptor it is associated with,
-     * a bitmask of the poll events that were triggered (typically ALOOPER_EVENT_INPUT),
+     * a bitmask of the poll events that were triggered (typically EVENT_INPUT),
      * and the data pointer that was originally supplied.
      *
      * Implementations should return 1 to continue receiving callbacks, or 0
@@ -102,34 +112,113 @@
     virtual int handleEvent(int fd, int events, void* data) = 0;
 };
 
-
 /**
- * Wraps a ALooper_callbackFunc function pointer.
+ * Wraps a Looper_callbackFunc function pointer.
  */
 class SimpleLooperCallback : public LooperCallback {
 protected:
     virtual ~SimpleLooperCallback();
 
 public:
-    SimpleLooperCallback(ALooper_callbackFunc callback);
+    SimpleLooperCallback(Looper_callbackFunc callback);
     virtual int handleEvent(int fd, int events, void* data);
 
 private:
-    ALooper_callbackFunc mCallback;
+    Looper_callbackFunc mCallback;
 };
 
-
 /**
  * A polling loop that supports monitoring file descriptor events, optionally
  * using callbacks.  The implementation uses epoll() internally.
  *
  * A looper can be associated with a thread although there is no requirement that it must be.
  */
-class Looper : public ALooper, public RefBase {
+class Looper : public RefBase {
 protected:
     virtual ~Looper();
 
 public:
+    enum {
+        /**
+         * Result from Looper_pollOnce() and Looper_pollAll():
+         * The poll was awoken using wake() before the timeout expired
+         * and no callbacks were executed and no other file descriptors were ready.
+         */
+        POLL_WAKE = -1,
+
+        /**
+         * Result from Looper_pollOnce() and Looper_pollAll():
+         * One or more callbacks were executed.
+         */
+        POLL_CALLBACK = -2,
+
+        /**
+         * Result from Looper_pollOnce() and Looper_pollAll():
+         * The timeout expired.
+         */
+        POLL_TIMEOUT = -3,
+
+        /**
+         * Result from Looper_pollOnce() and Looper_pollAll():
+         * An error occurred.
+         */
+        POLL_ERROR = -4,
+    };
+
+    /**
+     * Flags for file descriptor events that a looper can monitor.
+     *
+     * These flag bits can be combined to monitor multiple events at once.
+     */
+    enum {
+        /**
+         * The file descriptor is available for read operations.
+         */
+        EVENT_INPUT = 1 << 0,
+
+        /**
+         * The file descriptor is available for write operations.
+         */
+        EVENT_OUTPUT = 1 << 1,
+
+        /**
+         * The file descriptor has encountered an error condition.
+         *
+         * The looper always sends notifications about errors; it is not necessary
+         * to specify this event flag in the requested event set.
+         */
+        EVENT_ERROR = 1 << 2,
+
+        /**
+         * The file descriptor was hung up.
+         * For example, indicates that the remote end of a pipe or socket was closed.
+         *
+         * The looper always sends notifications about hangups; it is not necessary
+         * to specify this event flag in the requested event set.
+         */
+        EVENT_HANGUP = 1 << 3,
+
+        /**
+         * The file descriptor is invalid.
+         * For example, the file descriptor was closed prematurely.
+         *
+         * The looper always sends notifications about invalid file descriptors; it is not necessary
+         * to specify this event flag in the requested event set.
+         */
+        EVENT_INVALID = 1 << 4,
+    };
+
+    enum {
+        /**
+         * Option for Looper_prepare: this looper will accept calls to
+         * Looper_addFd() that do not have a callback (that is provide NULL
+         * for the callback).  In this case the caller of Looper_pollOnce()
+         * or Looper_pollAll() MUST check the return from these functions to
+         * discover when data is available on such fds and process it.
+         */
+        PREPARE_ALLOW_NON_CALLBACKS = 1<<0
+    };
+
     /**
      * Creates a looper.
      *
@@ -152,16 +241,16 @@
      * If the timeout is zero, returns immediately without blocking.
      * If the timeout is negative, waits indefinitely until an event appears.
      *
-     * Returns ALOOPER_POLL_WAKE if the poll was awoken using wake() before
+     * Returns POLL_WAKE if the poll was awoken using wake() before
      * the timeout expired and no callbacks were invoked and no other file
      * descriptors were ready.
      *
-     * Returns ALOOPER_POLL_CALLBACK if one or more callbacks were invoked.
+     * Returns POLL_CALLBACK if one or more callbacks were invoked.
      *
-     * Returns ALOOPER_POLL_TIMEOUT if there was no data before the given
+     * Returns POLL_TIMEOUT if there was no data before the given
      * timeout expired.
      *
-     * Returns ALOOPER_POLL_ERROR if an error occurred.
+     * Returns POLL_ERROR if an error occurred.
      *
      * Returns a value >= 0 containing an identifier if its file descriptor has data
      * and it has no callback function (requiring the caller here to handle it).
@@ -179,7 +268,7 @@
     /**
      * Like pollOnce(), but performs all pending callbacks until all
      * data has been consumed or a file descriptor is available with no callback.
-     * This function will never return ALOOPER_POLL_CALLBACK.
+     * This function will never return POLL_CALLBACK.
      */
     int pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData);
     inline int pollAll(int timeoutMillis) {
@@ -200,8 +289,8 @@
      *
      * "fd" is the file descriptor to be added.
      * "ident" is an identifier for this event, which is returned from pollOnce().
-     * The identifier must be >= 0, or ALOOPER_POLL_CALLBACK if providing a non-NULL callback.
-     * "events" are the poll events to wake up on.  Typically this is ALOOPER_EVENT_INPUT.
+     * The identifier must be >= 0, or POLL_CALLBACK if providing a non-NULL callback.
+     * "events" are the poll events to wake up on.  Typically this is EVENT_INPUT.
      * "callback" is the function to call when there is an event on the file descriptor.
      * "data" is a private data pointer to supply to the callback.
      *
@@ -211,7 +300,7 @@
      * data on the file descriptor.  It should execute any events it has pending,
      * appropriately reading from the file descriptor.  The 'ident' is ignored in this case.
      *
-     * (2) If "callback" is NULL, the 'ident' will be returned by ALooper_pollOnce
+     * (2) If "callback" is NULL, the 'ident' will be returned by Looper_pollOnce
      * when its file descriptor has data available, requiring the caller to take
      * care of processing it.
      *
@@ -225,7 +314,7 @@
      * easier to avoid races when the callback is removed from a different thread.
      * See removeFd() for details.
      */
-    int addFd(int fd, int ident, int events, ALooper_callbackFunc callback, void* data);
+    int addFd(int fd, int ident, int events, Looper_callbackFunc callback, void* data);
     int addFd(int fd, int ident, int events, const sp<LooperCallback>& callback, void* data);
 
     /**
@@ -308,7 +397,7 @@
      * If the thread already has a looper, it is returned.  Otherwise, a new
      * one is created, associated with the thread, and returned.
      *
-     * The opts may be ALOOPER_PREPARE_ALLOW_NON_CALLBACKS or 0.
+     * The opts may be PREPARE_ALLOW_NON_CALLBACKS or 0.
      */
     static sp<Looper> prepare(int opts);
 
diff --git a/libutils/Looper.cpp b/libutils/Looper.cpp
index c51df2d..9a2dd6c 100644
--- a/libutils/Looper.cpp
+++ b/libutils/Looper.cpp
@@ -43,7 +43,7 @@
 
 // --- SimpleLooperCallback ---
 
-SimpleLooperCallback::SimpleLooperCallback(ALooper_callbackFunc callback) :
+SimpleLooperCallback::SimpleLooperCallback(Looper_callbackFunc callback) :
         mCallback(callback) {
 }
 
@@ -139,7 +139,7 @@
 }
 
 sp<Looper> Looper::prepare(int opts) {
-    bool allowNonCallbacks = opts & ALOOPER_PREPARE_ALLOW_NON_CALLBACKS;
+    bool allowNonCallbacks = opts & PREPARE_ALLOW_NON_CALLBACKS;
     sp<Looper> looper = Looper::getForThread();
     if (looper == NULL) {
         looper = new Looper(allowNonCallbacks);
@@ -147,7 +147,7 @@
     }
     if (looper->getAllowNonCallbacks() != allowNonCallbacks) {
         ALOGW("Looper already prepared for this thread with a different value for the "
-                "ALOOPER_PREPARE_ALLOW_NON_CALLBACKS option.");
+                "LOOPER_PREPARE_ALLOW_NON_CALLBACKS option.");
     }
     return looper;
 }
@@ -212,7 +212,7 @@
     }
 
     // Poll.
-    int result = ALOOPER_POLL_WAKE;
+    int result = POLL_WAKE;
     mResponses.clear();
     mResponseIndex = 0;
 
@@ -234,7 +234,7 @@
             goto Done;
         }
         ALOGW("Poll failed with an unexpected error, errno=%d", errno);
-        result = ALOOPER_POLL_ERROR;
+        result = POLL_ERROR;
         goto Done;
     }
 
@@ -243,7 +243,7 @@
 #if DEBUG_POLL_AND_WAKE
         ALOGD("%p ~ pollOnce - timeout", this);
 #endif
-        result = ALOOPER_POLL_TIMEOUT;
+        result = POLL_TIMEOUT;
         goto Done;
     }
 
@@ -265,10 +265,10 @@
             ssize_t requestIndex = mRequests.indexOfKey(fd);
             if (requestIndex >= 0) {
                 int events = 0;
-                if (epollEvents & EPOLLIN) events |= ALOOPER_EVENT_INPUT;
-                if (epollEvents & EPOLLOUT) events |= ALOOPER_EVENT_OUTPUT;
-                if (epollEvents & EPOLLERR) events |= ALOOPER_EVENT_ERROR;
-                if (epollEvents & EPOLLHUP) events |= ALOOPER_EVENT_HANGUP;
+                if (epollEvents & EPOLLIN) events |= EVENT_INPUT;
+                if (epollEvents & EPOLLOUT) events |= EVENT_OUTPUT;
+                if (epollEvents & EPOLLERR) events |= EVENT_ERROR;
+                if (epollEvents & EPOLLHUP) events |= EVENT_HANGUP;
                 pushResponse(events, mRequests.valueAt(requestIndex));
             } else {
                 ALOGW("Ignoring unexpected epoll events 0x%x on fd %d that is "
@@ -304,7 +304,7 @@
 
             mLock.lock();
             mSendingMessage = false;
-            result = ALOOPER_POLL_CALLBACK;
+            result = POLL_CALLBACK;
         } else {
             // The last message left at the head of the queue determines the next wakeup time.
             mNextMessageUptime = messageEnvelope.uptime;
@@ -318,7 +318,7 @@
     // Invoke all response callbacks.
     for (size_t i = 0; i < mResponses.size(); i++) {
         Response& response = mResponses.editItemAt(i);
-        if (response.request.ident == ALOOPER_POLL_CALLBACK) {
+        if (response.request.ident == POLL_CALLBACK) {
             int fd = response.request.fd;
             int events = response.events;
             void* data = response.request.data;
@@ -333,7 +333,7 @@
             // Clear the callback reference in the response structure promptly because we
             // will not clear the response vector itself until the next poll.
             response.request.callback.clear();
-            result = ALOOPER_POLL_CALLBACK;
+            result = POLL_CALLBACK;
         }
     }
     return result;
@@ -344,7 +344,7 @@
         int result;
         do {
             result = pollOnce(timeoutMillis, outFd, outEvents, outData);
-        } while (result == ALOOPER_POLL_CALLBACK);
+        } while (result == POLL_CALLBACK);
         return result;
     } else {
         nsecs_t endTime = systemTime(SYSTEM_TIME_MONOTONIC)
@@ -352,14 +352,14 @@
 
         for (;;) {
             int result = pollOnce(timeoutMillis, outFd, outEvents, outData);
-            if (result != ALOOPER_POLL_CALLBACK) {
+            if (result != POLL_CALLBACK) {
                 return result;
             }
 
             nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
             timeoutMillis = toMillisecondTimeoutDelay(now, endTime);
             if (timeoutMillis == 0) {
-                return ALOOPER_POLL_TIMEOUT;
+                return POLL_TIMEOUT;
             }
         }
     }
@@ -401,7 +401,7 @@
     mResponses.push(response);
 }
 
-int Looper::addFd(int fd, int ident, int events, ALooper_callbackFunc callback, void* data) {
+int Looper::addFd(int fd, int ident, int events, Looper_callbackFunc callback, void* data) {
     return addFd(fd, ident, events, callback ? new SimpleLooperCallback(callback) : NULL, data);
 }
 
@@ -422,12 +422,12 @@
             return -1;
         }
     } else {
-        ident = ALOOPER_POLL_CALLBACK;
+        ident = POLL_CALLBACK;
     }
 
     int epollEvents = 0;
-    if (events & ALOOPER_EVENT_INPUT) epollEvents |= EPOLLIN;
-    if (events & ALOOPER_EVENT_OUTPUT) epollEvents |= EPOLLOUT;
+    if (events & EVENT_INPUT) epollEvents |= EPOLLIN;
+    if (events & EVENT_OUTPUT) epollEvents |= EPOLLOUT;
 
     { // acquire lock
         AutoMutex _l(mLock);
diff --git a/libutils/tests/Looper_test.cpp b/libutils/tests/Looper_test.cpp
index 8bf2ba2..00077e6 100644
--- a/libutils/tests/Looper_test.cpp
+++ b/libutils/tests/Looper_test.cpp
@@ -119,8 +119,8 @@
 
     EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. equal timeout";
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be LOOPER_POLL_TIMEOUT";
 }
 
 TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndAwokenBeforeWaiting_ImmediatelyReturns) {
@@ -132,8 +132,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because wake() was called before waiting";
-    EXPECT_EQ(ALOOPER_POLL_WAKE, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because loop was awoken";
+    EXPECT_EQ(Looper::POLL_WAKE, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because loop was awoken";
 }
 
 TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndAwokenWhileWaiting_PromptlyReturns) {
@@ -146,8 +146,8 @@
 
     EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. equal wake delay";
-    EXPECT_EQ(ALOOPER_POLL_WAKE, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because loop was awoken";
+    EXPECT_EQ(Looper::POLL_WAKE, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because loop was awoken";
 }
 
 TEST_F(LooperTest, PollOnce_WhenZeroTimeoutAndNoRegisteredFDs_ImmediatelyReturns) {
@@ -157,15 +157,15 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should be approx. zero";
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT";
 }
 
 TEST_F(LooperTest, PollOnce_WhenZeroTimeoutAndNoSignalledFDs_ImmediatelyReturns) {
     Pipe pipe;
     StubCallbackHandler handler(true);
 
-    handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
+    handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
 
     StopWatch stopWatch("pollOnce");
     int result = mLooper->pollOnce(0);
@@ -173,8 +173,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should be approx. zero";
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT";
     EXPECT_EQ(0, handler.callbackCount)
             << "callback should not have been invoked because FD was not signalled";
 }
@@ -184,7 +184,7 @@
     StubCallbackHandler handler(true);
 
     ASSERT_EQ(OK, pipe.writeSignal());
-    handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
+    handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
 
     StopWatch stopWatch("pollOnce");
     int result = mLooper->pollOnce(0);
@@ -192,21 +192,21 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should be approx. zero";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled";
     EXPECT_EQ(1, handler.callbackCount)
             << "callback should be invoked exactly once";
     EXPECT_EQ(pipe.receiveFd, handler.fd)
             << "callback should have received pipe fd as parameter";
-    EXPECT_EQ(ALOOPER_EVENT_INPUT, handler.events)
-            << "callback should have received ALOOPER_EVENT_INPUT as events";
+    EXPECT_EQ(Looper::EVENT_INPUT, handler.events)
+            << "callback should have received Looper::EVENT_INPUT as events";
 }
 
 TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndNoSignalledFDs_WaitsForTimeoutAndReturns) {
     Pipe pipe;
     StubCallbackHandler handler(true);
 
-    handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
+    handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
 
     StopWatch stopWatch("pollOnce");
     int result = mLooper->pollOnce(100);
@@ -214,8 +214,8 @@
 
     EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. equal timeout";
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT";
     EXPECT_EQ(0, handler.callbackCount)
             << "callback should not have been invoked because FD was not signalled";
 }
@@ -225,7 +225,7 @@
     StubCallbackHandler handler(true);
 
     pipe.writeSignal();
-    handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
+    handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
 
     StopWatch stopWatch("pollOnce");
     int result = mLooper->pollOnce(100);
@@ -235,14 +235,14 @@
             << "signal should actually have been written";
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should be approx. zero";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled";
     EXPECT_EQ(1, handler.callbackCount)
             << "callback should be invoked exactly once";
     EXPECT_EQ(pipe.receiveFd, handler.fd)
             << "callback should have received pipe fd as parameter";
-    EXPECT_EQ(ALOOPER_EVENT_INPUT, handler.events)
-            << "callback should have received ALOOPER_EVENT_INPUT as events";
+    EXPECT_EQ(Looper::EVENT_INPUT, handler.events)
+            << "callback should have received Looper::EVENT_INPUT as events";
 }
 
 TEST_F(LooperTest, PollOnce_WhenNonZeroTimeoutAndSignalledFDWhileWaiting_PromptlyInvokesCallbackAndReturns) {
@@ -250,7 +250,7 @@
     StubCallbackHandler handler(true);
     sp<DelayedWriteSignal> delayedWriteSignal = new DelayedWriteSignal(100, & pipe);
 
-    handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
+    handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
     delayedWriteSignal->run();
 
     StopWatch stopWatch("pollOnce");
@@ -261,21 +261,21 @@
             << "signal should actually have been written";
     EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. equal signal delay";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled";
     EXPECT_EQ(1, handler.callbackCount)
             << "callback should be invoked exactly once";
     EXPECT_EQ(pipe.receiveFd, handler.fd)
             << "callback should have received pipe fd as parameter";
-    EXPECT_EQ(ALOOPER_EVENT_INPUT, handler.events)
-            << "callback should have received ALOOPER_EVENT_INPUT as events";
+    EXPECT_EQ(Looper::EVENT_INPUT, handler.events)
+            << "callback should have received Looper::EVENT_INPUT as events";
 }
 
 TEST_F(LooperTest, PollOnce_WhenCallbackAddedThenRemoved_CallbackShouldNotBeInvoked) {
     Pipe pipe;
     StubCallbackHandler handler(true);
 
-    handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
+    handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
     pipe.writeSignal(); // would cause FD to be considered signalled
     mLooper->removeFd(pipe.receiveFd);
 
@@ -287,8 +287,8 @@
             << "signal should actually have been written";
     EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. equal timeout because FD was no longer registered";
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT";
     EXPECT_EQ(0, handler.callbackCount)
             << "callback should not be invoked";
 }
@@ -297,7 +297,7 @@
     Pipe pipe;
     StubCallbackHandler handler(false);
 
-    handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
+    handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
 
     // First loop: Callback is registered and FD is signalled.
     pipe.writeSignal();
@@ -310,8 +310,8 @@
             << "signal should actually have been written";
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. equal zero because FD was already signalled";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled";
     EXPECT_EQ(1, handler.callbackCount)
             << "callback should be invoked";
 
@@ -326,8 +326,8 @@
             << "signal should actually have been written";
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. equal zero because timeout was zero";
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT";
     EXPECT_EQ(1, handler.callbackCount)
             << "callback should not be invoked this time";
 }
@@ -339,7 +339,7 @@
     Pipe pipe;
 
     pipe.writeSignal();
-    mLooper->addFd(pipe.receiveFd, expectedIdent, ALOOPER_EVENT_INPUT, NULL, expectedData);
+    mLooper->addFd(pipe.receiveFd, expectedIdent, Looper::EVENT_INPUT, NULL, expectedData);
 
     StopWatch stopWatch("pollOnce");
     int fd;
@@ -356,15 +356,15 @@
             << "pollOnce result should be the ident of the FD that was signalled";
     EXPECT_EQ(pipe.receiveFd, fd)
             << "pollOnce should have returned the received pipe fd";
-    EXPECT_EQ(ALOOPER_EVENT_INPUT, events)
-            << "pollOnce should have returned ALOOPER_EVENT_INPUT as events";
+    EXPECT_EQ(Looper::EVENT_INPUT, events)
+            << "pollOnce should have returned Looper::EVENT_INPUT as events";
     EXPECT_EQ(expectedData, data)
             << "pollOnce should have returned the data";
 }
 
 TEST_F(LooperTest, AddFd_WhenCallbackAdded_ReturnsOne) {
     Pipe pipe;
-    int result = mLooper->addFd(pipe.receiveFd, 0, ALOOPER_EVENT_INPUT, NULL, NULL);
+    int result = mLooper->addFd(pipe.receiveFd, 0, Looper::EVENT_INPUT, NULL, NULL);
 
     EXPECT_EQ(1, result)
             << "addFd should return 1 because FD was added";
@@ -372,7 +372,7 @@
 
 TEST_F(LooperTest, AddFd_WhenIdentIsNegativeAndCallbackIsNull_ReturnsError) {
     Pipe pipe;
-    int result = mLooper->addFd(pipe.receiveFd, -1, ALOOPER_EVENT_INPUT, NULL, NULL);
+    int result = mLooper->addFd(pipe.receiveFd, -1, Looper::EVENT_INPUT, NULL, NULL);
 
     EXPECT_EQ(-1, result)
             << "addFd should return -1 because arguments were invalid";
@@ -397,7 +397,7 @@
 TEST_F(LooperTest, RemoveFd_WhenCallbackAddedThenRemovedTwice_ReturnsOnceFirstTimeAndReturnsZeroSecondTime) {
     Pipe pipe;
     StubCallbackHandler handler(false);
-    handler.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
+    handler.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
 
     // First time.
     int result = mLooper->removeFd(pipe.receiveFd);
@@ -417,8 +417,8 @@
     StubCallbackHandler handler1(true);
     StubCallbackHandler handler2(true);
 
-    handler1.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT);
-    handler2.setCallback(mLooper, pipe.receiveFd, ALOOPER_EVENT_INPUT); // replace it
+    handler1.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT);
+    handler2.setCallback(mLooper, pipe.receiveFd, Looper::EVENT_INPUT); // replace it
     pipe.writeSignal(); // would cause FD to be considered signalled
 
     StopWatch stopWatch("pollOnce");
@@ -429,8 +429,8 @@
             << "signal should actually have been written";
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because FD was already signalled";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because FD was signalled";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because FD was signalled";
     EXPECT_EQ(0, handler1.callbackCount)
             << "original handler callback should not be invoked because it was replaced";
     EXPECT_EQ(1, handler2.callbackCount)
@@ -447,8 +447,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because message was already sent";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because message was sent";
     EXPECT_EQ(size_t(1), handler->messages.size())
             << "handled message";
     EXPECT_EQ(MSG_TEST1, handler->messages[0].what)
@@ -469,8 +469,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because message was already sent";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because message was sent";
     EXPECT_EQ(size_t(3), handler1->messages.size())
             << "handled message";
     EXPECT_EQ(MSG_TEST1, handler1->messages[0].what)
@@ -495,8 +495,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "first poll should end quickly because next message timeout was computed";
-    EXPECT_EQ(ALOOPER_POLL_WAKE, result)
-            << "pollOnce result should be ALOOPER_POLL_WAKE due to wakeup";
+    EXPECT_EQ(Looper::POLL_WAKE, result)
+            << "pollOnce result should be Looper::POLL_WAKE due to wakeup";
     EXPECT_EQ(size_t(0), handler->messages.size())
             << "no message handled yet";
 
@@ -509,16 +509,16 @@
             << "handled message";
     EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "second poll should end around the time of the delayed message dispatch";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because message was sent";
 
     result = mLooper->pollOnce(100);
     elapsedMillis = ns2ms(stopWatch.elapsedTime());
 
     EXPECT_NEAR(100 + 100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "third poll should timeout";
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT because there were no messages left";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT because there were no messages left";
 }
 
 TEST_F(LooperTest, SendMessageDelayed_WhenSentToThePast_ShouldInvokeHandlerDuringNextPoll) {
@@ -531,8 +531,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because message was already sent";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because message was sent";
     EXPECT_EQ(size_t(1), handler->messages.size())
             << "handled message";
     EXPECT_EQ(MSG_TEST1, handler->messages[0].what)
@@ -549,8 +549,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because message was already sent";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because message was sent";
     EXPECT_EQ(size_t(1), handler->messages.size())
             << "handled message";
     EXPECT_EQ(MSG_TEST1, handler->messages[0].what)
@@ -568,8 +568,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "first poll should end quickly because next message timeout was computed";
-    EXPECT_EQ(ALOOPER_POLL_WAKE, result)
-            << "pollOnce result should be ALOOPER_POLL_WAKE due to wakeup";
+    EXPECT_EQ(Looper::POLL_WAKE, result)
+            << "pollOnce result should be Looper::POLL_WAKE due to wakeup";
     EXPECT_EQ(size_t(0), handler->messages.size())
             << "no message handled yet";
 
@@ -582,16 +582,16 @@
             << "handled message";
     EXPECT_NEAR(100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "second poll should end around the time of the delayed message dispatch";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because message was sent";
 
     result = mLooper->pollOnce(100);
     elapsedMillis = ns2ms(stopWatch.elapsedTime());
 
     EXPECT_NEAR(100 + 100, elapsedMillis, TIMING_TOLERANCE_MS)
             << "third poll should timeout";
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT because there were no messages left";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT because there were no messages left";
 }
 
 TEST_F(LooperTest, SendMessageAtTime_WhenSentToThePast_ShouldInvokeHandlerDuringNextPoll) {
@@ -605,8 +605,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because message was already sent";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because message was sent";
     EXPECT_EQ(size_t(1), handler->messages.size())
             << "handled message";
     EXPECT_EQ(MSG_TEST1, handler->messages[0].what)
@@ -624,8 +624,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because message was already sent";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because message was sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because message was sent";
     EXPECT_EQ(size_t(1), handler->messages.size())
             << "handled message";
     EXPECT_EQ(MSG_TEST1, handler->messages[0].what)
@@ -645,15 +645,15 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because message was sent so looper was awoken";
-    EXPECT_EQ(ALOOPER_POLL_WAKE, result)
-            << "pollOnce result should be ALOOPER_POLL_WAKE because looper was awoken";
+    EXPECT_EQ(Looper::POLL_WAKE, result)
+            << "pollOnce result should be Looper::POLL_WAKE because looper was awoken";
     EXPECT_EQ(size_t(0), handler->messages.size())
             << "no messages to handle";
 
     result = mLooper->pollOnce(0);
 
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT because there was nothing to do";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT because there was nothing to do";
     EXPECT_EQ(size_t(0), handler->messages.size())
             << "no messages to handle";
 }
@@ -673,8 +673,8 @@
 
     EXPECT_NEAR(0, elapsedMillis, TIMING_TOLERANCE_MS)
             << "elapsed time should approx. zero because message was sent so looper was awoken";
-    EXPECT_EQ(ALOOPER_POLL_CALLBACK, result)
-            << "pollOnce result should be ALOOPER_POLL_CALLBACK because two messages were sent";
+    EXPECT_EQ(Looper::POLL_CALLBACK, result)
+            << "pollOnce result should be Looper::POLL_CALLBACK because two messages were sent";
     EXPECT_EQ(size_t(2), handler->messages.size())
             << "no messages to handle";
     EXPECT_EQ(MSG_TEST2, handler->messages[0].what)
@@ -684,8 +684,8 @@
 
     result = mLooper->pollOnce(0);
 
-    EXPECT_EQ(ALOOPER_POLL_TIMEOUT, result)
-            << "pollOnce result should be ALOOPER_POLL_TIMEOUT because there was nothing to do";
+    EXPECT_EQ(Looper::POLL_TIMEOUT, result)
+            << "pollOnce result should be Looper::POLL_TIMEOUT because there was nothing to do";
     EXPECT_EQ(size_t(2), handler->messages.size())
             << "no more messages to handle";
 }