From ad3aa32fee096f6887ba41bf0bf2b767cbdefeab Mon Sep 17 00:00:00 2001 From: Eunae Kim Date: Fri, 25 Jul 2014 09:16:13 +0900 Subject: [PATCH] =?UTF-8?q?Fix=20a=20bug=20that=20the=20RecentTask=20list?= =?UTF-8?q?=20of=20other=E2=80=99s=20may=20show=20up=20to=20non-primary=20?= =?UTF-8?q?users.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cherry-pick from aosp to lmp-dev. When switching to a newly created user, the user may face this bug when he opens the RecentTask screen. A possible bug scenario is described as follows: A user id of a removed user may be recycled when created a new user. However, mRecentTasks is not correctly controlled so that old information may still remain and be possibly mapped to wrong user. This patch prevents this bug by explicitly removing old information in mRecentTasks when removing existing user. Change-Id: I1874dbd604598a5d740ae1e034981e21214c15c6 Signed-off-by: Eunae Kim Conflicts: services/java/com/android/server/am/ActivityManagerService.java --- .../server/am/ActivityManagerService.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 1ae0bbcf3ae89..9a58c56674715 100755 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -3638,6 +3638,27 @@ public final class ActivityManagerService extends ActivityManagerNative return ret; } + //explicitly remove thd old information in mRecentTasks when removing existing user. + private void removeRecentTasksForUser(int userId) { + if(userId <= 0) { + Slog.i(TAG, "Can't remove recent task on user " + userId); + return; + } + + for (int i = mRecentTasks.size() - 1; i >= 0; --i) { + TaskRecord tr = mRecentTasks.get(i); + if (tr.userId == userId) { + if(DEBUG_TASKS) Slog.i(TAG, "remove RecentTask " + tr + + " when finishing user" + userId); + tr.disposeThumbnail(); + mRecentTasks.remove(i); + } + } + + // Remove tasks from persistent storage. + mTaskPersister.wakeup(null, true); + } + final void addRecentTaskLocked(TaskRecord task) { int N = mRecentTasks.size(); // Quick case: check if the top-most recent task is the same. @@ -17642,6 +17663,9 @@ public final class ActivityManagerService extends ActivityManagerNative } } + // Explicitly remove the old information in mRecentTasks. + removeRecentTasksForUser(userId); + for (int i=0; i