From 0a0718c677a162ad7df2e72c1e9fc86f097ff2d8 Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Wed, 21 Jul 2021 23:31:48 -0700 Subject: [PATCH] Skip operation on content overlay if task's vanished The stack trace in b/194344478 and b/194280568 is actually from the preceding ActivityThreadTest test, which does not fail but does crash certain test cases after that. Since we may set a start delay on the content overlay fading out animation, there is chance that onTaskVanished happens before it is actually started. It's also possible that onTaskVanished happens during the content overlay fadeout. This CL should have addressed both cases. Bug: 194344478 Bug: 194280568 Test: atest --iteration 5 \ ActivityThreadTest#testHandlePictureInPictureRequested_overriddenToEnter \ ScreenshotTests#testScreenshotSecureLayers \ TaskStackChangedListenerTest#testTaskChangeCallBacks Change-Id: I81c0622966df32e02db7cb5aa3cd42d7c4af735e --- .../wm/shell/pip/PipTaskOrganizer.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) 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 a0d83c03da67b..fa76af0394a8b 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 @@ -1383,11 +1383,20 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, final ValueAnimator animator = ValueAnimator.ofFloat(1.0f, 0.0f); animator.setDuration(mCrossFadeAnimationDuration); animator.addUpdateListener(animation -> { - final float alpha = (float) animation.getAnimatedValue(); - final SurfaceControl.Transaction transaction = - mSurfaceControlTransactionFactory.getTransaction(); - transaction.setAlpha(surface, alpha); - transaction.apply(); + if (mPipTransitionState.getTransitionState() == PipTransitionState.UNDEFINED) { + // Could happen if onTaskVanished happens during the animation since we may have + // set a start delay on this animation. + Log.d(TAG, "Task vanished, skip fadeOutAndRemoveOverlay"); + animation.removeAllListeners(); + animation.removeAllUpdateListeners(); + animation.cancel(); + } else { + final float alpha = (float) animation.getAnimatedValue(); + final SurfaceControl.Transaction transaction = + mSurfaceControlTransactionFactory.getTransaction(); + transaction.setAlpha(surface, alpha); + transaction.apply(); + } }); animator.addListener(new AnimatorListenerAdapter() { @Override @@ -1400,6 +1409,10 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, } private void removeContentOverlay(SurfaceControl surface, Runnable callback) { + if (mPipTransitionState.getTransitionState() == PipTransitionState.UNDEFINED) { + // Avoid double removal, which is fatal. + return; + } final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction(); tx.remove(surface);