From e4dd9590735392eba76500d0acda53cf9d035856 Mon Sep 17 00:00:00 2001 From: Vinit Nayak Date: Wed, 15 Dec 2021 13:13:31 -0800 Subject: [PATCH] Add API to get multiple running tasks for split Bug: 205675364 Change-Id: Ia350e443b6b80ca8af2d546cb35cad23b212d86e --- .../shared/system/ActivityManagerWrapper.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java index 38eded8780146..48fcbbda7e467 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerWrapper.java @@ -61,7 +61,7 @@ import java.util.function.Consumer; public class ActivityManagerWrapper { private static final String TAG = "ActivityManagerWrapper"; - + private static final int NUM_RECENT_ACTIVITIES_REQUEST = 3; private static final ActivityManagerWrapper sInstance = new ActivityManagerWrapper(); // Should match the values in PhoneWindowManager @@ -112,6 +112,22 @@ public class ActivityManagerWrapper { return tasks.get(0); } + /** + * We ask for {@link #NUM_RECENT_ACTIVITIES_REQUEST} activities because when in split screen, + * we'll get back 2 activities for each split app and one for launcher. Launcher might be more + * "recently" used than one of the split apps so if we only request 2 tasks, then we might miss + * out on one of the split apps + * + * @return an array of up to {@link #NUM_RECENT_ACTIVITIES_REQUEST} running tasks + * filtering only for tasks that can be visible in the recent tasks list. + */ + public ActivityManager.RunningTaskInfo[] getRunningTasks(boolean filterOnlyVisibleRecents) { + // Note: The set of running tasks from the system is ordered by recency + List tasks = + mAtm.getTasks(NUM_RECENT_ACTIVITIES_REQUEST, filterOnlyVisibleRecents); + return tasks.toArray(new RunningTaskInfo[tasks.size()]); + } + /** * @return a list of the recents tasks. */