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

Commit eb553a4e authored by Daniel Akinola's avatar Daniel Akinola Committed by Android (Google) Code Review
Browse files

Merge "Fix sharing an app in PSS in foreground" into main

parents 38030949 e1c25e1c
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -53,8 +53,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.first().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
@@ -2,6 +2,7 @@ package com.android.systemui.mediaprojection.appselector.data

import android.app.ActivityManager.RecentTaskInfo
import android.content.pm.UserInfo
import android.graphics.Rect
import android.os.UserManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -14,8 +15,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.SNAP_TO_50_50
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
@@ -100,6 +103,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(
@@ -143,6 +157,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(
@@ -158,6 +187,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()
    }

    @Test
    fun loadRecentTasks_assignsCorrectUserType() {
        givenRecentTasks(
@@ -224,7 +268,7 @@ class ShellRecentTaskListProviderTest : SysuiTestCase() {
        GroupedRecentTaskInfo.forSplitTasks(
            createTaskInfo(taskId1, userId1, isVisible),
            createTaskInfo(taskId2, userId2, isVisible),
            null
            SplitBounds(Rect(), Rect(), taskId1, taskId2, SNAP_TO_50_50)
        )

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