Workaround for input ANR, always finish PiP menu activity.

- Always finish the PiP menu activity when the interaction is complete
  (either the menu is hidden after showing, or when the user stops
  interacting with it and it was shown for the dismiss overlay)
- Fix issue with bounds animation callback not working due to the app
  window being removed and not updating the app transition that its
  animation "finished"
- Add additional logging throughout to trace PiP animation

Bug: 36877782
Test: Enter PIP, tap to show menu, wait for it to hide, and then use
      wired headset button

Change-Id: Ie88ba107d7fffdd182a4063ef4f324b58669d0ad
diff --git a/services/core/java/com/android/server/wm/BoundsAnimationController.java b/services/core/java/com/android/server/wm/BoundsAnimationController.java
index 9f0ed21..7b8057ca 100644
--- a/services/core/java/com/android/server/wm/BoundsAnimationController.java
+++ b/services/core/java/com/android/server/wm/BoundsAnimationController.java
@@ -61,17 +61,21 @@
             extends WindowManagerInternal.AppTransitionListener implements Runnable {
 
         public void onAppTransitionCancelledLocked() {
+            if (DEBUG) Slog.d(TAG, "onAppTransitionCancelledLocked:"
+                    + " mFinishAnimationAfterTransition=" + mFinishAnimationAfterTransition);
             animationFinished();
         }
         public void onAppTransitionFinishedLocked(IBinder token) {
+            if (DEBUG) Slog.d(TAG, "onAppTransitionFinishedLocked:"
+                    + " mFinishAnimationAfterTransition=" + mFinishAnimationAfterTransition);
             animationFinished();
         }
         private void animationFinished() {
             if (mFinishAnimationAfterTransition) {
                 mHandler.removeCallbacks(this);
-                // This might end up calling into activity manager which will be bad since we have the
-                // window manager lock held at this point. Post a message to take care of the processing
-                // so we don't deadlock.
+                // This might end up calling into activity manager which will be bad since we have
+                // the window manager lock held at this point. Post a message to take care of the
+                // processing so we don't deadlock.
                 mHandler.post(this);
             }
         }
@@ -195,6 +199,7 @@
             if (!mTarget.setPinnedStackSize(mTmpRect, mTmpTaskBounds)) {
                 // Whoops, the target doesn't feel like animating anymore. Let's immediately finish
                 // any further animation.
+                if (DEBUG) Slog.d(TAG, "animateUpdate: cancelled");
                 animation.cancel();
             }
         }
@@ -203,7 +208,9 @@
         public void onAnimationEnd(Animator animation) {
             if (DEBUG) Slog.d(TAG, "onAnimationEnd: mTarget=" + mTarget
                     + " mMoveToFullScreen=" + mMoveToFullScreen
-                    + " mSkipAnimationEnd=" + mSkipAnimationEnd);
+                    + " mSkipAnimationEnd=" + mSkipAnimationEnd
+                    + " mFinishAnimationAfterTransition=" + mFinishAnimationAfterTransition
+                    + " mAppTransitionIsRunning=" + mAppTransition.isRunning());
 
             // There could be another animation running. For example in the
             // move to fullscreen case, recents will also be closing while the