diff options
| author | 2024-06-19 11:08:08 +0000 | |
|---|---|---|
| committer | 2024-06-24 14:50:44 +0000 | |
| commit | 7112c035b0b29afc53f68a03b30192268613a5b5 (patch) | |
| tree | c4fdbd1733ea15651b2580ed596371d378ebfbf0 | |
| parent | e84fdcef8279905f1fe5168645918827dfad4422 (diff) | |
Mark minimized Recents tasks in GroupedRecentTaskInfo.java and Task.java
With this CL we mark Recent Desktop tasks so that SystemUI / Launcher
can know which tasks are minimized.
Note: when we're in desktop mode it is enough to know whether a desktop
task is visible to know whether it is minimized. However, when outside
desktop mode (e.g. in Overview) all desktop tasks are marked invisible
so we need to have a separate field to know whether a task is minimized.
Bug: 333013317
Flag: com.android.window.flags.enable_desktop_windowing_mode
Test: manual: ensured minimized desktop tasks are not shown in Overview
Change-Id: I9011676234762a9b81d0df84c300fea05f6df442
4 files changed, 93 insertions, 17 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java index 9f3c519b441b..ad298dcc253e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/recents/RecentTasksController.java @@ -65,9 +65,11 @@ import com.android.wm.shell.util.SplitBounds; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.concurrent.Executor; import java.util.function.Consumer; @@ -394,6 +396,7 @@ public class RecentTasksController implements TaskStackListenerCallback, } ArrayList<ActivityManager.RecentTaskInfo> freeformTasks = new ArrayList<>(); + Set<Integer> minimizedFreeformTasks = new HashSet<>(); int mostRecentFreeformTaskIndex = Integer.MAX_VALUE; @@ -414,6 +417,9 @@ public class RecentTasksController implements TaskStackListenerCallback, mostRecentFreeformTaskIndex = recentTasks.size(); } freeformTasks.add(taskInfo); + if (mDesktopModeTaskRepository.get().isMinimizedTask(taskInfo.taskId)) { + minimizedFreeformTasks.add(taskInfo.taskId); + } continue; } @@ -431,8 +437,10 @@ public class RecentTasksController implements TaskStackListenerCallback, // Add a special entry for freeform tasks if (!freeformTasks.isEmpty()) { - recentTasks.add(mostRecentFreeformTaskIndex, GroupedRecentTaskInfo.forFreeformTasks( - freeformTasks.toArray(new ActivityManager.RecentTaskInfo[0]))); + recentTasks.add(mostRecentFreeformTaskIndex, + GroupedRecentTaskInfo.forFreeformTasks( + freeformTasks.toArray(new ActivityManager.RecentTaskInfo[0]), + minimizedFreeformTasks)); } return recentTasks; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/util/GroupedRecentTaskInfo.java b/libs/WindowManager/Shell/src/com/android/wm/shell/util/GroupedRecentTaskInfo.java index c045cebdf4e0..a2d2b9aff597 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/util/GroupedRecentTaskInfo.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/util/GroupedRecentTaskInfo.java @@ -27,6 +27,7 @@ import androidx.annotation.Nullable; import java.util.Arrays; import java.util.List; +import java.util.Set; /** * Simple container for recent tasks. May contain either a single or pair of tasks. @@ -50,6 +51,9 @@ public class GroupedRecentTaskInfo implements Parcelable { private final SplitBounds mSplitBounds; @GroupType private final int mType; + // TODO(b/348332802): move isMinimized inside each Task object instead once we have a + // replacement for RecentTaskInfo + private final int[] mMinimizedTaskIds; /** * Create new for a single task @@ -57,7 +61,7 @@ public class GroupedRecentTaskInfo implements Parcelable { public static GroupedRecentTaskInfo forSingleTask( @NonNull ActivityManager.RecentTaskInfo task) { return new GroupedRecentTaskInfo(new ActivityManager.RecentTaskInfo[]{task}, null, - TYPE_SINGLE); + TYPE_SINGLE, null /* minimizedFreeformTasks */); } /** @@ -66,28 +70,51 @@ public class GroupedRecentTaskInfo implements Parcelable { public static GroupedRecentTaskInfo forSplitTasks(@NonNull ActivityManager.RecentTaskInfo task1, @NonNull ActivityManager.RecentTaskInfo task2, @Nullable SplitBounds splitBounds) { return new GroupedRecentTaskInfo(new ActivityManager.RecentTaskInfo[]{task1, task2}, - splitBounds, TYPE_SPLIT); + splitBounds, TYPE_SPLIT, null /* minimizedFreeformTasks */); } /** * Create new for a group of freeform tasks */ public static GroupedRecentTaskInfo forFreeformTasks( - @NonNull ActivityManager.RecentTaskInfo... tasks) { - return new GroupedRecentTaskInfo(tasks, null, TYPE_FREEFORM); + @NonNull ActivityManager.RecentTaskInfo[] tasks, + @NonNull Set<Integer> minimizedFreeformTasks) { + return new GroupedRecentTaskInfo( + tasks, + null /* splitBounds */, + TYPE_FREEFORM, + minimizedFreeformTasks.stream().mapToInt(i -> i).toArray()); } - private GroupedRecentTaskInfo(@NonNull ActivityManager.RecentTaskInfo[] tasks, - @Nullable SplitBounds splitBounds, @GroupType int type) { + private GroupedRecentTaskInfo( + @NonNull ActivityManager.RecentTaskInfo[] tasks, + @Nullable SplitBounds splitBounds, + @GroupType int type, + @Nullable int[] minimizedFreeformTaskIds) { mTasks = tasks; mSplitBounds = splitBounds; mType = type; + mMinimizedTaskIds = minimizedFreeformTaskIds; + ensureAllMinimizedIdsPresent(tasks, minimizedFreeformTaskIds); + } + + private static void ensureAllMinimizedIdsPresent( + @NonNull ActivityManager.RecentTaskInfo[] tasks, + @Nullable int[] minimizedFreeformTaskIds) { + if (minimizedFreeformTaskIds == null) { + return; + } + if (!Arrays.stream(minimizedFreeformTaskIds).allMatch( + taskId -> Arrays.stream(tasks).anyMatch(task -> task.taskId == taskId))) { + throw new IllegalArgumentException("Minimized task IDs contain non-existent Task ID."); + } } GroupedRecentTaskInfo(Parcel parcel) { mTasks = parcel.createTypedArray(ActivityManager.RecentTaskInfo.CREATOR); mSplitBounds = parcel.readTypedObject(SplitBounds.CREATOR); mType = parcel.readInt(); + mMinimizedTaskIds = parcel.createIntArray(); } /** @@ -135,6 +162,10 @@ public class GroupedRecentTaskInfo implements Parcelable { return mType; } + public int[] getMinimizedTaskIds() { + return mMinimizedTaskIds; + } + @Override public String toString() { StringBuilder taskString = new StringBuilder(); @@ -161,6 +192,8 @@ public class GroupedRecentTaskInfo implements Parcelable { taskString.append("TYPE_FREEFORM"); break; } + taskString.append(", Minimized Task IDs: "); + taskString.append(Arrays.toString(mMinimizedTaskIds)); return taskString.toString(); } @@ -181,6 +214,7 @@ public class GroupedRecentTaskInfo implements Parcelable { parcel.writeTypedArray(mTasks, flags); parcel.writeTypedObject(mSplitBounds, flags); parcel.writeInt(mType); + parcel.writeIntArray(mMinimizedTaskIds); } @Override diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/recents/GroupedRecentTaskInfoTest.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/recents/GroupedRecentTaskInfoTest.kt index bbd65be9abda..15b73c541ed8 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/recents/GroupedRecentTaskInfoTest.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/recents/GroupedRecentTaskInfoTest.kt @@ -17,6 +17,7 @@ package com.android.wm.shell.recents import android.app.ActivityManager +import android.app.ActivityManager.RecentTaskInfo import android.graphics.Rect import android.os.Parcel import android.testing.AndroidTestingRunner @@ -33,6 +34,7 @@ import com.android.wm.shell.util.GroupedRecentTaskInfo.TYPE_SPLIT import com.android.wm.shell.util.SplitBounds import com.google.common.truth.Correspondence import com.google.common.truth.Truth.assertThat +import org.junit.Assert.assertThrows import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito.mock @@ -86,12 +88,13 @@ class GroupedRecentTaskInfoTest : ShellTestCase() { @Test fun testFreeformTasks_hasCorrectType() { - assertThat(freeformTasksGroupInfo().type).isEqualTo(TYPE_FREEFORM) + assertThat(freeformTasksGroupInfo(freeformTaskIds = arrayOf(1)).type) + .isEqualTo(TYPE_FREEFORM) } @Test - fun testSplitTasks_taskInfoList_hasThreeTasks() { - val list = freeformTasksGroupInfo().taskInfoList + fun testCreateFreeformTasks_hasCorrectNumberOfTasks() { + val list = freeformTasksGroupInfo(freeformTaskIds = arrayOf(1, 2, 3)).taskInfoList assertThat(list).hasSize(3) assertThat(list[0].taskId).isEqualTo(1) assertThat(list[1].taskId).isEqualTo(2) @@ -99,6 +102,16 @@ class GroupedRecentTaskInfoTest : ShellTestCase() { } @Test + fun testCreateFreeformTasks_nonExistentMinimizedTaskId_throwsException() { + assertThrows(IllegalArgumentException::class.java) { + freeformTasksGroupInfo( + freeformTaskIds = arrayOf(1, 2, 3), + minimizedTaskIds = arrayOf(1, 4) + ) + } + } + + @Test fun testParcelling_singleTask() { val recentTaskInfo = singleTaskGroupInfo() val parcel = Parcel.obtain() @@ -129,7 +142,7 @@ class GroupedRecentTaskInfoTest : ShellTestCase() { @Test fun testParcelling_freeformTasks() { - val recentTaskInfo = freeformTasksGroupInfo() + val recentTaskInfo = freeformTasksGroupInfo(freeformTaskIds = arrayOf(1, 2, 3)) val parcel = Parcel.obtain() recentTaskInfo.writeToParcel(parcel, 0) parcel.setDataPosition(0) @@ -145,6 +158,21 @@ class GroupedRecentTaskInfoTest : ShellTestCase() { .containsExactly(1, 2, 3) } + @Test + fun testParcelling_freeformTasks_minimizedTasks() { + val recentTaskInfo = freeformTasksGroupInfo( + freeformTaskIds = arrayOf(1, 2, 3), minimizedTaskIds = arrayOf(2)) + + val parcel = Parcel.obtain() + recentTaskInfo.writeToParcel(parcel, 0) + parcel.setDataPosition(0) + + // Read the object back from the parcel + val recentTaskInfoParcel = CREATOR.createFromParcel(parcel) + assertThat(recentTaskInfoParcel.type).isEqualTo(TYPE_FREEFORM) + assertThat(recentTaskInfoParcel.minimizedTaskIds).isEqualTo(arrayOf(2).toIntArray()) + } + private fun createTaskInfo(id: Int) = ActivityManager.RecentTaskInfo().apply { taskId = id token = WindowContainerToken(mock(IWindowContainerToken::class.java)) @@ -162,10 +190,12 @@ class GroupedRecentTaskInfoTest : ShellTestCase() { return GroupedRecentTaskInfo.forSplitTasks(task1, task2, splitBounds) } - private fun freeformTasksGroupInfo(): GroupedRecentTaskInfo { - val task1 = createTaskInfo(id = 1) - val task2 = createTaskInfo(id = 2) - val task3 = createTaskInfo(id = 3) - return GroupedRecentTaskInfo.forFreeformTasks(task1, task2, task3) + private fun freeformTasksGroupInfo( + freeformTaskIds: Array<Int>, + minimizedTaskIds: Array<Int> = emptyArray() + ): GroupedRecentTaskInfo { + return GroupedRecentTaskInfo.forFreeformTasks( + freeformTaskIds.map { createTaskInfo(it) }.toTypedArray(), + minimizedTaskIds.toSet()) } } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.java b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.java index 78d4fc8d4c04..edf855fe5576 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.java +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/recents/model/Task.java @@ -249,6 +249,9 @@ public class Task { @ViewDebug.ExportedProperty(category="recents") public boolean isVisible; + @ViewDebug.ExportedProperty(category = "recents") + public boolean isMinimized; + public Task() { // Do nothing } @@ -283,6 +286,7 @@ public class Task { positionInParent = other.positionInParent; appBounds = other.appBounds; isVisible = other.isVisible; + isMinimized = other.isMinimized; } /** |