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

Commit 6771134b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Check if displays allow adding system decorations instead of just...

Merge "Check if displays allow adding system decorations instead of just relying on onDisplayAddSystemDecorations callbacks" into main
parents ff99923f bf90c54d
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -552,6 +552,44 @@ class DisplayRepositoryTest : SysuiTestCase() {
        testScope.runTest {
            setDisplays(0)
            whenever(windowManager.shouldShowSystemDecors(0)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(2)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(3)).thenReturn(true)
            val lastDisplayIdsWithSystemDecorations by latestDisplayIdsWithSystemDecorationsValue()

            sendOnDisplayAddSystemDecorations(2)
            sendOnDisplayAddSystemDecorations(3)

            assertThat(lastDisplayIdsWithSystemDecorations).containsExactly(0, 2, 3)
        }

    @Test
    @DisableFlags(
        Flags.FLAG_ENABLE_SYS_DECORS_CALLBACKS_VIA_WM,
        FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT,
    )
    fun displayIdsWithSystemDecorations_systemDecorationAdded_contentModeFlagOff_emitsOnlyDisplaysWithSystemDecorations() =
        testScope.runTest {
            setDisplays(0)
            whenever(windowManager.shouldShowSystemDecors(0)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(2)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(3)).thenReturn(false)
            val lastDisplayIdsWithSystemDecorations by latestDisplayIdsWithSystemDecorationsValue()

            sendOnDisplayAddSystemDecorations(2)
            sendOnDisplayAddSystemDecorations(3)

            assertThat(lastDisplayIdsWithSystemDecorations).containsExactly(0, 2)
        }

    @Test
    @DisableFlags(Flags.FLAG_ENABLE_SYS_DECORS_CALLBACKS_VIA_WM)
    @EnableFlags(FLAG_ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT)
    fun displayIdsWithSystemDecorations_systemDecorationAdded_contentModeFlagOn_emitsAllDisplays() =
        testScope.runTest {
            setDisplays(0)
            whenever(windowManager.shouldShowSystemDecors(0)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(2)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(3)).thenReturn(false)
            val lastDisplayIdsWithSystemDecorations by latestDisplayIdsWithSystemDecorationsValue()

            sendOnDisplayAddSystemDecorations(2)
@@ -566,6 +604,7 @@ class DisplayRepositoryTest : SysuiTestCase() {
        testScope.runTest {
            setDisplays(0)
            whenever(windowManager.shouldShowSystemDecors(0)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(1)).thenReturn(true)

            val priorDisplayIdsWithSystemDecorations by latestDisplayIdsWithSystemDecorationsValue()
            sendOnDisplayAddSystemDecorations(1)
@@ -580,6 +619,8 @@ class DisplayRepositoryTest : SysuiTestCase() {
    @DisableFlags(Flags.FLAG_ENABLE_SYS_DECORS_CALLBACKS_VIA_WM)
    fun displayIdsWithSystemDecorations_systemDecorationRemoved_doesNotEmitRemovedDisplayId() =
        testScope.runTest {
            whenever(windowManager.shouldShowSystemDecors(1)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(2)).thenReturn(true)
            val lastDisplayIdsWithSystemDecorations by latestDisplayIdsWithSystemDecorationsValue()

            sendOnDisplayAddSystemDecorations(1)
@@ -593,6 +634,8 @@ class DisplayRepositoryTest : SysuiTestCase() {
    @DisableFlags(Flags.FLAG_ENABLE_SYS_DECORS_CALLBACKS_VIA_WM)
    fun displayIdsWithSystemDecorations_systemDecorationsRemoved_nonExistentDisplay_noEffect() =
        testScope.runTest {
            whenever(windowManager.shouldShowSystemDecors(1)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(2)).thenReturn(true)
            val lastDisplayIdsWithSystemDecorations by latestDisplayIdsWithSystemDecorationsValue()

            sendOnDisplayAddSystemDecorations(1)
@@ -605,6 +648,8 @@ class DisplayRepositoryTest : SysuiTestCase() {
    @DisableFlags(Flags.FLAG_ENABLE_SYS_DECORS_CALLBACKS_VIA_WM)
    fun displayIdsWithSystemDecorations_displayRemoved_doesNotEmitRemovedDisplayId() =
        testScope.runTest {
            whenever(windowManager.shouldShowSystemDecors(1)).thenReturn(true)
            whenever(windowManager.shouldShowSystemDecors(2)).thenReturn(true)
            val lastDisplayIdsWithSystemDecorations by latestDisplayIdsWithSystemDecorationsValue()

            sendOnDisplayAddSystemDecorations(1)
@@ -618,6 +663,7 @@ class DisplayRepositoryTest : SysuiTestCase() {
    @DisableFlags(Flags.FLAG_ENABLE_SYS_DECORS_CALLBACKS_VIA_WM)
    fun displayIdsWithSystemDecorations_displayRemoved_nonExistentDisplay_noEffect() =
        testScope.runTest {
            whenever(windowManager.shouldShowSystemDecors(1)).thenReturn(true)
            val lastDisplayIdsWithSystemDecorations by latestDisplayIdsWithSystemDecorationsValue()

            sendOnDisplayAddSystemDecorations(1)
+8 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.display.data.repository

import android.view.IWindowManager
import android.window.DesktopExperienceFlags.ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT
import com.android.app.displaylib.DisplaysWithDecorationsRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
@@ -48,7 +49,13 @@ constructor(
        val callback =
            object : CommandQueue.Callbacks {
                override fun onDisplayAddSystemDecorations(displayId: Int) {
                    if (ENABLE_DISPLAY_CONTENT_MODE_MANAGEMENT.isTrue()) {
                        trySend(Event.Add(displayId))
                    } else {
                        if (windowManager.shouldShowSystemDecors(displayId)) {
                            trySend(Event.Add(displayId))
                        }
                    }
                }

                override fun onDisplayRemoveSystemDecorations(displayId: Int) {