Prevent IndexOutOfBoundsException while removing activities
IndexOutOfBoundsException was thrown when traversing the Task
from bottom to top because the activity could be removed from
the Task and the activities are less than its original size.
Bug: 260643770
Test: 1) Start multiple activities in a Task
2) Swipe up to home
3) Kill the app process from shell
4) Remove the task from Recents
Change-Id: I64955415c04da30d7dc8a4681474ceb06db1e88b
This commit is contained in:
@@ -1591,15 +1591,22 @@ class Task extends TaskFragment {
|
|||||||
removeChild(r, reason);
|
removeChild(r, reason);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
final ArrayList<ActivityRecord> finishingActivities = new ArrayList<>();
|
||||||
|
forAllActivities(r -> {
|
||||||
|
if (r.finishing || (excludingTaskOverlay && r.isTaskOverlay())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
finishingActivities.add(r);
|
||||||
|
});
|
||||||
|
|
||||||
// Finish or destroy apps from the bottom to ensure that all the other activity have
|
// Finish or destroy apps from the bottom to ensure that all the other activity have
|
||||||
// been finished and the top task in another task gets resumed when a top activity is
|
// been finished and the top task in another task gets resumed when a top activity is
|
||||||
// removed. Otherwise, the next top activity could be started while the top activity
|
// removed. Otherwise, the next top activity could be started while the top activity
|
||||||
// is removed, which is not necessary since the next top activity is on the same Task
|
// is removed, which is not necessary since the next top activity is on the same Task
|
||||||
// and should also be removed.
|
// and should also be removed.
|
||||||
forAllActivities((r) -> {
|
for (int i = finishingActivities.size() - 1; i >= 0; i--) {
|
||||||
if (r.finishing || (excludingTaskOverlay && r.isTaskOverlay())) {
|
final ActivityRecord r = finishingActivities.get(i);
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Prevent the transition from being executed too early if the top activity is
|
// Prevent the transition from being executed too early if the top activity is
|
||||||
// resumed but the mVisibleRequested of any other activity is true, the transition
|
// resumed but the mVisibleRequested of any other activity is true, the transition
|
||||||
// should wait until next activity resumed.
|
// should wait until next activity resumed.
|
||||||
@@ -1609,7 +1616,7 @@ class Task extends TaskFragment {
|
|||||||
} else {
|
} else {
|
||||||
r.destroyIfPossible(reason);
|
r.destroyIfPossible(reason);
|
||||||
}
|
}
|
||||||
}, false /* traverseTopToBottom */);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user