summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
author Ikram Gabiyev <gabiyev@google.com> 2024-11-19 16:08:43 -0800
committer Ikram Gabiyev <gabiyev@google.com> 2024-11-19 16:28:18 -0800
commit777bbee092fdedfc57ccae03eddf0d04936571db (patch)
treee6545469b5c1772a9132f5b13abd97feada5ca0d /libs
parent172621540c16d3f0ef19a0dae9ce721a78caab76 (diff)
Implement early animation cancel thru merge
Upon receiving a merge signal on expand PiP, end the animation early and finish the current transition. Also make sure to clear mFinishCallback cache before calling onTransitionFinish(). Otherwise, we might have a merge candidate come in and cache its own finishCallback before we clear it. This should fix issues we have been having with PinnedStackTests, where some transitions would be left unfinished causing breaks. Bug: 379390590 Flag: com.android.wm.shell.enable_pip2 Test: atest PinnedStackTests Change-Id: I14fe9f845c8ee5e039213fb823dbf07f1663afe1
Diffstat (limited to 'libs')
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java42
1 files changed, 33 insertions, 9 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java
index 6471760be6d8..2bcbe3013397 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipTransition.java
@@ -31,6 +31,7 @@ import static com.android.wm.shell.transition.Transitions.TRANSIT_EXIT_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_REMOVE_PIP;
import static com.android.wm.shell.transition.Transitions.TRANSIT_RESIZE_PIP;
+import android.animation.ValueAnimator;
import android.annotation.NonNull;
import android.app.ActivityManager;
import android.app.PictureInPictureParams;
@@ -120,6 +121,8 @@ public class PipTransition extends PipTransitionController implements
@Nullable
private Transitions.TransitionFinishCallback mFinishCallback;
+ private ValueAnimator mTransitionAnimator;
+
public PipTransition(
Context context,
@NonNull ShellInit shellInit,
@@ -209,7 +212,12 @@ public class PipTransition extends PipTransitionController implements
@Override
public void mergeAnimation(@NonNull IBinder transition, @NonNull TransitionInfo info,
@NonNull SurfaceControl.Transaction t, @NonNull IBinder mergeTarget,
- @NonNull Transitions.TransitionFinishCallback finishCallback) {}
+ @NonNull Transitions.TransitionFinishCallback finishCallback) {
+ // Just jump-cut the current animation if any, but do not merge.
+ if (info.getType() == TRANSIT_EXIT_PIP) {
+ end();
+ }
+ }
@Override
public void onTransitionConsumed(@NonNull IBinder transition, boolean aborted,
@@ -271,6 +279,14 @@ public class PipTransition extends PipTransitionController implements
return false;
}
+ @Override
+ public void end() {
+ if (mTransitionAnimator != null && mTransitionAnimator.isRunning()) {
+ mTransitionAnimator.end();
+ mTransitionAnimator = null;
+ }
+ }
+
//
// Animation schedulers and entry points
//
@@ -438,7 +454,7 @@ public class PipTransition extends PipTransitionController implements
}
finishTransition();
});
- animator.start();
+ cacheAndStartTransitionAnimator(animator);
return true;
}
@@ -538,7 +554,7 @@ public class PipTransition extends PipTransitionController implements
PipAlphaAnimator.FADE_IN);
// This should update the pip transition state accordingly after we stop playing.
animator.setAnimationEndCallback(this::finishTransition);
- animator.start();
+ cacheAndStartTransitionAnimator(animator);
return true;
}
@@ -608,7 +624,7 @@ public class PipTransition extends PipTransitionController implements
}
finishTransition();
});
- animator.start();
+ cacheAndStartTransitionAnimator(animator);
return true;
}
@@ -834,17 +850,17 @@ public class PipTransition extends PipTransitionController implements
return leash;
}
+ void cacheAndStartTransitionAnimator(@NonNull ValueAnimator animator) {
+ mTransitionAnimator = animator;
+ mTransitionAnimator.start();
+ }
+
//
// Miscellaneous callbacks and listeners
//
@Override
public void finishTransition() {
- if (mFinishCallback != null) {
- mFinishCallback.onTransitionFinished(null /* finishWct */);
- mFinishCallback = null;
- }
-
final int currentState = mPipTransitionState.getState();
int nextState = PipTransitionState.UNDEFINED;
switch (currentState) {
@@ -859,6 +875,14 @@ public class PipTransition extends PipTransitionController implements
break;
}
mPipTransitionState.setState(nextState);
+
+ if (mFinishCallback != null) {
+ // Need to unset mFinishCallback first because onTransitionFinished can re-enter this
+ // handler if there is a pending PiP animation.
+ final Transitions.TransitionFinishCallback finishCallback = mFinishCallback;
+ mFinishCallback = null;
+ finishCallback.onTransitionFinished(null /* finishWct */);
+ }
}
@Override