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

Commit e1dc1058 authored by Jorge Gil's avatar Jorge Gil
Browse files

Cancel veil animations on dispose

The veil animations may be ongoing when a window decoration is destroyed
and thus its veil surface is released, which leads to an NPE since the
surface has been removed and made null by the time the animator tries to
update it. This change cancels any animations before the surface is
released to prevent the crash.

Bug: 322570124
Test: drag a freeform task to split-left, open another app to
split-right, drag the left task from the handle into the split-left
visual indicator, verify no crash.

Change-Id: Ibce242104aa6fa46b57ed3b1fe36128ae34c97bf
parent 6561d91e
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ public class ResizeVeil {

        relayout(taskBounds, t);
        if (fadeIn) {
            cancelAnimation();
            mVeilAnimator = new ValueAnimator();
            mVeilAnimator.setFloatValues(0f, 1f);
            mVeilAnimator.setDuration(RESIZE_ALPHA_DURATION);
@@ -210,15 +211,16 @@ public class ResizeVeil {
     * Animate veil's alpha to 0, fading it out.
     */
    public void hideVeil() {
        final ValueAnimator animator = new ValueAnimator();
        animator.setFloatValues(1, 0);
        animator.setDuration(RESIZE_ALPHA_DURATION);
        animator.addUpdateListener(animation -> {
        cancelAnimation();
        mVeilAnimator = new ValueAnimator();
        mVeilAnimator.setFloatValues(1, 0);
        mVeilAnimator.setDuration(RESIZE_ALPHA_DURATION);
        mVeilAnimator.addUpdateListener(animation -> {
            SurfaceControl.Transaction t = mSurfaceControlTransactionSupplier.get();
            t.setAlpha(mVeilSurface, 1 - animator.getAnimatedFraction());
            t.setAlpha(mVeilSurface, 1 - mVeilAnimator.getAnimatedFraction());
            t.apply();
        });
        animator.addListener(new AnimatorListenerAdapter() {
        mVeilAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                SurfaceControl.Transaction t = mSurfaceControlTransactionSupplier.get();
@@ -226,7 +228,7 @@ public class ResizeVeil {
                t.apply();
            }
        });
        animator.start();
        mVeilAnimator.start();
    }

    @ColorRes
@@ -240,10 +242,20 @@ public class ResizeVeil {
        }
    }

    private void cancelAnimation() {
        if (mVeilAnimator != null) {
            mVeilAnimator.removeAllUpdateListeners();
            mVeilAnimator.cancel();
        }
    }

    /**
     * Dispose of veil when it is no longer needed, likely on close of its container decor.
     */
    void dispose() {
        cancelAnimation();
        mVeilAnimator = null;

        if (mViewHost != null) {
            mViewHost.release();
            mViewHost = null;