Do not put in-recent task in hidden task list

Tasks that cannot be accessed recently are hidden tasks, and the tasks
will be removed when going to home to avoid leakage. But the task may
be added to recent task again according to back stack, then it should
not be hidden anymore, otherwise it may be removed unexpectedly.

Also guard the case when performing the removal of hidden tasks.

Fixes: 149538962
Test: RecentTasksTest#testAddTasksHomeClearUntrackedTasks_expectFinish
Change-Id: I3de151aaeaad311f863c3867102a916779370407
This commit is contained in:
Riddle Hsu
2020-06-29 17:02:57 +08:00
parent 46986caa19
commit a9391ebe84
2 changed files with 12 additions and 7 deletions

View File

@@ -1426,8 +1426,8 @@ class RecentTasks {
private void removeUnreachableHiddenTasks(int windowingMode) {
for (int i = mHiddenTasks.size() - 1; i >= 0; i--) {
final Task hiddenTask = mHiddenTasks.get(i);
if (!hiddenTask.hasChild()) {
// The task was removed by other path.
if (!hiddenTask.hasChild() || hiddenTask.inRecents) {
// The task was removed by other path or it became reachable (added to recents).
mHiddenTasks.remove(i);
continue;
}
@@ -1449,6 +1449,9 @@ class RecentTasks {
* of task as the given one.
*/
private void removeForAddTask(Task task) {
// The adding task will be in recents so it is not hidden.
mHiddenTasks.remove(task);
final int removeIndex = findRemoveIndexForAddTask(task);
if (removeIndex == -1) {
// Nothing to trim
@@ -1460,8 +1463,6 @@ class RecentTasks {
// callbacks here.
final Task removedTask = mTasks.remove(removeIndex);
if (removedTask != task) {
// The added task is in recents so it is not hidden.
mHiddenTasks.remove(task);
if (removedTask.hasChild()) {
// A non-empty task is replaced by a new task. Because the removed task is no longer
// managed by the recent tasks list, add it to the hidden list to prevent the task

View File

@@ -464,15 +464,19 @@ public class RecentTasksTest extends ActivityTestsBase {
mRecentTasks.add(task1);
final Task task2 = taskBuilder.apply(true /* visible */);
mRecentTasks.add(task2);
// Only the last task is kept in recents and the previous 2 tasks will becomes untracked
final Task task3 = createTaskBuilder(className).build();
mRecentTasks.add(task3);
// Only the last added task is kept in recents and the previous 2 tasks will become hidden
// tasks because their intents are identical.
mRecentTasks.add(createTaskBuilder(className).build());
mRecentTasks.add(task1);
// Go home to trigger the removal of untracked tasks.
mRecentTasks.add(createTaskBuilder(".Home").setStack(mTaskContainer.getRootHomeTask())
.build());
// The task was added into recents again so it is not hidden and shouldn't be removed.
assertNotNull(task1.getTopNonFinishingActivity());
// All activities in the invisible task should be finishing or removed.
assertNull(task1.getTopNonFinishingActivity());
assertNull(task3.getTopNonFinishingActivity());
// The visible task should not be affected.
assertNotNull(task2.getTopNonFinishingActivity());
}