summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-08-27 01:58:29 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-08-27 01:58:29 +0000
commitb1f88d1156aeea8cfaee1cfb50bc596ceea7f1be (patch)
tree35753a7a1e52db7147767f74c2186d5e19108fe5
parent13d424b6d906edd0ee76dfd5c835829f6a5d1cb9 (diff)
parent346b11ffdcd26425883495ebd27f8cd8decdb230 (diff)
Merge "Avoid changing scenes if already on the desired scene" into main
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractorTest.kt36
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt19
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalSceneInteractor.kt2
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,