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]: 3388bd2a0b

Test: atest RecentTasks RecentsAnimationControllerTest
Test: atest TaskDisplayAreaTests WindowStateTests
fixes: 155100679
Change-Id: I8a59fbcb99810172a3b3192917d24e5122a02476
This commit is contained in:
Charles Chen
2020-05-15 17:32:03 +08:00
parent 54dd86ac12
commit 7d550c4fc4
4 changed files with 13 additions and 10 deletions

View File

@@ -1387,9 +1387,7 @@ class RecentTasks {
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 @@ class RecentTasks {
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. */

View File

@@ -406,8 +406,9 @@ public class RecentsAnimationController implements DeathRecipient {
}
// 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();

View File

@@ -195,7 +195,7 @@ final class TaskDisplayArea extends DisplayArea<ActivityStack> {
return mChildren.indexOf(stack);
}
ActivityStack getRootHomeTask() {
@Nullable ActivityStack getRootHomeTask() {
return mRootHomeTask;
}

View File

@@ -1509,7 +1509,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
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 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
final Task task = getTask();
if (task != null) {
task.getDimBounds(mTmpRect);
} else {
} else if (getRootTask() != null) {
getRootTask().getDimBounds(mTmpRect);
}
}