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

Commit 1bc44b45 authored by Nicolò Mazzucato's avatar Nicolò Mazzucato Committed by Android (Google) Code Review
Browse files

Merge changes Ie34a4ac6,I78323f20,If95ab474,I3927a1fd into main

* changes:
  Fix status bar icon size when shade goes around
  Fix statusbar visibility wrt shade expansion in multiple displays
  Propagate new shade displayId only after display change succeeded
  Make SysUiState for external display an override of the default one
parents 9ae2affb e5db5c65
Loading
Loading
Loading
Loading
+105 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.model

import android.view.Display
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.dump.dumpManager
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers
import org.mockito.Mockito.never
import org.mockito.kotlin.any
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.reset
import org.mockito.kotlin.verify

@SmallTest
@RunWith(AndroidJUnit4::class)
class SysUIStateOverrideTest : SysuiTestCase() {
    private val kosmos = testKosmos()

    private val defaultState = kosmos.sysUiState
    private val callbackOnOverride = mock<SysUiState.SysUiStateCallback>()
    private val dumpManager = kosmos.dumpManager

    private val underTest = kosmos.sysUiStateOverrideFactory.invoke(DISPLAY_1)

    @Before
    fun setup() {
        underTest.start()
        underTest.addCallback(callbackOnOverride)
        reset(callbackOnOverride)
    }

    @Test
    fun setFlag_setOnDefaultState_propagatedToOverride() {
        defaultState.setFlag(FLAG_1, true).commitUpdate()

        verify(callbackOnOverride).onSystemUiStateChanged(FLAG_1, Display.DEFAULT_DISPLAY)
        verify(callbackOnOverride).onSystemUiStateChanged(FLAG_1, DISPLAY_1)
    }

    @Test
    fun setFlag_onOverride_overridesDefaultOnes() {
        defaultState.setFlag(FLAG_1, false).setFlag(FLAG_2, true).commitUpdate()
        underTest.setFlag(FLAG_1, true).setFlag(FLAG_2, false).commitUpdate()

        assertThat(underTest.isFlagEnabled(FLAG_1)).isTrue()
        assertThat(underTest.isFlagEnabled(FLAG_2)).isFalse()

        assertThat(defaultState.isFlagEnabled(FLAG_1)).isFalse()
        assertThat(defaultState.isFlagEnabled(FLAG_2)).isTrue()
    }

    @Test
    fun destroy_callbacksForDefaultStateNotReceivedAnymore() {
        defaultState.setFlag(FLAG_1, true).commitUpdate()

        verify(callbackOnOverride).onSystemUiStateChanged(FLAG_1, Display.DEFAULT_DISPLAY)

        reset(callbackOnOverride)
        underTest.destroy()
        defaultState.setFlag(FLAG_1, false).commitUpdate()

        verify(callbackOnOverride, never()).onSystemUiStateChanged(FLAG_1, Display.DEFAULT_DISPLAY)
    }

    @Test
    fun init_registersWithDumpManager() {
        verify(dumpManager).registerNormalDumpable(any(), eq(underTest))
    }

    @Test
    fun destroy_unregistersWithDumpManager() {
        underTest.destroy()

        verify(dumpManager).unregisterDumpable(ArgumentMatchers.anyString())
    }

