summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipAnimationController.java10
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java38
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 22d1564cf2c4..4eba1697b595 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;
@@ -195,6 +196,15 @@ public class PipAnimationController {
}
/**
+ * 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
*/
public static class PipAnimationCallback {
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 694b69390be4..c05654a74034 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) {