Fix AVD memory leak

The memory leak was caused by a lingering internal listener
that held a global ref to the AVD java object when the AVD is
infinite. As a result, the native VectorDrawable Tree can
not be destroyed, and therefore leak bitmaps.

This memory leak is fixed by removing all the internal listeners
for all the unfinished AVDs when the animation context is
destroyed.

BUG: 37518414
Test: follow steps in comment #1 of the bug, and inspect memory heap.

Change-Id: Ibbd1547a083b83d0cebd8e304d9b01abda4950ef
diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp
index 192e3bb..e71b673 100644
--- a/core/jni/android_view_ThreadedRenderer.cpp
+++ b/core/jni/android_view_ThreadedRenderer.cpp
@@ -208,8 +208,15 @@
 
     void detachAnimators() {
         // Remove animators from the list and post a delayed message in future to end the animator
+        // For infinite animators, remove the listener so we no longer hold a global ref to the AVD
+        // java object, and therefore the AVD objects in both native and Java can be properly
+        // released.
         for (auto& anim : mRunningVDAnimators) {
             detachVectorDrawableAnimator(anim.get());
+            anim->clearOneShotListener();
+        }
+        for (auto& anim : mPausedVDAnimators) {
+            anim->clearOneShotListener();
         }
         mRunningVDAnimators.clear();
         mPausedVDAnimators.clear();