Merge "Ensure content-overlay is removed on app re-launch" into tm-dev

This commit is contained in:
Hongwei Wang
2022-05-27 16:28:08 +00:00
committed by Android (Google) Code Review
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.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
*/

View File

@@ -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) {