From dfd7be012b889f92d3e7e6d80ff7fe6b55c75901 Mon Sep 17 00:00:00 2001 From: Winson Date: Tue, 10 May 2016 13:30:37 -0700 Subject: [PATCH] Fixing issue with excluded task showing when docking. - On multi-window state changes, we should not include the front most excluded task when fetching the task list. This CL also clarifies which tasks are included and excluded. Bug: 28452689 Change-Id: Ia30eaf75382286a9d4ee5a5b11013dddf8e4ac82 --- .../android/systemui/recents/RecentsActivity.java | 5 ++-- .../com/android/systemui/recents/RecentsImpl.java | 14 ++++----- .../systemui/recents/misc/SystemServicesProxy.java | 34 +++++++++++++--------- .../recents/model/RecentsTaskLoadPlan.java | 8 ++--- .../systemui/recents/model/RecentsTaskLoader.java | 4 +-- .../systemui/recents/tv/RecentsTvActivity.java | 2 +- .../android/systemui/recents/tv/RecentsTvImpl.java | 2 +- 7 files changed, 38 insertions(+), 31 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index a5f3e7700cf8..1875259a8476 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -364,7 +364,7 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD RecentsActivityLaunchState launchState = config.getLaunchState(); if (!loadPlan.hasTasks()) { loader.preloadTasks(loadPlan, launchState.launchedToTaskId, - launchState.launchedFromHome); + !launchState.launchedFromHome); } RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); @@ -453,7 +453,8 @@ public class RecentsActivity extends Activity implements ViewTreeObserver.OnPreD RecentsActivityLaunchState launchState = config.getLaunchState(); RecentsTaskLoader loader = Recents.getTaskLoader(); RecentsTaskLoadPlan loadPlan = loader.createLoadPlan(this); - loader.preloadTasks(loadPlan, -1 /* runningTaskId */, false /* isHomeStackVisible */); + loader.preloadTasks(loadPlan, -1 /* runningTaskId */, + false /* includeFrontMostExcludedTask */); RecentsTaskLoadPlan.Options loadOpts = new RecentsTaskLoadPlan.Options(); loadOpts.numVisibleTasks = launchState.launchedNumVisibleTasks; diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java index 297dec92d9b9..611f9f201f1e 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsImpl.java @@ -112,7 +112,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener // Load the next task only if we aren't svelte RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); - loader.preloadTasks(plan, -1, true /* isHomeStackVisible */); + loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */); RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); // This callback is made when a new activity is launched and the old one is paused // so ignore the current activity and try and preload the thumbnail for the @@ -189,7 +189,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener // We can use a new plan since the caches will be the same. RecentsTaskLoader loader = Recents.getTaskLoader(); RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); - loader.preloadTasks(plan, -1, true /* isHomeStackVisible */); + loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */); RecentsTaskLoadPlan.Options launchOpts = new RecentsTaskLoadPlan.Options(); launchOpts.numVisibleTasks = loader.getIconCacheSize(); launchOpts.numVisibleTaskThumbnails = loader.getThumbnailCacheSize(); @@ -366,8 +366,8 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener ActivityManager.RunningTaskInfo runningTask = ssp.getRunningTask(); RecentsTaskLoader loader = Recents.getTaskLoader(); sInstanceLoadPlan = loader.createLoadPlan(mContext); - sInstanceLoadPlan.preloadRawTasks(isHomeStackVisible.value); - loader.preloadTasks(sInstanceLoadPlan, runningTask.id, isHomeStackVisible.value); + sInstanceLoadPlan.preloadRawTasks(!isHomeStackVisible.value); + loader.preloadTasks(sInstanceLoadPlan, runningTask.id, !isHomeStackVisible.value); TaskStack stack = sInstanceLoadPlan.getTaskStack(); if (stack.getTaskCount() > 0) { // Only preload the icon (but not the thumbnail since it may not have been taken for @@ -401,7 +401,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener SystemServicesProxy ssp = Recents.getSystemServices(); RecentsTaskLoader loader = Recents.getTaskLoader(); RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); - loader.preloadTasks(plan, -1, true /* isHomeStackVisible */); + loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */); TaskStack focusedStack = plan.getTaskStack(); // Return early if there are no tasks in the focused stack @@ -453,7 +453,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener SystemServicesProxy ssp = Recents.getSystemServices(); RecentsTaskLoader loader = Recents.getTaskLoader(); RecentsTaskLoadPlan plan = loader.createLoadPlan(mContext); - loader.preloadTasks(plan, -1, true /* isHomeStackVisible */); + loader.preloadTasks(plan, -1, false /* includeFrontMostExcludedTask */); TaskStack focusedStack = plan.getTaskStack(); // Return early if there are no tasks in the focused stack @@ -818,7 +818,7 @@ public class RecentsImpl implements ActivityOptions.OnAnimationFinishedListener sInstanceLoadPlan = loader.createLoadPlan(mContext); } if (mLaunchedWhileDocking || mTriggeredFromAltTab || !sInstanceLoadPlan.hasTasks()) { - loader.preloadTasks(sInstanceLoadPlan, runningTask.id, isHomeStackVisible); + loader.preloadTasks(sInstanceLoadPlan, runningTask.id, !isHomeStackVisible); } TaskStack stack = sInstanceLoadPlan.getTaskStack(); diff --git a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java index 08b52d94ad20..62c1945c1171 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java +++ b/packages/SystemUI/src/com/android/systemui/recents/misc/SystemServicesProxy.java @@ -253,11 +253,12 @@ public class SystemServicesProxy { /** * Returns a list of the recents tasks. * - * @param isHomeStackVisible whether or not the home stack is currently visible. If it is - * visible, then we ignore all excluded tasks (even the first one). + * @param includeFrontMostExcludedTask if set, will ensure that the front most excluded task + * will be visible, otherwise no excluded tasks will be + * visible. */ public List getRecentTasks(int numLatestTasks, int userId, - boolean isHomeStackVisible, ArraySet quietProfileIds) { + boolean includeFrontMostExcludedTask, ArraySet quietProfileIds) { if (mAm == null) return null; // If we are mocking, then create some recent tasks @@ -295,13 +296,16 @@ public class SystemServicesProxy { // Remove home/recents/excluded tasks int minNumTasksToQuery = 10; int numTasksToQuery = Math.max(minNumTasksToQuery, numLatestTasks); - List tasks = mAm.getRecentTasksForUser(numTasksToQuery, - ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS | + int flags = ActivityManager.RECENT_IGNORE_HOME_STACK_TASKS | ActivityManager.RECENT_INGORE_DOCKED_STACK_TOP_TASK | ActivityManager.RECENT_INGORE_PINNED_STACK_TASKS | ActivityManager.RECENT_IGNORE_UNAVAILABLE | - ActivityManager.RECENT_INCLUDE_PROFILES | - ActivityManager.RECENT_WITH_EXCLUDED, userId); + ActivityManager.RECENT_INCLUDE_PROFILES; + if (includeFrontMostExcludedTask) { + flags |= ActivityManager.RECENT_WITH_EXCLUDED; + } + List tasks = mAm.getRecentTasksForUser(numTasksToQuery, + flags, userId); // Break early if we can't get a valid set of tasks if (tasks == null) { @@ -316,18 +320,20 @@ public class SystemServicesProxy { // NOTE: The order of these checks happens in the expected order of the traversal of the // tasks - // Check the first non-recents task, include this task even if it is marked as excluded - // from recents if we are currently in the app. In other words, only remove excluded - // tasks if it is not the first active task, and not in the blacklist. + // Remove the task if it is blacklisted + if (sRecentsBlacklist.contains(t.realActivity.getClassName())) { + iter.remove(); + } + + // Remove the task if it is marked as excluded, unless it is the first most task and we + // are requested to include it boolean isExcluded = (t.baseIntent.getFlags() & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS; - boolean isBlackListed = sRecentsBlacklist.contains(t.realActivity.getClassName()); - // Filter out recent tasks from managed profiles which are in quiet mode. isExcluded |= quietProfileIds.contains(t.userId); - if (isBlackListed || (isExcluded && (isHomeStackVisible || !isFirstValidTask))) { + if (isExcluded && (!isFirstValidTask || !includeFrontMostExcludedTask)) { iter.remove(); - continue; } + isFirstValidTask = false; } 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 251ad71e5d62..1278b735a7cd 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java +++ b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoadPlan.java @@ -100,12 +100,12 @@ public class RecentsTaskLoadPlan { * An optimization to preload the raw list of tasks. The raw tasks are saved in least-recent * to most-recent order. */ - public synchronized void preloadRawTasks(boolean isHomeStackVisible) { + public synchronized void preloadRawTasks(boolean includeFrontMostExcludedTask) { int currentUserId = UserHandle.USER_CURRENT; updateCurrentQuietProfilesCache(currentUserId); SystemServicesProxy ssp = Recents.getSystemServices(); mRawTasks = ssp.getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), - currentUserId, isHomeStackVisible, mCurrentQuietProfiles); + currentUserId, includeFrontMostExcludedTask, mCurrentQuietProfiles); // Since the raw tasks are given in most-recent to least-recent order, we need to reverse it Collections.reverse(mRawTasks); @@ -121,11 +121,11 @@ public class RecentsTaskLoadPlan { * - least-recent to most-recent freeform tasks */ public synchronized void preloadPlan(RecentsTaskLoader loader, int runningTaskId, - boolean isHomeStackVisible) { + boolean includeFrontMostExcludedTask) { Resources res = mContext.getResources(); ArrayList allTasks = new ArrayList<>(); if (mRawTasks == null) { - preloadRawTasks(isHomeStackVisible); + preloadRawTasks(includeFrontMostExcludedTask); } SparseArray affiliatedTasks = new SparseArray<>(); diff --git a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoader.java b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoader.java index 9460b642796e..ca59831786b4 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoader.java +++ b/packages/SystemUI/src/com/android/systemui/recents/model/RecentsTaskLoader.java @@ -334,8 +334,8 @@ public class RecentsTaskLoader { /** Preloads recents tasks using the specified plan to store the output. */ public void preloadTasks(RecentsTaskLoadPlan plan, int runningTaskId, - boolean isHomeStackVisible) { - plan.preloadPlan(this, runningTaskId, isHomeStackVisible); + boolean includeFrontMostExcludedTask) { + plan.preloadPlan(this, runningTaskId, includeFrontMostExcludedTask); } /** Begins loading the heavy task data according to the specified options. */ diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java index acebf427feab..3a17d222bda8 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java @@ -180,7 +180,7 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener { RecentsConfiguration config = Recents.getConfiguration(); RecentsActivityLaunchState launchState = config.getLaunchState(); if (!plan.hasTasks()) { - loader.preloadTasks(plan, -1, launchState.launchedFromHome); + loader.preloadTasks(plan, -1, !launchState.launchedFromHome); } mLaunchedFromHome = launchState.launchedFromHome; TaskStack stack = plan.getTaskStack(); diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvImpl.java b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvImpl.java index 6f7bd4146303..fca8d2d1fae1 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvImpl.java @@ -63,7 +63,7 @@ public class RecentsTvImpl extends RecentsImpl{ sInstanceLoadPlan = loader.createLoadPlan(mContext); } if (mTriggeredFromAltTab || !sInstanceLoadPlan.hasTasks()) { - loader.preloadTasks(sInstanceLoadPlan, runningTask.id, isHomeStackVisible); + loader.preloadTasks(sInstanceLoadPlan, runningTask.id, !isHomeStackVisible); } TaskStack stack = sInstanceLoadPlan.getTaskStack(); -- 2.11.0