From 26ac40305aac2ecb176e45485a2cebd3111c2dd9 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 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 --- .../server/am/ActivityManagerService.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java index 0751c2b3e816f..dea41e48c4b62 100644 --- a/services/java/com/android/server/am/ActivityManagerService.java +++ b/services/java/com/android/server/am/ActivityManagerService.java @@ -3355,6 +3355,24 @@ public final class ActivityManagerService extends ActivityManagerNative return ret; } + //explicitly remove thd old information in mRecentTasks when removing existing user. + private void removeRecentTaskLocked(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); + } + } + } + final void addRecentTaskLocked(TaskRecord task) { int N = mRecentTasks.size(); // Quick case: check if the top-most recent task is the same. @@ -16503,6 +16521,8 @@ public final class ActivityManagerService extends ActivityManagerNative // Kill all the processes for the user. forceStopUserLocked(userId, "finish user"); } + //explicitly remove the old information in mRecentTasks when removing existing user. + removeRecentTaskLocked(userId); } for (int i=0; i