[AChoreographer] Add private api that decouples from ALooper.

For ease of use by HWUI, we'll get rid of the reliance of a thread-local
ALooper:
* Rather than using AChoreographer_getInstance to access a thread-local
AChoreographer instance, the caller will be expected to create and
destroy its own instnace.
* For use by HWUI's own looper instance, _getFd() will expose the
underlying file descriptor from which events can be listened. The
corresponding choreographer combined callback can be called to flush
pending display events.

Bug: 136262896
Test: builds
Change-Id: I94f102da22974cbad37f21a68d2f04ac0cec5c78
diff --git a/libs/gui/DisplayEventDispatcher.cpp b/libs/gui/DisplayEventDispatcher.cpp
index 208d729..8af1a1c 100644
--- a/libs/gui/DisplayEventDispatcher.cpp
+++ b/libs/gui/DisplayEventDispatcher.cpp
@@ -50,17 +50,20 @@
         return result;
     }
 
-    int rc = mLooper->addFd(mReceiver.getFd(), 0, Looper::EVENT_INPUT, this, NULL);
-    if (rc < 0) {
-        return UNKNOWN_ERROR;
+    if (mLooper != nullptr) {
+        int rc = mLooper->addFd(mReceiver.getFd(), 0, Looper::EVENT_INPUT, this, NULL);
+        if (rc < 0) {
+            return UNKNOWN_ERROR;
+        }
     }
+
     return OK;
 }
 
 void DisplayEventDispatcher::dispose() {
     ALOGV("dispatcher %p ~ Disposing display event dispatcher.", this);
 
-    if (!mReceiver.initCheck()) {
+    if (!mReceiver.initCheck() && mLooper != nullptr) {
         mLooper->removeFd(mReceiver.getFd());
     }
 }
@@ -101,6 +104,10 @@
     mConfigChangeFlag = configChangeFlag;
 }
 
+int DisplayEventDispatcher::getFd() {
+    return mReceiver.getFd();
+}
+
 int DisplayEventDispatcher::handleEvent(int, int events, void*) {
     if (events & (Looper::EVENT_ERROR | Looper::EVENT_HANGUP)) {
         ALOGE("Display event receiver pipe was closed or an error occurred.  "