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

Commit d091d07e authored by Kenneth Ford's avatar Kenneth Ford
Browse files

Update SysUI usages of device state overlay config values

Updates the usages of the device state overlay configuration
values which can now be updated with the
DeviceState#hasProperty API's that were introduced in 24Q3.

Bug: 336640888
Test: RotationLockTileMapperTest
Test: KeyguardUnlockAnimationControllerTest
Test: RearDisplayDialogControllerTest
Test: CentralSurfacesImplTest
Test: FoldStateListenerTest
Test: DisplaySwitchLatencyTrackerTest
Test: DeviceStateRepositoryTest
Flag: android.hardware.devicestate.feature.flags.device_state_property_migration
Change-Id: I4f32d611a2f89bbcc0cf9187fa2daf09bb337252
parent d5e5c502
Loading
Loading
Loading
Loading
+104 −28
Original line number Diff line number Diff line
@@ -16,6 +16,14 @@

package com.android.systemui.display.data.repository

import android.hardware.devicestate.DeviceState.PROPERTY_EMULATED_ONLY
import android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_DUAL_DISPLAY_INTERNAL_DEFAULT
import android.hardware.devicestate.DeviceState.PROPERTY_FEATURE_REAR_DISPLAY
import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY
import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY
import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED
import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN
import android.hardware.devicestate.DeviceState.PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN
import android.hardware.devicestate.DeviceStateManager
import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -40,6 +48,8 @@ import org.junit.Before
import org.junit.runner.RunWith
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import android.hardware.devicestate.DeviceState as PlatformDeviceState
import org.mockito.kotlin.whenever

