From f77d2086c47043208cb6711bbd53927824b4d32d Mon Sep 17 00:00:00 2001 From: Schneider Victor-tulias Date: Fri, 28 Apr 2023 15:45:24 -0700 Subject: [PATCH] Add null checks for mRecentsView Fixed a NPE and added some null checks for mRecentsView. These NPEs can happen if the launcher is destroyed unexpectedly. Flag: not needed Fixes: 279738827 Test: ran launcher and tested some gestures Change-Id: I9c32e22a13d950346ce705ba3a6f11dd3f1da87f --- .../android/quickstep/AbsSwipeUpHandler.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index b7a29e0034..5333cbe919 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -177,7 +177,7 @@ public abstract class AbsSwipeUpHandler, protected @Nullable RecentsAnimationController mDeferredCleanupRecentsAnimationController; protected RecentsAnimationTargets mRecentsAnimationTargets; protected T mActivity; - protected Q mRecentsView; + protected @Nullable Q mRecentsView; protected Runnable mGestureEndCallback; protected MultiStateCallback mStateCallback; protected boolean mCanceled; @@ -1895,7 +1895,9 @@ public abstract class AbsSwipeUpHandler, private void invalidateHandlerWithLauncher() { endLauncherTransitionController(); - mRecentsView.onGestureAnimationEnd(); + if (mRecentsView != null) { + mRecentsView.onGestureAnimationEnd(); + } resetLauncherListeners(); } @@ -1922,7 +1924,9 @@ public abstract class AbsSwipeUpHandler, private void resetLauncherListeners() { mActivity.getRootView().setOnApplyWindowInsetsListener(null); - mRecentsView.removeOnScrollChangedListener(mOnRecentsScrollListener); + if (mRecentsView != null) { + mRecentsView.removeOnScrollChangedListener(mOnRecentsScrollListener); + } } private void resetStateForAnimationCancel() { @@ -1981,8 +1985,10 @@ public abstract class AbsSwipeUpHandler, private boolean updateThumbnail(int runningTaskId, boolean refreshView) { boolean finishTransitionPosted = false; final TaskView taskView; - if (mGestureState.getEndTarget() == HOME || mGestureState.getEndTarget() == NEW_TASK - || mGestureState.getEndTarget() == ALL_APPS) { + if (mGestureState.getEndTarget() == HOME + || mGestureState.getEndTarget() == NEW_TASK + || mGestureState.getEndTarget() == ALL_APPS + || mRecentsView == null) { // Capture the screenshot before finishing the transition to home or quickswitching to // ensure it's taken in the correct orientation, but no need to update the thumbnail. taskView = null; @@ -2135,7 +2141,7 @@ public abstract class AbsSwipeUpHandler, protected void startNewTask(Consumer resultCallback) { // Launch the task user scrolled to (mRecentsView.getNextPage()). if (!mCanceled) { - TaskView nextTask = mRecentsView.getNextPageTaskView(); + TaskView nextTask = mRecentsView == null ? null : mRecentsView.getNextPageTaskView(); if (nextTask != null) { Task.TaskKey nextTaskKey = nextTask.getTask().key; int taskId = nextTaskKey.id; @@ -2237,7 +2243,8 @@ public abstract class AbsSwipeUpHandler, return; } RemoteAnimationTarget taskTarget = taskTargetOptional.get(); - TaskView taskView = mRecentsView.getTaskViewByTaskId(taskTarget.taskId); + TaskView taskView = mRecentsView == null + ? null : mRecentsView.getTaskViewByTaskId(taskTarget.taskId); if (taskView == null || !taskView.getThumbnail().shouldShowSplashView()) { finishRecentsAnimationOnTasksAppeared(null /* onFinishComplete */); return; @@ -2296,9 +2303,11 @@ public abstract class AbsSwipeUpHandler, * resume if we finish the controller. */ protected int getLastAppearedTaskIndex() { - return mGestureState.getLastAppearedTaskId() != -1 - ? mRecentsView.getTaskIndexForId(mGestureState.getLastAppearedTaskId()) - : mRecentsView.getRunningTaskIndex(); + return mRecentsView == null + ? -1 + : mGestureState.getLastAppearedTaskId() != -1 + ? mRecentsView.getTaskIndexForId(mGestureState.getLastAppearedTaskId()) + : mRecentsView.getRunningTaskIndex(); } /**