Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8a0a814 authored by dakinola's avatar dakinola Committed by Daniel Akinola
Browse files

Fix sharing an app in PSS in foreground

Manual cherry-pick of ag/27693415 to 24D1-dev

Bug: 340137127
Flag: NONE
Test: manually checking a split screen pss session with Meet
Test: atest SystemUITest:ShellRecentTaskListProviderTest
Merged-In: I01b60a357f312d51807bc6469998880e017d9240
Change-Id: Iccad3ff1abf62e898a2193b768ac6fb00d19801f
parent 7608bcd7
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -50,8 +50,13 @@ constructor(
        withContext(coroutineDispatcher) {
            val groupedTasks: List<GroupedRecentTaskInfo> = recents?.getTasks() ?: emptyList()
            // Note: the returned task list is from the most-recent to least-recent order.
            // The last foreground task is at index 1, because at index 0 will be our app selector.
            val foregroundGroup = groupedTasks.elementAtOrNull(1)
            // When opening the app selector in full screen, index 0 will be just the app selector
            // activity and a null second task, so the foreground task will be index 1, but when
            // opening the app selector in split screen mode, the foreground task will be the second
            // task in index 0.
            val foregroundGroup =
                if (groupedTasks.elementAtOrNull(0)?.splitBounds != null) groupedTasks.first()
                else groupedTasks.elementAtOrNull(1)
            val foregroundTaskId1 = foregroundGroup?.taskInfo1?.taskId
            val foregroundTaskId2 = foregroundGroup?.taskInfo2?.taskId
            val foregroundTaskIds = listOfNotNull(foregroundTaskId1, foregroundTaskId2)
+45 −1
Original line number Diff line number Diff line
package com.android.systemui.mediaprojection.appselector.data

import android.app.ActivityManager.RecentTaskInfo
import android.graphics.Rect
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -8,8 +9,10 @@ import com.android.systemui.settings.UserTracker
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.android.wm.shell.common.split.SplitScreenConstants
import com.android.wm.shell.recents.RecentTasks
import com.android.wm.shell.util.GroupedRecentTaskInfo
import com.android.wm.shell.util.SplitBounds
import com.google.common.truth.Truth.assertThat
import java.util.Optional
import java.util.function.Consumer
@@ -89,6 +92,17 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
        assertThat(result[0].isForegroundTask).isFalse()
    }

    @Test
    fun loadRecentTasks_singleTaskPair_returnsTasksAsForeground() {
        givenRecentTasks(
            createTaskPair(taskId1 = 2, taskId2 = 3, isVisible = true),
        )

        val result = runBlocking { recentTaskListProvider.loadRecentTasks() }

        assertThat(result[0].isForegroundTask).isTrue()
    }

    @Test
    fun loadRecentTasks_multipleTasks_returnsSecondVisibleTaskAsForegroundTask() {
        givenRecentTasks(
@@ -132,6 +146,21 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
            .inOrder()
    }

    @Test
    fun loadRecentTasks_firstTaskIsGroupedAndVisible_marksBothGroupedTasksAsForeground() {
        givenRecentTasks(
            createTaskPair(taskId1 = 1, taskId2 = 2, isVisible = true),
            createSingleTask(taskId = 3),
            createSingleTask(taskId = 4),
        )

        val result = runBlocking { recentTaskListProvider.loadRecentTasks() }

        assertThat(result.map { it.isForegroundTask })
                .containsExactly(true, true, false, false)
                .inOrder()
    }

    @Test
    fun loadRecentTasks_secondTaskIsGroupedAndInvisible_marksBothGroupedTasksAsNotForeground() {
        givenRecentTasks(
@@ -147,6 +176,21 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
            .inOrder()
    }

    @Test
    fun loadRecentTasks_firstTaskIsGroupedAndInvisible_marksBothGroupedTasksAsNotForeground() {
        givenRecentTasks(
            createTaskPair(taskId1 = 1, taskId2 = 2, isVisible = false),
            createSingleTask(taskId = 3),
            createSingleTask(taskId = 4),
        )

        val result = runBlocking { recentTaskListProvider.loadRecentTasks() }

        assertThat(result.map { it.isForegroundTask })
                .containsExactly(false, false, false, false)
                .inOrder()
    }

    @Suppress("UNCHECKED_CAST")
    private fun givenRecentTasks(vararg tasks: GroupedRecentTaskInfo) {
        whenever(recentTasks.getRecentTasks(any(), any(), any(), any(), any())).thenAnswer {
@@ -177,7 +221,7 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
        GroupedRecentTaskInfo.forSplitTasks(
            createTaskInfo(taskId1, isVisible),
            createTaskInfo(taskId2, isVisible),
            null
            SplitBounds(Rect(), Rect(), taskId1, taskId2, SplitScreenConstants.SNAP_TO_50_50)
        )

    private fun createTaskInfo(taskId: Int, isVisible: Boolean = false) =