Fix issue with animations that couldn't be started

If we can't create a remote animation target for some reason
(removed from task, no main window, etc), SurfaceAnimator
called startAnimation but we never invoke the finish callback.

Thus, we need to make sure to also invoke the finish callback
when not using the AppWindowToken as part of the remote animation.

This actually happens if the main intent clears the task, like
Settings. In that case, it removes all sub activities, which then
get added to mClosingApps, which then are part of a transition.

It's questionable why this would need to happen, but we don't have
the risk budget to go down that rabbit hole.

Test: RemoteAnimationControllerTest
Test: Open Settings -> Network -> Wifi, press home, reopen
Settings, repeat 10x
Test: adb shell dumpsys window -a
Fixes: 76438155
Change-Id: Ib528d5c0d3559eb20522799af68ebbfb17b9801b
diff --git a/services/core/java/com/android/server/wm/RemoteAnimationController.java b/services/core/java/com/android/server/wm/RemoteAnimationController.java
index 88577d0..541a6f6 100644
--- a/services/core/java/com/android/server/wm/RemoteAnimationController.java
+++ b/services/core/java/com/android/server/wm/RemoteAnimationController.java
@@ -133,11 +133,18 @@
     private RemoteAnimationTarget[] createAnimations() {
         final ArrayList<RemoteAnimationTarget> targets = new ArrayList<>();
         for (int i = mPendingAnimations.size() - 1; i >= 0; i--) {
+            final RemoteAnimationAdapterWrapper wrapper = mPendingAnimations.get(i);
             final RemoteAnimationTarget target =
                     mPendingAnimations.get(i).createRemoteAppAnimation();
             if (target != null) {
                 targets.add(target);
             } else {
+
+                // We can't really start an animation but we still need to make sure to finish the
+                // pending animation that was started by SurfaceAnimator
+                if (wrapper.mCapturedFinishCallback != null) {
+                    wrapper.mCapturedFinishCallback.onAnimationFinished(wrapper);
+                }
                 mPendingAnimations.remove(i);
             }
         }