Allow animation in Android viewer

To do that, we let ALooper_pollAll return immediately rather than wait indefinitely.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2031383002

Review-Url: https://codereview.chromium.org/2031383002
diff --git a/tools/viewer/sk_app/android/surface_glue_android.cpp b/tools/viewer/sk_app/android/surface_glue_android.cpp
index daf26a3..1821a53 100644
--- a/tools/viewer/sk_app/android/surface_glue_android.cpp
+++ b/tools/viewer/sk_app/android/surface_glue_android.cpp
@@ -22,6 +22,7 @@
 #include "SkTypes.h"
 #include "SkUtils.h"
 #include "Window_android.h"
+#include "SkTime.h"
 
 namespace sk_app {
 
@@ -160,6 +161,8 @@
     return 1;  // continue receiving callbacks
 }
 
+static double now_ms() { return SkTime::GetMSecs(); }
+
 void* SkiaAndroidApp::pthread_main(void* arg) {
     SkDebugf("pthread_main begins");
 
@@ -173,16 +176,24 @@
     ALooper_addFd(looper, skiaAndroidApp->fPipes[0], LOOPER_ID_MESSAGEPIPE, ALOOPER_EVENT_INPUT,
                   message_callback, skiaAndroidApp);
 
-    int ident;
-    int events;
-    struct android_poll_source* source;
-
     skiaAndroidApp->fApp = Application::Create(0, nullptr, skiaAndroidApp);
 
-    while ((ident = ALooper_pollAll(-1, nullptr, &events, (void**)&source)) >= 0) {
-        SkDebugf("ALooper_pollAll ident=%d", ident);
+    double currentTime = 0.0;
+    double previousTime = 0.0;
+    while (true) {
+        const int ident = ALooper_pollAll(0, nullptr, nullptr, nullptr);
+
+        if (ident >= 0) {
+            SkDebugf("Unhandled ALooper_pollAll ident=%d !", ident);
+        } else {
+            previousTime = currentTime;
+            currentTime = now_ms();
+            skiaAndroidApp->fApp->onIdle(currentTime - previousTime);
+        }
     }
 
+    SkDebugf("pthread_main ends");
+
     return nullptr;
 }