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

Commit bf90c54d authored by alinazaidi's avatar alinazaidi
Browse files

Check if displays allow adding system decorations instead of just relying on...

Check if displays allow adding system decorations instead of just relying on onDisplayAddSystemDecorations callbacks

Before the CD project, aka when content mode flag is OFF, onDisplayAddSystemDecorations() is always sent to status bar upon a new display is created.

Test: atest com.android.systemui.display.data.repository.DisplayRepositoryTest
Bug: 424787145
Flag: com.android.systemui.shared.status_bar_connected_displays
Change-Id: I8078fab2a92cf62e436cdb98b547dd7db0483091
parent e0c0a7f5
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) {