diff --git a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java index 1f8ddf0122..406e9f46ae 100644 --- a/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java +++ b/quickstep/src/com/android/quickstep/LauncherBackAnimationController.java @@ -185,6 +185,13 @@ public class LauncherBackAnimationController { @Override public void onBackProgressed(BackMotionEvent backMotionEvent) { mHandler.post(() -> { + LauncherBackAnimationController controller = mControllerRef.get(); + if (controller == null + || controller.mLauncher == null + || !controller.mLauncher.isStarted()) { + // Skip animating back progress if Launcher isn't visible yet. + return; + } mProgressAnimator.onBackProgressed(backMotionEvent); }); } @@ -294,6 +301,10 @@ public class LauncherBackAnimationController { SurfaceControl parent = viewRootImpl != null ? viewRootImpl.getSurfaceControl() : null; + if (parent == null || !parent.isValid()) { + // Parent surface is not ready at the moment. Retry later. + return; + } boolean isDarkTheme = Utilities.isDarkTheme(mLauncher); mScrimLayer = new SurfaceControl.Builder() .setName("Back to launcher background scrim") @@ -326,6 +337,10 @@ public class LauncherBackAnimationController { if (!mBackInProgress || mBackTarget == null) { return; } + if (mScrimLayer == null) { + // Scrim hasn't been attached yet. Let's attach it. + addScrimLayer(); + } float screenWidth = mStartRect.width(); float screenHeight = mStartRect.height(); float width = Utilities.mapRange(progress, 1, MIN_WINDOW_SCALE) * screenWidth; @@ -446,6 +461,9 @@ public class LauncherBackAnimationController { mScrimAlphaAnimator.cancel(); mScrimAlphaAnimator = null; } + if (mScrimLayer != null) { + removeScrimLayer(); + } } private void startTransitionAnimations(RectFSpringAnim springAnim, AnimatorSet anim) {