    private companion object {
        const val DISPLAY_1 = 1
        const val FLAG_1 = 1L
        const val FLAG_2 = 2L
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -140,6 +140,8 @@ public class SysUiStateTest extends SysuiTestCase {

    @Test
    public void init_registersWithDumpManager() {
        mFlagsContainer.start();

        verify(mDumpManager).registerNormalDumpable(any(), eq(mFlagsContainer));
    }

+16 −3
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ class ShadeDisplaysRepositoryTest : SysuiTestCase() {
    fun policy_changing_propagatedFromTheLatestPolicy() =
        testScope.runTest {
            val underTest = createUnderTest()
            val displayIds by collectValues(underTest.displayId)
            val displayIds by collectValues(underTest.pendingDisplayId)

            assertThat(displayIds).containsExactly(0)

@@ -98,7 +98,7 @@ class ShadeDisplaysRepositoryTest : SysuiTestCase() {
                DEVELOPMENT_SHADE_DISPLAY_AWARENESS,
                FakeShadeDisplayPolicy.name,
            )
            val displayId by collectLastValue(underTest.displayId)
            val displayId by collectLastValue(underTest.pendingDisplayId)

            displayRepository.addDisplay(displayId = 1)

@@ -161,7 +161,7 @@ class ShadeDisplaysRepositoryTest : SysuiTestCase() {
                FakeShadeDisplayPolicy.name,
            )

            val displayId by collectLastValue(underTest.displayId)
            val displayId by collectLastValue(underTest.pendingDisplayId)

            displayRepository.addDisplays(display(id = 2, type = TYPE_EXTERNAL))
            FakeShadeDisplayPolicy.setDisplayId(2)
@@ -176,4 +176,17 @@ class ShadeDisplaysRepositoryTest : SysuiTestCase() {

            assertThat(displayId).isEqualTo(2)
        }

    @Test
    fun onDisplayChangedSucceeded_displayIdChanges() =
        testScope.runTest {
            val underTest = createUnderTest()
            val displayId by collectLastValue(underTest.displayId)

            assertThat(displayId).isEqualTo(Display.DEFAULT_DISPLAY)

            underTest.onDisplayChangedSucceeded(1)

            assertThat(displayId).isEqualTo(1)
        }
}
+2 −2
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ class ShadePrimaryDisplayCommandTest : SysuiTestCase() {
    @Test
    fun commandShadeDisplayOverride_resetsDisplayId() =
        testScope.runTest {
            val displayId by collectLastValue(shadeDisplaysRepository.displayId)
            val displayId by collectLastValue(shadeDisplaysRepository.pendingDisplayId)
            assertThat(displayId).isEqualTo(Display.DEFAULT_DISPLAY)

            val newDisplayId = 2
@@ -87,7 +87,7 @@ class ShadePrimaryDisplayCommandTest : SysuiTestCase() {
    @Test
    fun commandShadeDisplayOverride_anyExternalDisplay_notOnDefaultAnymore() =
        testScope.runTest {
            val displayId by collectLastValue(shadeDisplaysRepository.displayId)
            val displayId by collectLastValue(shadeDisplaysRepository.pendingDisplayId)
            assertThat(displayId).isEqualTo(Display.DEFAULT_DISPLAY)
            val newDisplayId = 2
            displayRepository.addDisplay(displayId = newDisplayId)
+8 −8
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.view.Display
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.data.repository.configurationRepository
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
@@ -82,7 +81,7 @@ class ShadeDisplaysInteractorTest : SysuiTestCase() {
    fun start_shadeInCorrectPosition_notAddedOrRemoved() =
        testScope.runTest {
            whenever(display.displayId).thenReturn(0)
            positionRepository.setDisplayId(0)
            positionRepository.setPendingDisplayId(0)

            underTest.start()

@@ -93,18 +92,19 @@ class ShadeDisplaysInteractorTest : SysuiTestCase() {
    fun start_shadeInWrongPosition_changes() =
        testScope.runTest {
            whenever(display.displayId).thenReturn(0)
            positionRepository.setDisplayId(1)
            positionRepository.setPendingDisplayId(1)

            underTest.start()

            verify(shadeContext).reparentToDisplay(eq(1))
            assertThat(positionRepository.displayId.value).isEqualTo(1)
        }

    @Test
    fun start_shadeInWrongPosition_logsStartToLatencyTracker() =
        testScope.runTest {
            whenever(display.displayId).thenReturn(0)
            positionRepository.setDisplayId(1)
            positionRepository.setPendingDisplayId(1)

            underTest.start()

@@ -115,7 +115,7 @@ class ShadeDisplaysInteractorTest : SysuiTestCase() {
    fun start_shadeInWrongPosition_someNotificationsVisible_hiddenThenShown() =
        testScope.runTest {
            whenever(display.displayId).thenReturn(0)
            positionRepository.setDisplayId(1)
            positionRepository.setPendingDisplayId(1)
            activeNotificationRepository.setActiveNotifs(1)

            underTest.start()
@@ -129,7 +129,7 @@ class ShadeDisplaysInteractorTest : SysuiTestCase() {
    fun start_shadeInWrongPosition_someNotificationsVisible_waitsForInflationsBeforeShowingNssl() =
        testScope.runTest {
            whenever(display.displayId).thenReturn(0)
            positionRepository.setDisplayId(1)
            positionRepository.setPendingDisplayId(1)
            activeNotificationRepository.setActiveNotifs(1)

            val endRebinding = notificationRebindingTracker.trackRebinding("test")
@@ -155,7 +155,7 @@ class ShadeDisplaysInteractorTest : SysuiTestCase() {
    fun start_shadeInWrongPosition_noNotifications_nsslNotHidden() =
        testScope.runTest {
            whenever(display.displayId).thenReturn(0)
            positionRepository.setDisplayId(1)
            positionRepository.setPendingDisplayId(1)
            activeNotificationRepository.setActiveNotifs(0)

            underTest.start()
@@ -170,7 +170,7 @@ class ShadeDisplaysInteractorTest : SysuiTestCase() {
    fun start_shadeInWrongPosition_waitsUntilMovedToDisplayReceived() =
        testScope.runTest {
            whenever(display.displayId).thenReturn(0)
            positionRepository.setDisplayId(1)
            positionRepository.setPendingDisplayId(1)
            activeNotificationRepository.setActiveNotifs(1)

            underTest.start()
Loading