Add AnimatedImageDrawable to host build of libhwui

This puts Looper usages behind #ifdef __ANDROID__ as the looper is not
supported on host builds. Instead of using the looper to call the
InvokeListener, the listener is called directly for host.

Bug: 322360037
Test: build libhwui on host
Change-Id: I133fa5a7b50e9681160f0a70c23f3946b51a7cd6
diff --git a/libs/hwui/jni/AnimatedImageDrawable.cpp b/libs/hwui/jni/AnimatedImageDrawable.cpp
index 90b1da8..0f80c55 100644
--- a/libs/hwui/jni/AnimatedImageDrawable.cpp
+++ b/libs/hwui/jni/AnimatedImageDrawable.cpp
@@ -25,7 +25,9 @@
 #include <hwui/AnimatedImageDrawable.h>
 #include <hwui/Canvas.h>
 #include <hwui/ImageDecoder.h>
+#ifdef __ANDROID__
 #include <utils/Looper.h>
+#endif
 
 #include "ColorFilter.h"
 #include "GraphicsJNI.h"
@@ -180,6 +182,23 @@
     drawable->setRepetitionCount(loopCount);
 }
 
+#ifndef __ANDROID__
+struct Message {
+    Message(int w) {}
+};
+
+class MessageHandler : public virtual RefBase {
+protected:
+    virtual ~MessageHandler() override {}
+
+public:
+    /**
+     * Handles a message.
+     */
+    virtual void handleMessage(const Message& message) = 0;
+};
+#endif
+
 class InvokeListener : public MessageHandler {
 public:
     InvokeListener(JNIEnv* env, jobject javaObject) {
@@ -204,6 +223,7 @@
 };
 
 class JniAnimationEndListener : public OnAnimationEndListener {
+#ifdef __ANDROID__
 public:
     JniAnimationEndListener(sp<Looper>&& looper, JNIEnv* env, jobject javaObject) {
         mListener = new InvokeListener(env, javaObject);
@@ -215,6 +235,17 @@
 private:
     sp<InvokeListener> mListener;
     sp<Looper> mLooper;
+#else
+public:
+    JniAnimationEndListener(JNIEnv* env, jobject javaObject) {
+        mListener = new InvokeListener(env, javaObject);
+    }
+
+    void onAnimationEnd() override { mListener->handleMessage(0); }
+
+private:
+    sp<InvokeListener> mListener;
+#endif
 };
 
 static void AnimatedImageDrawable_nSetOnAnimationEndListener(JNIEnv* env, jobject /*clazz*/,
@@ -223,6 +254,7 @@
     if (!jdrawable) {
         drawable->setOnAnimationEndListener(nullptr);
     } else {
+#ifdef __ANDROID__
         sp<Looper> looper = Looper::getForThread();
         if (!looper.get()) {
             doThrowISE(env,
@@ -233,6 +265,10 @@
 
         drawable->setOnAnimationEndListener(
                 std::make_unique<JniAnimationEndListener>(std::move(looper), env, jdrawable));
+#else
+        drawable->setOnAnimationEndListener(
+                std::make_unique<JniAnimationEndListener>(env, jdrawable));
+#endif
     }
 }