Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 78d1ad2c authored by wilsonshih's avatar wilsonshih
Browse files

Do not delete task snapshot files when user stopped.

While pause a user, the tasks of the user will be removed from
recents. But there should just release memory vs delete snapshot files
when unloadUserDataFromMemoryLocked called. So the snapshot can be
reload from disk when user unlocked again.

Bug: 366374788
Flag: EXEMPT bugfix
Test: turn off device while some tasks of second user are exist, turn
on device, verify those tasks of second user shown on recents.
Stop second user without launch any task, verify no tasks of second
user shown on recents.
Enable second user again, verify those tasks can shown on recents.
Test: atest RecentTasksTest
Test: follow issue description.

Change-Id: I9a98339eaf6bd1a171aced598f61396eea7f8af2
parent 201ec7ec
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -551,6 +551,12 @@ class RecentTasks {
        long currentElapsedTime = SystemClock.elapsedRealtime();
        for (int i = 0; i < tasks.size(); i++) {
            Task task = tasks.get(i);
            // Remove the task restored from xml if any existing tasks match.
            if (findRemoveIndexForAddTask(task) >= 0) {
                tasks.remove(i);
                i--;
                continue;
            }
            task.lastActiveTime = currentElapsedTime - i;
        }

@@ -561,6 +567,7 @@ class RecentTasks {
        if (existedTaskIds.size() > 0) {
            syncPersistentTaskIdsLocked();
        }
        mTaskNotificationController.notifyTaskListUpdated();
    }

    private boolean isRecentTasksLoaded(int userId) {
@@ -679,26 +686,34 @@ class RecentTasks {
        if (isRecentTasksLoaded(userId)) {
            Slog.i(TAG, "Unloading recents for user " + userId + " from memory.");
            mUsersWithRecentsLoaded.delete(userId);
            removeTasksForUserLocked(userId);
            removeTasksForUserFromMemoryLocked(userId);
        }
        mPersistedTaskIds.delete(userId);
        mTaskPersister.unloadUserDataFromMemory(userId);
    }

    /** Remove recent tasks for a user. */
    private void removeTasksForUserLocked(int userId) {
    private void removeTasksForUserFromMemoryLocked(int userId) {
        if (userId <= 0) {
            Slog.i(TAG, "Can't remove recent task on user " + userId);
            return;
        }

        boolean notifyTaskUpdated = false;
        for (int i = mTasks.size() - 1; i >= 0; --i) {
            Task task = mTasks.get(i);
            if (task.mUserId == userId) {
                ProtoLog.i(WM_DEBUG_TASKS, "remove RecentTask %s when finishing user "
                        + "%d", task, userId);
                remove(task);
                mTasks.remove(task);
                mService.mWindowManager.mSnapshotController.mTaskSnapshotController
                        .removeSnapshotCache(task.mTaskId);
                // Only notify if list has changed.
                notifyTaskUpdated = true;
            }
        }
        if (notifyTaskUpdated) {
            mTaskNotificationController.notifyTaskListUpdated();
        }
    }