Merge "Ensure content-overlay is removed on app re-launch" into tm-dev am: 999a0666ac

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18618656

Change-Id: If2792dc20f7c457998b9892918ad34fb1ddd48bb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Hongwei Wang
2022-05-27 16:47:40 +00:00
committed by Automerger Merge Worker
2 changed files with 29 additions and 19 deletions

View File

@@ -25,6 +25,7 @@ import android.animation.Animator;
import android.animation.RectEvaluator; import android.animation.RectEvaluator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.annotation.IntDef; import android.annotation.IntDef;
import android.annotation.NonNull;
import android.app.TaskInfo; import android.app.TaskInfo;
import android.content.Context; import android.content.Context;
import android.graphics.Rect; import android.graphics.Rect;
@@ -194,6 +195,15 @@ public class PipAnimationController {
return animator; 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 * Additional callback interface for PiP animation
*/ */

View File

@@ -457,6 +457,9 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
wct.setBoundsChangeTransaction(mToken, tx); 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 // 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. // won't be interrupted by alpha animation for existing PiP.
mPipTransitionState.setTransitionState(PipTransitionState.EXITING_PIP); mPipTransitionState.setTransitionState(PipTransitionState.EXITING_PIP);
@@ -802,18 +805,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
return; return;
} }
final PipAnimationController.PipTransitionAnimator<?> animator = cancelCurrentAnimator();
mPipAnimationController.getCurrentAnimator();
if (animator != null) {
if (animator.getContentOverlayLeash() != null) {
removeContentOverlay(animator.getContentOverlayLeash(),
animator::clearContentOverlay);
}
animator.removeAllUpdateListeners();
animator.removeAllListeners();
animator.cancel();
}
onExitPipFinished(info); onExitPipFinished(info);
if (Transitions.ENABLE_SHELL_TRANSITIONS) { if (Transitions.ENABLE_SHELL_TRANSITIONS) {
@@ -1050,9 +1042,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
int direction = TRANSITION_DIRECTION_NONE; int direction = TRANSITION_DIRECTION_NONE;
if (animator != null) { if (animator != null) {
direction = animator.getTransitionDirection(); direction = animator.getTransitionDirection();
animator.removeAllUpdateListeners(); PipAnimationController.quietCancel(animator);
animator.removeAllListeners();
animator.cancel();
// Do notify the listeners that this was canceled // Do notify the listeners that this was canceled
sendOnPipTransitionCancelled(direction); sendOnPipTransitionCancelled(direction);
sendOnPipTransitionFinished(direction); sendOnPipTransitionFinished(direction);
@@ -1586,10 +1576,8 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
// set a start delay on this animation. // set a start delay on this animation.
ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE,
"%s: Task vanished, skip fadeOutAndRemoveOverlay", TAG); "%s: Task vanished, skip fadeOutAndRemoveOverlay", TAG);
animation.removeAllListeners(); PipAnimationController.quietCancel(animation);
animation.removeAllUpdateListeners(); } else if (surface.isValid()) {
animation.cancel();
} else {
final float alpha = (float) animation.getAnimatedValue(); final float alpha = (float) animation.getAnimatedValue();
final SurfaceControl.Transaction transaction = final SurfaceControl.Transaction transaction =
mSurfaceControlTransactionFactory.getTransaction(); mSurfaceControlTransactionFactory.getTransaction();
@@ -1628,6 +1616,18 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
tx.apply(); 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 @VisibleForTesting
public void setSurfaceControlTransactionFactory( public void setSurfaceControlTransactionFactory(
PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) { PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) {