From aaf3915bfd4f129769512986d5e471b9182b8bb1 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Thu, 26 May 2022 10:53:38 -0700 Subject: [PATCH] Ensure content-overlay is removed on app re-launch When app is re-launched, WM shell enters the exitPip process and within which we should ensure any content-overlay attached to the on-going animator is removed. Bug: 232439933 Test: re-launch app immediately after app explictly calls enterPip Change-Id: I17a204378c75d2442db588a1fa8cc2917f00b3f4 --- .../wm/shell/pip/PipAnimationController.java | 10 +++++ .../wm/shell/pip/PipTaskOrganizer.java | 38 +++++++++---------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java index 22d1564cf2c4d..4eba1697b5957 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java @@ -25,6 +25,7 @@ import android.animation.Animator; import android.animation.RectEvaluator; import android.animation.ValueAnimator; import android.annotation.IntDef; +import android.annotation.NonNull; import android.app.TaskInfo; import android.content.Context; import android.graphics.Rect; @@ -194,6 +195,15 @@ public class PipAnimationController { return animator; } + /** + * Quietly cancel the animator by removing the listeners first. + */ + static void quietCancel(@NonNull ValueAnimator animator) { + animator.removeAllUpdateListeners(); + animator.removeAllListeners(); + animator.cancel(); + } + /** * Additional callback interface for PiP animation */ diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java index 694b69390be43..c05654a740347 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java @@ -457,6 +457,9 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, wct.setBoundsChangeTransaction(mToken, tx); } + // Cancel the existing animator if there is any. + cancelCurrentAnimator(); + // Set the exiting state first so if there is fixed rotation later, the running animation // won't be interrupted by alpha animation for existing PiP. mPipTransitionState.setTransitionState(PipTransitionState.EXITING_PIP); @@ -802,18 +805,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, return; } - final PipAnimationController.PipTransitionAnimator animator = - mPipAnimationController.getCurrentAnimator(); - if (animator != null) { - if (animator.getContentOverlayLeash() != null) { - removeContentOverlay(animator.getContentOverlayLeash(), - animator::clearContentOverlay); - } - animator.removeAllUpdateListeners(); - animator.removeAllListeners(); - animator.cancel(); - } - + cancelCurrentAnimator(); onExitPipFinished(info); if (Transitions.ENABLE_SHELL_TRANSITIONS) { @@ -1050,9 +1042,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, int direction = TRANSITION_DIRECTION_NONE; if (animator != null) { direction = animator.getTransitionDirection(); - animator.removeAllUpdateListeners(); - animator.removeAllListeners(); - animator.cancel(); + PipAnimationController.quietCancel(animator); // Do notify the listeners that this was canceled sendOnPipTransitionCancelled(direction); sendOnPipTransitionFinished(direction); @@ -1586,10 +1576,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, // set a start delay on this animation. ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, "%s: Task vanished, skip fadeOutAndRemoveOverlay", TAG); - animation.removeAllListeners(); - animation.removeAllUpdateListeners(); - animation.cancel(); - } else { + PipAnimationController.quietCancel(animation); + } else if (surface.isValid()) { final float alpha = (float) animation.getAnimatedValue(); final SurfaceControl.Transaction transaction = mSurfaceControlTransactionFactory.getTransaction(); @@ -1628,6 +1616,18 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, tx.apply(); } + private void cancelCurrentAnimator() { + final PipAnimationController.PipTransitionAnimator animator = + mPipAnimationController.getCurrentAnimator(); + if (animator != null) { + if (animator.getContentOverlayLeash() != null) { + removeContentOverlay(animator.getContentOverlayLeash(), + animator::clearContentOverlay); + } + PipAnimationController.quietCancel(animator); + } + } + @VisibleForTesting public void setSurfaceControlTransactionFactory( PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) {