From 99866c56ad227f4ca43bd52a11f29aa59d08f581 Mon Sep 17 00:00:00 2001 From: Tony Huang Date: Wed, 18 May 2022 17:09:24 +0800 Subject: [PATCH] Fix NPE if draging again while animating The animator cancel calling might cause surfaces released by our implementation. Moving the cancel call before we make sure surface is not null. Fix: 230686609 Test: Open animation scale setting and try drop then drag again divider quickly Test: pass exising tests Change-Id: I2e94f3ece3f211ceb15f380e4ee9322b8c27f8ac --- .../wm/shell/common/split/SplitDecorManager.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitDecorManager.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitDecorManager.java index de30dbbe7e46c..484294ab295bc 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitDecorManager.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitDecorManager.java @@ -160,6 +160,15 @@ public class SplitDecorManager extends WindowlessWindowManager { mBounds.set(newBounds); } + final boolean show = + newBounds.width() > mBounds.width() || newBounds.height() > mBounds.height(); + final boolean animate = show != mShown; + if (animate && mFadeAnimator != null && mFadeAnimator.isRunning()) { + // If we need to animate and animator still running, cancel it before we ensure both + // background and icon surfaces are non null for next animation. + mFadeAnimator.cancel(); + } + if (mBackgroundLeash == null) { mBackgroundLeash = SurfaceUtils.makeColorLayer(mHostLeash, RESIZING_BACKGROUND_SURFACE_NAME, mSurfaceSession); @@ -183,11 +192,7 @@ public class SplitDecorManager extends WindowlessWindowManager { newBounds.width() / 2 - mIconSize / 2, newBounds.height() / 2 - mIconSize / 2); - boolean show = newBounds.width() > mBounds.width() || newBounds.height() > mBounds.height(); - if (show != mShown) { - if (mFadeAnimator != null && mFadeAnimator.isRunning()) { - mFadeAnimator.cancel(); - } + if (animate) { startFadeAnimation(show, false /* isResized */); mShown = show; }