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

Commit dbd3e6f8 authored by Maryam Dehaini's avatar Maryam Dehaini Committed by Android (Google) Code Review
Browse files

Merge "Filter out null bitmaps when showing "Manage Windows" menu" into main

parents 948b3b23 4f7b5bfb
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -48,11 +48,13 @@ abstract class ManageWindowsViewContainer(
    lateinit var menuView: ManageWindowsView

    /** Creates the base menu view and fills it with icon views. */
    fun createMenu(snapshotList: List<Pair<Int, TaskSnapshot>>,
    fun createMenu(snapshotList: List<Pair<Int, TaskSnapshot?>>,
             onIconClickListener: ((Int) -> Unit),
             onOutsideClickListener: (() -> Unit)): ManageWindowsView {
        val bitmapList = snapshotList.map { (index, snapshot) ->
            index to Bitmap.wrapHardwareBuffer(snapshot.hardwareBuffer, snapshot.colorSpace)
        val bitmapList = snapshotList
            .filter { it.second != null }
            .map { (index, snapshot) ->
                index to Bitmap.wrapHardwareBuffer(snapshot!!.hardwareBuffer, snapshot.colorSpace)
            }
        return createAndShowMenuView(
            bitmapList,
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ class DesktopHandleManageWindowsMenu(
    private val captionWidth: Int,
    private val windowManagerWrapper: WindowManagerWrapper,
    context: Context,
    snapshotList: List<Pair<Int, TaskSnapshot>>,
    snapshotList: List<Pair<Int, TaskSnapshot?>>,
    onIconClickListener: ((Int) -> Unit),
    onOutsideClickListener: (() -> Unit)
) : ManageWindowsViewContainer(
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ class DesktopHeaderManageWindowsMenu(
    private val desktopUserRepositories: DesktopUserRepositories,
    private val surfaceControlBuilderSupplier: Supplier<SurfaceControl.Builder>,
    private val surfaceControlTransactionSupplier: Supplier<SurfaceControl.Transaction>,
    snapshotList: List<Pair<Int, TaskSnapshot>>,
    snapshotList: List<Pair<Int, TaskSnapshot?>>,
    onIconClickListener: ((Int) -> Unit),
    onOutsideClickListener: (() -> Unit)
) : ManageWindowsViewContainer(
+26 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.platform.test.annotations.EnableFlags
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.view.SurfaceControl
import android.window.TaskSnapshot
import androidx.test.filters.SmallTest
import com.android.window.flags.Flags
import com.android.wm.shell.MockToken
@@ -33,6 +34,7 @@ import com.android.wm.shell.sysui.ShellInit
import com.android.wm.shell.windowdecor.additionalviewcontainer.AdditionalSystemViewContainer
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -84,7 +86,29 @@ class DesktopHeaderManageWindowsMenuTest : ShellTestCase() {
        assertThat(menu.menuViewContainer).isInstanceOf(AdditionalSystemViewContainer::class.java)
    }

    private fun createMenu(task: RunningTaskInfo) = DesktopHeaderManageWindowsMenu(
    @Test
    @EnableFlags(Flags.FLAG_ENABLE_FULLY_IMMERSIVE_IN_DESKTOP)
    fun testShow_nullSnapshotDoesNotCauseNPE() {
        val task = createFreeformTask()
        val snapshotList = listOf(Pair(/* index = */ 1, /* snapshot = */ null))
        // Set as immersive so that menu is created as system view container (simpler of the
        // options)
        userRepositories.getProfile(DEFAULT_USER_ID).setTaskInFullImmersiveState(
            displayId = task.displayId,
            taskId = task.taskId,
            immersive = true
        )
        try {
            menu = createMenu(task, snapshotList)
        } catch (e: NullPointerException) {
            fail("Null snapshot should not have thrown null pointer exception")
        }
    }

    private fun createMenu(
        task: RunningTaskInfo,
        snapshotList: List<Pair<Int, TaskSnapshot?>> = emptyList()
    ) = DesktopHeaderManageWindowsMenu(
        callerTaskInfo = task,
        x = 0,
        y = 0,
@@ -94,7 +118,7 @@ class DesktopHeaderManageWindowsMenuTest : ShellTestCase() {
        desktopUserRepositories = userRepositories,
        surfaceControlBuilderSupplier = { SurfaceControl.Builder() },
        surfaceControlTransactionSupplier = { SurfaceControl.Transaction() },
        snapshotList = emptyList(),
        snapshotList = snapshotList,
        onIconClickListener = {},
        onOutsideClickListener = {},
    )