summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Louis Chang <louischang@google.com> 2023-07-13 03:24:13 +0000
committer Louis Chang <louischang@google.com> 2023-09-26 00:56:02 +0000
commit66c2a75b1f7a0eca910e9cc47d4cc796d69f792f (patch)
treed6c298da159aac29187e0133c713966199182a30
parentcb9ba1442e7174dbb10c371171dc14b03e40f113 (diff)
Removes the hidden tasks that exceeds the cache limit
Allows the system to cache a small number of hidden tasks and remove the oldest hidden task when exceeds the cache limit. Bug: 288627637 Bug: 166143360 Test: atest RecentTasksTest Change-Id: Ibb0a61fb1fa3543e8d6b6982d1b6f8325982abcb Merged-In: Ibb0a61fb1fa3543e8d6b6982d1b6f8325982abcb (cherry picked from commit f03c90017e43b37cea7341c26881fd9de668dfa6)
-rw-r--r--services/core/java/com/android/server/wm/RecentTasks.java12
1 files changed, 9 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/wm/RecentTasks.java b/services/core/java/com/android/server/wm/RecentTasks.java
index 4faaf5170f27..f33ecaa90531 100644
--- a/services/core/java/com/android/server/wm/RecentTasks.java
+++ b/services/core/java/com/android/server/wm/RecentTasks.java
@@ -183,6 +183,8 @@ class RecentTasks {
/** The non-empty tasks that are removed from recent tasks (see {@link #removeForAddTask}). */
private final ArrayList<Task> mHiddenTasks = new ArrayList<>();
+ /** The maximum size that the hidden tasks are cached. */
+ private static final int MAX_HIDDEN_TASK_SIZE = 10;
/** Whether to trim inactive tasks when activities are idle. */
private boolean mCheckTrimmableTasksOnIdle;
@@ -1497,9 +1499,13 @@ class RecentTasks {
return task.compareTo(rootHomeTask) < 0;
}
- /** Remove the tasks that user may not be able to return. */
+ /** Remove the tasks that user may not be able to return when exceeds the cache limit. */
private void removeUnreachableHiddenTasks(int windowingMode) {
- for (int i = mHiddenTasks.size() - 1; i >= 0; i--) {
+ final int size = mHiddenTasks.size();
+ if (size <= MAX_HIDDEN_TASK_SIZE) {
+ return;
+ }
+ for (int i = size - 1; i >= MAX_HIDDEN_TASK_SIZE; i--) {
final Task hiddenTask = mHiddenTasks.get(i);
if (!hiddenTask.hasChild() || hiddenTask.inRecents) {
// The task was removed by other path or it became reachable (added to recents).
@@ -1543,7 +1549,7 @@ class RecentTasks {
// 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
// from becoming dangling.
- mHiddenTasks.add(removedTask);
+ mHiddenTasks.add(0, removedTask);
}
notifyTaskRemoved(removedTask, false /* wasTrimmed */, false /* killProcess */);
if (DEBUG_RECENTS_TRIM_TASKS) {