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

Commit 89da0783 authored by Andreas Miko's avatar Andreas Miko Committed by Android (Google) Code Review
Browse files

Merge changes I8cbb7ee7,Iea75430f,Idf988662 into main

* changes:
  Refactor KeyguardState.isBouncerState()
  Remove isFinishedInStateWhereValue() and verify deviceIsAsleepInState()
  Transform isFinishedInState()
parents f58de2f9 f42fd869
Loading
Loading
Loading
Loading
+59 −39
Original line number Diff line number Diff line
@@ -69,6 +69,11 @@ import com.android.systemui.media.controls.ui.controller.MediaHierarchyManager
import com.android.systemui.media.controls.ui.view.MediaHost
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.data.repository.Idle
import com.android.systemui.scene.data.repository.Transition
import com.android.systemui.scene.data.repository.setTransition
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.settings.fakeUserTracker
import com.android.systemui.shade.ShadeTestUtil
import com.android.systemui.shade.domain.interactor.shadeInteractor
@@ -492,13 +497,16 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                flowOf(ObservableTransitionState.Idle(CommunalScenes.Communal))
            )
            // Transitioned to Glanceable hub.
            keyguardTransitionRepository.sendTransitionSteps(
            kosmos.setTransition(
                sceneTransition = Idle(Scenes.Communal),
                stateTransition =
                    TransitionStep(
                        from = KeyguardState.LOCKSCREEN,
                        to = KeyguardState.GLANCEABLE_HUB,
                testScope = testScope,
                    )
            )
            // Shade not expanded.
            shadeTestUtil.setLockscreenShadeExpansion(0f)
            if (!SceneContainerFlag.isEnabled) shadeTestUtil.setLockscreenShadeExpansion(0f)

            assertThat(isFocusable).isEqualTo(true)
        }
