diff options
| author | 2024-08-23 16:04:10 -0400 | |
|---|---|---|
| committer | 2024-08-26 19:30:51 +0000 | |
| commit | 346b11ffdcd26425883495ebd27f8cd8decdb230 (patch) | |
| tree | ccb76873deaf5a6b05ba2523ae99a6c716d84ce0 | |
| parent | 8702521d4e32cdb09702edc4f1195ad44e0fbd3d (diff) | |
Avoid changing scenes if already on the desired scene
This fixes a bug where the KeyguardState override set by calling
changeScene sticks around because the scene never actually changes. This
causes issues the next time a transition occurs, as we end up in the
wrong KeyguardState.
Bug: 361819832
Test: atest CommunalSceneInteractorTest
Flag: com.android.systemui.communal_scene_ktf_refactor
Change-Id: I5f45aaae037cce0e8f844698222a1a58577cbde7
3 files changed, 50 insertions, 7 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractorTest.kt index ed7e9107240e..dfb75cae6ecd 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractorTest.kt @@ -22,6 +22,7 @@ import com.android.compose.animation.scene.ObservableTransitionState import com.android.systemui.SysuiTestCase import com.android.systemui.animation.ActivityTransitionAnimator import com.android.systemui.communal.data.repository.communalSceneRepository +import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor.OnSceneAboutToChangeListener import com.android.systemui.communal.domain.model.CommunalTransitionProgressModel import com.android.systemui.communal.shared.model.CommunalScenes import com.android.systemui.communal.shared.model.EditModeState @@ -36,6 +37,11 @@ import kotlinx.coroutines.test.advanceTimeBy import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith +import org.mockito.kotlin.any +import org.mockito.kotlin.anyOrNull +import org.mockito.kotlin.mock +import org.mockito.kotlin.never +import org.mockito.kotlin.verify @SmallTest @RunWith(AndroidJUnit4::class) @@ -58,6 +64,36 @@ class CommunalSceneInteractorTest : SysuiTestCase() { } @Test + fun changeScene_callsSceneStateProcessor() = + testScope.runTest { + val callback: OnSceneAboutToChangeListener = mock() + underTest.registerSceneStateProcessor(callback) + + val currentScene by collectLastValue(underTest.currentScene) + assertThat(currentScene).isEqualTo(CommunalScenes.Blank) + verify(callback, never()).onSceneAboutToChange(any(), anyOrNull()) + + underTest.changeScene(CommunalScenes.Communal, "test") + assertThat(currentScene).isEqualTo(CommunalScenes.Communal) + verify(callback).onSceneAboutToChange(CommunalScenes.Communal, null) + } + + @Test + fun changeScene_doesNotCallSceneStateProcessorForDuplicateState() = + testScope.runTest { + val callback: OnSceneAboutToChangeListener = mock() + underTest.registerSceneStateProcessor(callback) + + val currentScene by collectLastValue(underTest.currentScene) + assertThat(currentScene).isEqualTo(CommunalScenes.Blank) + + underTest.changeScene(CommunalScenes.Blank, "test") + assertThat(currentScene).isEqualTo(CommunalScenes.Blank) + + verify(callback, never()).onSceneAboutToChange(any(), anyOrNull()) + } + + @Test fun snapToScene() = testScope.runTest { val currentScene by collectLastValue(underTest.currentScene) diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt index 7e28e19d0ee0..0bfcd242828d 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt @@ -36,11 +36,15 @@ import com.android.systemui.testKosmos import com.android.systemui.user.data.repository.FakeUserRepository import com.android.systemui.user.data.repository.fakeUserRepository import com.google.common.truth.Truth.assertThat +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.test.TestScope +import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +@OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(AndroidJUnit4::class) class CommunalTutorialInteractorTest : SysuiTestCase() { @@ -50,14 +54,14 @@ class CommunalTutorialInteractorTest : SysuiTestCase() { private lateinit var underTest: CommunalTutorialInteractor private lateinit var keyguardRepository: FakeKeyguardRepository private lateinit var communalTutorialRepository: FakeCommunalTutorialRepository - private lateinit var communalInteractor: CommunalInteractor + private lateinit var communalSceneInteractor: CommunalSceneInteractor private lateinit var userRepository: FakeUserRepository @Before fun setUp() { keyguardRepository = kosmos.fakeKeyguardRepository communalTutorialRepository = kosmos.fakeCommunalTutorialRepository - communalInteractor = kosmos.communalInteractor + communalSceneInteractor = kosmos.communalSceneInteractor userRepository = kosmos.fakeUserRepository kosmos.fakeFeatureFlagsClassic.set(Flags.COMMUNAL_SERVICE_ENABLED, true) @@ -158,7 +162,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() { kosmos.setCommunalAvailable(true) communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED) - communalInteractor.changeScene(CommunalScenes.Blank, "test") + communalSceneInteractor.changeScene(CommunalScenes.Blank, "test") assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_NOT_STARTED) } @@ -171,7 +175,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() { goToCommunal() communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_STARTED) - communalInteractor.changeScene(CommunalScenes.Blank, "test") + communalSceneInteractor.changeScene(CommunalScenes.Blank, "test") assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED) } @@ -184,13 +188,14 @@ class CommunalTutorialInteractorTest : SysuiTestCase() { goToCommunal() communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED) - communalInteractor.changeScene(CommunalScenes.Blank, "test") + communalSceneInteractor.changeScene(CommunalScenes.Blank, "test") assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED) } - private suspend fun goToCommunal() { + private suspend fun TestScope.goToCommunal() { kosmos.setCommunalAvailable(true) - communalInteractor.changeScene(CommunalScenes.Communal, "test") + communalSceneInteractor.changeScene(CommunalScenes.Communal, "test") + runCurrent() } } diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractor.kt index a0b996675331..8f756a23a9da 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractor.kt @@ -88,6 +88,7 @@ constructor( keyguardState: KeyguardState? = null, ) { applicationScope.launch("$TAG#changeScene") { + if (currentScene.value == newScene) return@launch logger.logSceneChangeRequested( from = currentScene.value, to = newScene, @@ -108,6 +109,7 @@ constructor( ) { applicationScope.launch("$TAG#snapToScene") { delay(delayMillis) + if (currentScene.value == newScene) return@launch logger.logSceneChangeRequested( from = currentScene.value, to = newScene, |