Keeping only running users recents in memory
Currently, all the users' recent tasks are loaded into memory and kept
in sync with the persistent storage. This changes the system so
that it loads a users recents into memory lazily (i.e. when
getRecentTasks is called for that user) and unloads them from the
memory as soon as the user is stopped. This also required bucketizing
the taskIds per user, so that the next available taskId can be assigned
without having knowledge of all the tasks that are stored away in
persistent storage but are not available in memory.
Bug-Id: b/24569398
Change-Id: Ia5cb64d9f4ee727225dce34e45ca63e946ac27a8
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 312e309..07cc505 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -2590,8 +2590,9 @@
if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target
+ " out to bottom task " + bottom.task);
} else {
- targetTask = createTaskRecord(mStackSupervisor.getNextTaskId(), target.info,
- null, null, null, false);
+ targetTask = createTaskRecord(
+ mStackSupervisor.getNextTaskIdForUserLocked(target.userId),
+ target.info, null, null, null, false);
targetTask.affinityIntent = target.intent;
if (DEBUG_TASKS) Slog.v(TAG_TASKS, "Start pushing activity " + target
+ " out to new task " + target.task);
@@ -4798,7 +4799,8 @@
final boolean wasResumed = wasFocused && (prevStack.mResumedActivity == r);
final TaskRecord task = createTaskRecord(
- mStackSupervisor.getNextTaskId(), r.info, r.intent, null, null, true);
+ mStackSupervisor.getNextTaskIdForUserLocked(r.userId),
+ r.info, r.intent, null, null, true);
r.setTask(task, null);
task.addActivityToTop(r);
setAppTask(r, task);