@@ -541,10 +549,13 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            keyguardRepository.setKeyguardOccluded(true)

            // And on hub
            keyguardTransitionRepository.sendTransitionSteps(
            kosmos.setTransition(
                sceneTransition = Idle(Scenes.Communal),
                stateTransition =
                    TransitionStep(
                        from = KeyguardState.DREAMING,
                        to = KeyguardState.GLANCEABLE_HUB,
                testScope = testScope,
                    )
            )

            // Then flow is not frozen
@@ -558,10 +569,13 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            assertThat(isCommunalContentFlowFrozen).isEqualTo(true)

            // 3. When transitioned to OCCLUDED and activity shows
            keyguardTransitionRepository.sendTransitionSteps(
            kosmos.setTransition(
                sceneTransition = Idle(Scenes.Lockscreen),
                stateTransition =
                    TransitionStep(
                        from = KeyguardState.GLANCEABLE_HUB,
                        to = KeyguardState.OCCLUDED,
                testScope = testScope,
                    )
            )

            // Then flow is not frozen
@@ -579,10 +593,13 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            keyguardRepository.setKeyguardOccluded(false)

            // And transitioned to hub
            keyguardTransitionRepository.sendTransitionSteps(
            kosmos.setTransition(
                sceneTransition = Idle(Scenes.Communal),
                stateTransition =
                    TransitionStep(
                        from = KeyguardState.LOCKSCREEN,
                        to = KeyguardState.GLANCEABLE_HUB,
                testScope = testScope,
                    )
            )

            // Then flow is not frozen
@@ -593,31 +610,31 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            runCurrent()

            // And transitioning to occluded
            keyguardTransitionRepository.sendTransitionStep(
            kosmos.setTransition(
                sceneTransition = Transition(from = Scenes.Communal, to = Scenes.Lockscreen),
                stateTransition =
                    TransitionStep(
                        from = KeyguardState.GLANCEABLE_HUB,
                        to = KeyguardState.OCCLUDED,
                        transitionState = TransitionState.STARTED,
                        value = 0f,
                    )
            )

            keyguardTransitionRepository.sendTransitionStep(
                from = KeyguardState.GLANCEABLE_HUB,
                to = KeyguardState.OCCLUDED,
                transitionState = TransitionState.RUNNING,
                value = 0.5f,
            )

            // Then flow is frozen
            assertThat(isCommunalContentFlowFrozen).isEqualTo(true)

            // 3. When transition is finished
            keyguardTransitionRepository.sendTransitionStep(
            kosmos.setTransition(
                sceneTransition = Idle(Scenes.Lockscreen),
                stateTransition =
                    TransitionStep(
                        from = KeyguardState.GLANCEABLE_HUB,
                        to = KeyguardState.OCCLUDED,
                        transitionState = TransitionState.FINISHED,
                        value = 1f,
                    )
            )

            // Then flow is not frozen
            assertThat(isCommunalContentFlowFrozen).isEqualTo(false)
@@ -639,10 +656,13 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            keyguardRepository.setKeyguardOccluded(true)

            // And transitioned to hub
            keyguardTransitionRepository.sendTransitionSteps(
            kosmos.setTransition(
                sceneTransition = Idle(Scenes.Communal),
                stateTransition =
                    TransitionStep(
                        from = KeyguardState.DREAMING,
                        to = KeyguardState.GLANCEABLE_HUB,
                testScope = testScope,
                    )
            )

            // Widgets available
+2 −0
Original line number Diff line number Diff line
@@ -149,6 +149,8 @@ public class DreamOverlayContainerViewControllerTest extends SysuiTestCase {
        when(mDreamOverlayContainerView.getRootSurfaceControl())
                .thenReturn(mAttachedSurfaceControl);
        when(mKeyguardTransitionInteractor.isFinishedInStateWhere(any())).thenReturn(emptyFlow());
        when(mKeyguardTransitionInteractor.isFinishedIn(any(), any())).thenReturn(emptyFlow());
        when(mKeyguardTransitionInteractor.isFinishedIn(any())).thenReturn(emptyFlow());
        when(mShadeInteractor.isAnyExpanded()).thenReturn(MutableStateFlow(false));
        when(mCommunalInteractor.isCommunalShowing()).thenReturn(MutableStateFlow(false));

+85 −1
Original line number Diff line number Diff line
@@ -1097,9 +1097,10 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer
    fun isFinishedInState() =
        testScope.runTest {
            val results by collectValues(underTest.isFinishedInState(GONE))
            val results by collectValues(underTest.isFinishedIn(Scenes.Gone, GONE))

            sendSteps(
                TransitionStep(AOD, DOZING, 0f, STARTED),
@@ -1193,6 +1194,89 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
                )
        }

    @Test
    @EnableSceneContainer
    fun isFinishedIn() =
        testScope.runTest {
            val results by collectValues(underTest.isFinishedIn(Scenes.Gone, GONE))

            sendSteps(
                TransitionStep(AOD, DOZING, 0f, STARTED),
                TransitionStep(AOD, DOZING, 0.5f, RUNNING),
                TransitionStep(AOD, DOZING, 1f, FINISHED),
            )

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false, // Finished in DOZING, not GONE.
                    )
                )

            kosmos.setSceneTransition(Transition(from = Scenes.Lockscreen, to = Scenes.Gone))

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                    )
                )

            kosmos.setSceneTransition(Idle(Scenes.Gone))

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                    )
                )

            kosmos.setSceneTransition(Transition(from = Scenes.Gone, to = Scenes.Lockscreen))

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                    )
                )

            kosmos.setSceneTransition(Idle(Scenes.Lockscreen))

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                        false,
                    )
                )

            kosmos.setSceneTransition(Transition(from = Scenes.Lockscreen, to = Scenes.Gone))

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                        false,
                    )
                )

            kosmos.setSceneTransition(Idle(Scenes.Gone))

            assertThat(results)
                .isEqualTo(
                    listOf(
                        false,
                        true,
                        false,
                        true,
                    )
                )
        }

    @Test
    fun finishedKeyguardState_emitsAgainIfCancelledAndReversed() =
        testScope.runTest {
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.keyguard.shared.model

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.flags.EnableSceneContainer
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@SmallTest
@RunWith(AndroidJUnit4::class)
class KeyguardStateTest : SysuiTestCase() {

    /**
     * This test makes sure that the result of [deviceIsAwakeInState] are equal for all the states
     * that are obsolete with scene container enabled and UNDEFINED. This means for example that if
     * GONE is transformed to UNDEFINED it makes sure that GONE and UNDEFINED need to have the same
     * value. This assumption is important as with scene container flag enabled call sites will only
     * check the result passing in UNDEFINED.
     *
     * This is true today, but as more states may become obsolete this assumption may not be true
     * anymore and therefore [deviceIsAwakeInState] would need to be rewritten to factor in the
     * scene state.
     */
    @Test
    @EnableSceneContainer
    fun assertUndefinedResultMatchesObsoleteStateResults() {
        for (state in KeyguardState.entries) {
            val isAwakeInSceneContainer =
                KeyguardState.deviceIsAwakeInState(state.mapToSceneContainerState())
            val isAwake = KeyguardState.deviceIsAwakeInState(state)
            assertThat(isAwakeInSceneContainer).isEqualTo(isAwake)
        }
    }
}
+11 −4
Original line number Diff line number Diff line
@@ -38,8 +38,11 @@ import com.android.systemui.keyguard.domain.interactor.keyguardClockInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.scene.data.repository.Idle
import com.android.systemui.scene.data.repository.setTransition
import com.android.systemui.scene.domain.interactor.sceneContainerOcclusionInteractor
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
@@ -392,11 +395,15 @@ class StatusBarStateControllerImplTest(flags: FlagsParameterization) : SysuiTest
            )
            assertThat(underTest.leaveOpenOnKeyguardHide()).isEqualTo(true)

            keyguardTransitionRepository.sendTransitionSteps(
            kosmos.setTransition(
                sceneTransition = Idle(Scenes.Gone),
                stateTransition =
                    TransitionStep(
                        from = KeyguardState.LOCKSCREEN,
                        to = KeyguardState.GONE,
                testScope = testScope,
                    )
            )

            assertThat(underTest.leaveOpenOnKeyguardHide()).isEqualTo(false)
        }
}
Loading