@RunWith(AndroidJUnit4::class)
@TestableLooper.RunWithLooper
@@ -59,15 +69,33 @@ class DeviceStateRepositoryTest : SysuiTestCase() {
    @Before
    fun setup() {
        mContext.orCreateTestableResources.apply {
            addOverride(R.array.config_foldedDeviceStates, listOf(TEST_FOLDED).toIntArray())
            addOverride(R.array.config_halfFoldedDeviceStates, TEST_HALF_FOLDED.toIntArray())
            addOverride(R.array.config_openDeviceStates, TEST_UNFOLDED.toIntArray())
            addOverride(R.array.config_rearDisplayDeviceStates, TEST_REAR_DISPLAY.toIntArray())
            addOverride(
                R.array.config_foldedDeviceStates,
                listOf(TEST_FOLDED.identifier).toIntArray()
            )
            addOverride(
                R.array.config_halfFoldedDeviceStates,
                TEST_HALF_FOLDED.identifier.toIntArray()
            )
            addOverride(R.array.config_openDeviceStates, TEST_UNFOLDED.identifier.toIntArray())
            addOverride(
                R.array.config_rearDisplayDeviceStates,
                TEST_REAR_DISPLAY.identifier.toIntArray()
            )
            addOverride(
                R.array.config_concurrentDisplayDeviceStates,
                TEST_CONCURRENT_DISPLAY.toIntArray()
                TEST_CONCURRENT_DISPLAY.identifier.toIntArray()
            )
        }
        whenever(deviceStateManager.supportedDeviceStates).thenReturn(
            listOf(
                TEST_FOLDED,
                TEST_HALF_FOLDED,
                TEST_UNFOLDED,
                TEST_REAR_DISPLAY,
                TEST_CONCURRENT_DISPLAY
            )
        )
        deviceStateRepository =
            DeviceStateRepositoryImpl(
                mContext,
@@ -85,9 +113,7 @@ class DeviceStateRepositoryTest : SysuiTestCase() {
        testScope.runTest {
            val state = displayState()

            deviceStateManagerListener.value.onDeviceStateChanged(
                getDeviceStateForIdentifier(TEST_FOLDED)
            )
            deviceStateManagerListener.value.onDeviceStateChanged(TEST_FOLDED)

            assertThat(state()).isEqualTo(DeviceState.FOLDED)
        }
@@ -97,9 +123,7 @@ class DeviceStateRepositoryTest : SysuiTestCase() {
        testScope.runTest {
            val state = displayState()

            deviceStateManagerListener.value.onDeviceStateChanged(
                getDeviceStateForIdentifier(TEST_HALF_FOLDED)
            )
            deviceStateManagerListener.value.onDeviceStateChanged(TEST_HALF_FOLDED)

            assertThat(state()).isEqualTo(DeviceState.HALF_FOLDED)
        }
@@ -109,9 +133,7 @@ class DeviceStateRepositoryTest : SysuiTestCase() {
        testScope.runTest {
            val state = displayState()

            deviceStateManagerListener.value.onDeviceStateChanged(
                getDeviceStateForIdentifier(TEST_UNFOLDED)
            )
            deviceStateManagerListener.value.onDeviceStateChanged(TEST_UNFOLDED)

            assertThat(state()).isEqualTo(DeviceState.UNFOLDED)
        }
@@ -121,9 +143,7 @@ class DeviceStateRepositoryTest : SysuiTestCase() {
        testScope.runTest {
            val state = displayState()

            deviceStateManagerListener.value.onDeviceStateChanged(
                getDeviceStateForIdentifier(TEST_REAR_DISPLAY)
            )
            deviceStateManagerListener.value.onDeviceStateChanged(TEST_REAR_DISPLAY)

            assertThat(state()).isEqualTo(DeviceState.REAR_DISPLAY)
        }
@@ -133,9 +153,7 @@ class DeviceStateRepositoryTest : SysuiTestCase() {
        testScope.runTest {
            val state = displayState()

            deviceStateManagerListener.value.onDeviceStateChanged(
                getDeviceStateForIdentifier(TEST_CONCURRENT_DISPLAY)
            )
            deviceStateManagerListener.value.onDeviceStateChanged(TEST_CONCURRENT_DISPLAY)

            assertThat(state()).isEqualTo(DeviceState.CONCURRENT_DISPLAY)
        }
@@ -164,9 +182,9 @@ class DeviceStateRepositoryTest : SysuiTestCase() {

    private fun Int.toIntArray() = listOf(this).toIntArray()

    private fun getDeviceStateForIdentifier(id: Int): android.hardware.devicestate.DeviceState {
        return android.hardware.devicestate.DeviceState(
            android.hardware.devicestate.DeviceState.Configuration.Builder(id, /* name= */ "")
    private fun getDeviceStateForIdentifier(id: Int): PlatformDeviceState {
        return PlatformDeviceState(
            PlatformDeviceState.Configuration.Builder(id, /* name= */ "")
                .build()
        )
    }
@@ -174,10 +192,68 @@ class DeviceStateRepositoryTest : SysuiTestCase() {
    private companion object {
        // Used to fake the ids in the test. Note that there is no guarantees different devices will
        // have the same ids (that's why the ones in this test start from 41)
        const val TEST_FOLDED = 41
        const val TEST_HALF_FOLDED = 42
        const val TEST_UNFOLDED = 43
        const val TEST_REAR_DISPLAY = 44
        const val TEST_CONCURRENT_DISPLAY = 45
        val TEST_FOLDED =
            PlatformDeviceState(
                PlatformDeviceState.Configuration.Builder(41, "FOLDED")
                    .setSystemProperties(
                        setOf(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY)
                    )
                    .setPhysicalProperties(
                        setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_CLOSED)
                    )
                    .build()
            )
        val TEST_HALF_FOLDED =
            PlatformDeviceState(
                PlatformDeviceState.Configuration.Builder(42, "HALF_FOLDED")
                    .setSystemProperties(
                        setOf(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)
                    )
                    .setPhysicalProperties(
                        setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_HALF_OPEN)
                    )
                    .build()
            )
        val TEST_UNFOLDED =
            PlatformDeviceState(
                PlatformDeviceState.Configuration.Builder(43, "UNFOLDED")
                    .setSystemProperties(
                        setOf(PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY)
                    )
                    .setPhysicalProperties(
                        setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN)
                    )
                    .build()
            )
        val TEST_REAR_DISPLAY =
            PlatformDeviceState(
                PlatformDeviceState.Configuration.Builder(44, "REAR_DISPLAY")
                    .setSystemProperties(
                        setOf(
                            PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_OUTER_PRIMARY,
                            PROPERTY_FEATURE_REAR_DISPLAY,
                            PROPERTY_EMULATED_ONLY
                        )
                    )
                    .setPhysicalProperties(
                        setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN)
                    )
                    .build()
            )
        val TEST_CONCURRENT_DISPLAY =
            PlatformDeviceState(
                PlatformDeviceState.Configuration.Builder(45, "CONCURRENT_DISPLAY")
                    .setSystemProperties(
                        setOf(
                            PROPERTY_FOLDABLE_DISPLAY_CONFIGURATION_INNER_PRIMARY,
                            PROPERTY_FEATURE_DUAL_DISPLAY_INTERNAL_DEFAULT,
                            PROPERTY_EMULATED_ONLY
                        )
                    )
                    .setPhysicalProperties(
                        setOf(PROPERTY_FOLDABLE_HARDWARE_CONFIGURATION_FOLD_IN_OPEN)
                    )
                    .build()
            )
    }
}
+10 −2
Original line number Diff line number Diff line
@@ -21,14 +21,16 @@ import com.android.keyguard.KeyguardViewController
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.shared.system.smartspace.ILauncherUnlockAnimationController
import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.phone.BiometricUnlockController
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.defaultDeviceState
import com.android.systemui.deviceStateManager
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.argThat
import com.android.systemui.util.mockito.whenever
import java.util.function.Predicate
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertFalse
@@ -47,6 +49,7 @@ import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoMoreInteractions
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.clearInvocations
import org.mockito.kotlin.whenever

@RunWith(AndroidJUnit4::class)
@RunWithLooper
@@ -65,6 +68,8 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
    @Mock private lateinit var notificationShadeWindowController: NotificationShadeWindowController
    @Mock private lateinit var powerManager: PowerManager
    @Mock private lateinit var wallpaperManager: WallpaperManager
    private val kosmos = Kosmos()
    private val deviceStateManager = kosmos.deviceStateManager

    @Mock
    private lateinit var launcherUnlockAnimationController: ILauncherUnlockAnimationController.Stub
@@ -173,7 +178,8 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
                    statusBarStateController,
                    notificationShadeWindowController,
                    powerManager,
                    wallpaperManager
                    wallpaperManager,
                    deviceStateManager
                ) {
                override fun shouldPerformSmartspaceTransition(): Boolean =
                    shouldPerformSmartspaceTransition
@@ -185,6 +191,8 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {

        whenever(keyguardViewController.viewRootImpl).thenReturn(mock(ViewRootImpl::class.java))
        whenever(powerManager.isInteractive).thenReturn(true)
        whenever(deviceStateManager.supportedDeviceStates)
            .thenReturn(listOf(kosmos.defaultDeviceState))

        // All of these fields are final, so we can't mock them, but are needed so that the surface
        // appear amount setter doesn't short circuit.
+11 −2
Original line number Diff line number Diff line
@@ -29,12 +29,15 @@ import com.android.systemui.qs.tiles.impl.rotation.qsRotationLockTileConfig
import com.android.systemui.qs.tiles.viewmodel.QSTileState
import com.android.systemui.res.R
import com.android.systemui.statusbar.policy.DevicePostureController
import com.android.systemui.defaultDeviceState
import com.android.systemui.statusbar.policy.devicePostureController
import com.android.systemui.util.mockito.whenever
import com.android.systemui.deviceStateManager
import com.android.systemui.foldedDeviceStateList
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.whenever

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -42,13 +45,17 @@ class RotationLockTileMapperTest : SysuiTestCase() {
    private val kosmos = Kosmos()
    private val rotationLockTileConfig = kosmos.qsRotationLockTileConfig
    private val devicePostureController = kosmos.devicePostureController
    private val deviceStateManager = kosmos.deviceStateManager

    private lateinit var mapper: RotationLockTileMapper

    @Before
    fun setup() {
        deviceStateManager
        whenever(devicePostureController.devicePosture)
            .thenReturn(DevicePostureController.DEVICE_POSTURE_CLOSED)
        whenever(deviceStateManager.supportedDeviceStates)
            .thenReturn(listOf(kosmos.defaultDeviceState))

        mapper =
            RotationLockTileMapper(
@@ -64,7 +71,8 @@ class RotationLockTileMapperTest : SysuiTestCase() {
                    }
                    .resources,
                context.theme,
                devicePostureController
                devicePostureController,
                deviceStateManager
            )
    }

@@ -162,6 +170,7 @@ class RotationLockTileMapperTest : SysuiTestCase() {
                intArrayOf(1, 2, 3)
            )
        }
        whenever(deviceStateManager.supportedDeviceStates).thenReturn(kosmos.foldedDeviceStateList)
    }

    private fun createRotationLockTileState(
+25 −5
Original line number Diff line number Diff line
@@ -18,15 +18,20 @@ package com.android.systemui.unfold

import android.content.Context
import android.content.res.Resources
import android.hardware.devicestate.DeviceStateManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.R
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.data.repository.ConfigurationRepositoryImpl
import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
import com.android.systemui.defaultDeviceState
import com.android.systemui.deviceStateManager
import com.android.systemui.display.data.repository.DeviceStateRepository
import com.android.systemui.display.data.repository.DeviceStateRepository.DeviceState
import com.android.systemui.foldedDeviceStateList
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.shared.model.ScreenPowerState
import com.android.systemui.power.shared.model.WakeSleepReason
@@ -39,10 +44,10 @@ import com.android.systemui.unfold.DisplaySwitchLatencyTracker.Companion.FOLDABL
import com.android.systemui.unfold.DisplaySwitchLatencyTracker.DisplaySwitchLatencyEvent
import com.android.systemui.unfold.data.repository.UnfoldTransitionRepositoryImpl
import com.android.systemui.unfold.domain.interactor.UnfoldTransitionInteractor
import com.android.systemui.unfoldedDeviceState
import com.android.systemui.util.animation.data.repository.AnimationStatusRepository
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.capture
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.time.FakeSystemClock
import com.google.common.truth.Truth.assertThat
import java.util.Optional
@@ -61,8 +66,9 @@ import org.mockito.ArgumentCaptor
import org.mockito.Captor
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.mock
import org.mockito.Mockito.`when` as whenever

@OptIn(ExperimentalCoroutinesApi::class)
@RunWith(AndroidJUnit4::class)
@@ -78,8 +84,14 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    private val animationStatusRepository = mock<AnimationStatusRepository>()
    private val keyguardInteractor = mock<KeyguardInteractor>()
    private val displaySwitchLatencyLogger = mock<DisplaySwitchLatencyLogger>()
    private val kosmos = Kosmos()
    private val deviceStateManager = kosmos.deviceStateManager
    private val closedDeviceState = kosmos.foldedDeviceStateList.first()
    private val openDeviceState = kosmos.unfoldedDeviceState
    private val defaultDeviceState = kosmos.defaultDeviceState
    private val nonEmptyClosedDeviceStatesArray: IntArray =
        IntArray(2) { closedDeviceState.identifier }

    private val nonEmptyClosedDeviceStatesArray: IntArray = IntArray(2) { 0 }
    private val testDispatcher: TestDispatcher = StandardTestDispatcher()
    private val testScope: TestScope = TestScope(testDispatcher)
    private val isAsleep = MutableStateFlow(false)
@@ -108,6 +120,10 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
    fun setup() {
        MockitoAnnotations.initMocks(this)
        whenever(mockContext.resources).thenReturn(resources)
        whenever(mockContext.getSystemService(DeviceStateManager::class.java))
            .thenReturn(deviceStateManager)
        whenever(deviceStateManager.supportedDeviceStates)
            .thenReturn(listOf(closedDeviceState, openDeviceState))
        whenever(resources.getIntArray(R.array.config_foldedDeviceStates))
            .thenReturn(nonEmptyClosedDeviceStatesArray)
        whenever(foldStateRepository.state).thenReturn(deviceState)
@@ -128,7 +144,8 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
                testDispatcher.asExecutor(),
                testScope.backgroundScope,
                displaySwitchLatencyLogger,
                systemClock
                systemClock,
                deviceStateManager
            )
    }

@@ -182,7 +199,8 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
                    testDispatcher.asExecutor(),
                    testScope.backgroundScope,
                    displaySwitchLatencyLogger,
                    systemClock
                    systemClock,
                    deviceStateManager
                )
            areAnimationEnabled.emit(true)

@@ -321,6 +339,8 @@ class DisplaySwitchLatencyTrackerTest : SysuiTestCase() {
            deviceState.emit(DeviceState.UNFOLDED)
            whenever(resources.getIntArray(R.array.config_foldedDeviceStates))
                .thenReturn(IntArray(0))
            whenever(deviceStateManager.supportedDeviceStates)
                .thenReturn(listOf(defaultDeviceState))

            displaySwitchLatencyTracker.start()
            deviceState.emit(DeviceState.HALF_FOLDED)
+13 −0
Original line number Diff line number Diff line
@@ -23,9 +23,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.util.LatencyTracker
import com.android.systemui.SysuiTestCase
import com.android.systemui.foldedDeviceStateList
import com.android.systemui.halfFoldedDeviceState
import com.android.systemui.keyguard.ScreenLifecycle
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.unfold.util.FoldableDeviceStates
import com.android.systemui.unfold.util.FoldableTestUtils
import com.android.systemui.unfoldedDeviceState
import com.android.systemui.util.mockito.any
import java.util.Optional
import org.junit.Before
@@ -38,6 +42,7 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoMoreInteractions
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.whenever

@RunWith(AndroidJUnit4::class)
@SmallTest
@@ -62,6 +67,13 @@ class UnfoldLatencyTrackerTest : SysuiTestCase() {
    @Before
    fun setUp() {
        MockitoAnnotations.initMocks(this)
        whenever(deviceStateManager.supportedDeviceStates).thenReturn(
            listOf(
                Kosmos().foldedDeviceStateList[0],
                Kosmos().unfoldedDeviceState
            )
        )

        unfoldLatencyTracker =
            UnfoldLatencyTracker(
                    latencyTracker,
@@ -73,6 +85,7 @@ class UnfoldLatencyTrackerTest : SysuiTestCase() {
                    screenLifecycle
                )
                .apply { init() }

        deviceStates = FoldableTestUtils.findDeviceStates(context)

        verify(deviceStateManager).registerCallback(any(), foldStateListenerCaptor.capture())
Loading