Protect against NPE when updating state

The TaskViewTaskController & state might be removed before one
of the visibility or bounds transactions are set, do nothing
in this case.

Test: atest TaskViewTransitionsTest
Bug: 280063582
Change-Id: If1384be31cd0668faba8d92d06a012ba6a5130dc
This commit is contained in:
Mady Mellor
2023-05-02 09:07:09 -07:00
parent a346767333
commit be465e8752
2 changed files with 23 additions and 1 deletions

View File

@@ -202,6 +202,7 @@ public class TaskViewTransitions implements Transitions.TransitionHandler {
}
void setTaskViewVisible(TaskViewTaskController taskView, boolean visible) {
if (mTaskViews.get(taskView) == null) return;
if (mTaskViews.get(taskView).mVisible == visible) return;
if (taskView.getTaskInfo() == null) {
// Nothing to update, task is not yet available
@@ -220,17 +221,19 @@ public class TaskViewTransitions implements Transitions.TransitionHandler {
void updateBoundsState(TaskViewTaskController taskView, Rect boundsOnScreen) {
TaskViewRequestedState state = mTaskViews.get(taskView);
if (state == null) return;
state.mBounds.set(boundsOnScreen);
}
void updateVisibilityState(TaskViewTaskController taskView, boolean visible) {
TaskViewRequestedState state = mTaskViews.get(taskView);
if (state == null) return;
state.mVisible = visible;
}
void setTaskBounds(TaskViewTaskController taskView, Rect boundsOnScreen) {
TaskViewRequestedState state = mTaskViews.get(taskView);
if (Objects.equals(boundsOnScreen, state.mBounds)) {
if (state == null || Objects.equals(boundsOnScreen, state.mBounds)) {
return;
}
state.mBounds.set(boundsOnScreen);

View File

@@ -179,4 +179,23 @@ public class TaskViewTransitionsTest extends ShellTestCase {
mTaskViewTransitions.findPending(mTaskViewTaskController, TRANSIT_CHANGE);
assertThat(pendingBounds2).isNull();
}
@Test
public void testSetTaskVisibility_taskRemoved_noNPE() {
mTaskViewTransitions.removeTaskView(mTaskViewTaskController);
assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS);
mTaskViewTransitions.setTaskViewVisible(mTaskViewTaskController, false);
}
@Test
public void testSetTaskBounds_taskRemoved_noNPE() {
mTaskViewTransitions.removeTaskView(mTaskViewTaskController);
assumeTrue(Transitions.ENABLE_SHELL_TRANSITIONS);
mTaskViewTransitions.setTaskBounds(mTaskViewTaskController,
new Rect(0, 0, 100, 100));
}
}