From e8e9069b3a93b430bd8bd144ed8f792fa810fe76 Mon Sep 17 00:00:00 2001 From: lpeter Date: Tue, 2 May 2023 13:37:09 +0000 Subject: [PATCH] Return right activities in getTopVisibleActivities method Currently, it will only return a top visible activity for every visible root task in the getTopVisibleActivities method. On a split screen, there will be two visible activities in the same root task. It will miss to return an activity when using the getTopVisibleActivities method on the split screen. We need to return right activities on the split screen in getTopVisibleActivities method. Bug: 245507506 Test: atest CtsVoiceInteractionTestCases Test: manual test Change-Id: Id9df59be04bfe805a160d41f044386c3d20eecb6 --- .../wm/ActivityTaskManagerInternal.java | 3 +++ .../server/wm/RootWindowContainer.java | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java b/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java index bfb735de2d0a6..1a836dbb45646 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java +++ b/services/core/java/com/android/server/wm/ActivityTaskManagerInternal.java @@ -171,6 +171,9 @@ public abstract class ActivityTaskManagerInternal { /** * Returns the top activity from each of the currently visible root tasks, and the related task * id. The first entry will be the focused activity. + * + *

NOTE: If the top activity is in the split screen, the other activities in the same split + * screen will also be returned. */ public abstract List getTopVisibleActivities(); diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index cd4b3c565a41d..355c142b92983 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -1741,9 +1741,13 @@ class RootWindowContainer extends WindowContainer /** * @return a list of pairs, containing activities and their task id which are the top ones in * each visible root task. The first entry will be the focused activity. + * + *

NOTE: If the top activity is in the split screen, the other activities in the same split + * screen will also be returned. */ List getTopVisibleActivities() { final ArrayList topVisibleActivities = new ArrayList<>(); + final ArrayList activityAssistInfos = new ArrayList<>(); final Task topFocusedRootTask = getTopDisplayFocusedRootTask(); // Traverse all displays. forAllRootTasks(rootTask -> { @@ -1751,11 +1755,21 @@ class RootWindowContainer extends WindowContainer if (rootTask.shouldBeVisible(null /* starting */)) { final ActivityRecord top = rootTask.getTopNonFinishingActivity(); if (top != null) { - ActivityAssistInfo visibleActivity = new ActivityAssistInfo(top); + activityAssistInfos.clear(); + activityAssistInfos.add(new ActivityAssistInfo(top)); + // Check if the activity on the split screen. + final Task adjacentTask = top.getTask().getAdjacentTask(); + if (adjacentTask != null) { + final ActivityRecord adjacentActivityRecord = + adjacentTask.getTopNonFinishingActivity(); + if (adjacentActivityRecord != null) { + activityAssistInfos.add(new ActivityAssistInfo(adjacentActivityRecord)); + } + } if (rootTask == topFocusedRootTask) { - topVisibleActivities.add(0, visibleActivity); + topVisibleActivities.addAll(0, activityAssistInfos); } else { - topVisibleActivities.add(visibleActivity); + topVisibleActivities.addAll(activityAssistInfos); } } }