Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a0718c6 authored by Hongwei Wang's avatar Hongwei Wang
Browse files

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
parent b6e3779d
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -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 -> {
            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);