From 25a7b1d9c217f547f05a59f8928d2f0268906eeb Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Wed, 21 Jun 2017 17:37:58 -0700 Subject: [PATCH] Ensure that the recent tasks are loaded for SysUI's current user. - At the point where we preload tasks, the current user in the system can be different than the "current" user from SystemUI's perspective. Instead of using the CURRENT user to get the recent tasks, use SystemUI's current user, to ensure that the tasks fetched are the same user as the user that we update the OVERVIEW_LAST_STACK_ACTIVE_TIME for (even if it's not the actual current user). - In addition, if user switch happens between preloadRawTasks() and preloadPlan(), ensure we are using the user which we loaded recent tasks for, for the same reason as above. Bug: 62440327 Test: Switch between users and ensure that tasks are not lost Change-Id: Ia7bbf7f4c4002f6082f6f668c15a8da705ff23eb --- .../systemui/recents/model/RecentsTaskLoadPlan.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java index 93033eae0db11..80c44a39bb0db 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java +++ b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java @@ -71,6 +71,7 @@ public class RecentsTaskLoadPlan { Context mContext; + int mPreloadedUserId; List mRawTasks; TaskStack mStack; ArraySet mCurrentQuietProfiles = new ArraySet(); @@ -83,9 +84,6 @@ public class RecentsTaskLoadPlan { private void updateCurrentQuietProfilesCache(int currentUserId) { mCurrentQuietProfiles.clear(); - if (currentUserId == UserHandle.USER_CURRENT) { - currentUserId = SystemServicesProxy.getInstance(mContext).getCurrentUser(); - } UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); List profiles = userManager.getProfiles(currentUserId); if (profiles != null) { @@ -105,9 +103,10 @@ public class RecentsTaskLoadPlan { * Note: Do not lock, callers should synchronize on the loader before making this call. */ void preloadRawTasks(boolean includeFrontMostExcludedTask) { - int currentUserId = UserHandle.USER_CURRENT; - updateCurrentQuietProfilesCache(currentUserId); SystemServicesProxy ssp = Recents.getSystemServices(); + int currentUserId = ssp.getCurrentUser(); + updateCurrentQuietProfilesCache(currentUserId); + mPreloadedUserId = currentUserId; mRawTasks = ssp.getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), currentUserId, includeFrontMostExcludedTask, mCurrentQuietProfiles); @@ -135,7 +134,6 @@ public class RecentsTaskLoadPlan { preloadRawTasks(includeFrontMostExcludedTask); } - SystemServicesProxy ssp = SystemServicesProxy.getInstance(mContext); SparseArray affiliatedTasks = new SparseArray<>(); SparseIntArray affiliatedTaskCounts = new SparseIntArray(); SparseBooleanArray lockedUsers = new SparseBooleanArray(); @@ -143,7 +141,7 @@ public class RecentsTaskLoadPlan { R.string.accessibility_recents_item_will_be_dismissed); String appInfoDescFormat = mContext.getString( R.string.accessibility_recents_item_open_app_info); - int currentUserId = ssp.getCurrentUser(); + int currentUserId = mPreloadedUserId; long legacyLastStackActiveTime = migrateLegacyLastStackActiveTime(currentUserId); long lastStackActiveTime = Settings.Secure.getLongForUser(mContext.getContentResolver(), Secure.OVERVIEW_LAST_STACK_ACTIVE_TIME, legacyLastStackActiveTime, currentUserId);