Fix NPE in isTrimmable
Previous CL[1] makes the root home task nullable, which causes NPE
in RecentTask#isTrimmable. This CL adds null checks on the method and
other callers which don't have checks, and also marks
TaskDisplayArea#getRootHomeTask as @Nullable.
[1]: 3388bd2a0b0cdcb79c36d939f5913669de1b7b90
Test: atest RecentTasks RecentsAnimationControllerTest
Test: atest TaskDisplayAreaTests WindowStateTests
fixes: 155100679
Change-Id: I8a59fbcb99810172a3b3192917d24e5122a02476
diff --git a/services/core/java/com/android/server/wm/RecentTasks.java b/services/core/java/com/android/server/wm/RecentTasks.java
index d8a4ecb..1cd94b4 100644
--- a/services/core/java/com/android/server/wm/RecentTasks.java
+++ b/services/core/java/com/android/server/wm/RecentTasks.java
@@ -1387,9 +1387,7 @@
return false;
}
- /**
- * @return whether the given task can be trimmed even if it is outside the visible range.
- */
+ /** @return whether the given task can be trimmed even if it is outside the visible range. */
protected boolean isTrimmable(Task task) {
final ActivityStack stack = task.getStack();
@@ -1404,9 +1402,13 @@
return false;
}
+ final ActivityStack rootHomeTask = stack.getDisplayArea().getRootHomeTask();
+ // Home stack does not exist. Don't trim the task.
+ if (rootHomeTask == null) {
+ return false;
+ }
// Trim tasks that are behind the home task.
- final TaskDisplayArea taskDisplayArea = stack.getDisplayArea();
- return task.compareTo(taskDisplayArea.getRootHomeTask()) < 0;
+ return task.compareTo(rootHomeTask) < 0;
}
/** Remove the tasks that user may not be able to return. */
diff --git a/services/core/java/com/android/server/wm/RecentsAnimationController.java b/services/core/java/com/android/server/wm/RecentsAnimationController.java
index d6ddcd0..94c38ea 100644
--- a/services/core/java/com/android/server/wm/RecentsAnimationController.java
+++ b/services/core/java/com/android/server/wm/RecentsAnimationController.java
@@ -406,8 +406,9 @@
}
// Save the minimized home height
- mMinimizedHomeBounds = mDisplayContent.getDefaultTaskDisplayArea().getRootHomeTask()
- .getBounds();
+ final ActivityStack rootHomeTask =
+ mDisplayContent.getDefaultTaskDisplayArea().getRootHomeTask();
+ mMinimizedHomeBounds = rootHomeTask != null ? rootHomeTask.getBounds() : null;
mService.mWindowPlacerLocked.performSurfacePlacement();
diff --git a/services/core/java/com/android/server/wm/TaskDisplayArea.java b/services/core/java/com/android/server/wm/TaskDisplayArea.java
index 37a4c1f..6a7a5f9 100644
--- a/services/core/java/com/android/server/wm/TaskDisplayArea.java
+++ b/services/core/java/com/android/server/wm/TaskDisplayArea.java
@@ -195,7 +195,7 @@
return mChildren.indexOf(stack);
}
- ActivityStack getRootHomeTask() {
+ @Nullable ActivityStack getRootHomeTask() {
return mRootHomeTask;
}
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index a948ece..03e53e4 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -1509,7 +1509,7 @@
return mActivityRecord != null ? mActivityRecord.getTask() : null;
}
- ActivityStack getRootTask() {
+ @Nullable ActivityStack getRootTask() {
final Task task = getTask();
if (task != null) {
return (ActivityStack) task.getRootTask();
@@ -2532,7 +2532,7 @@
final Task task = getTask();
if (task != null) {
task.getDimBounds(mTmpRect);
- } else {
+ } else if (getRootTask() != null) {
getRootTask().getDimBounds(mTmpRect);
}
}