summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsSceneViewModel.kt45
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsSceneViewModelTest.kt115
2 files changed, 160 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsSceneViewModel.kt b/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsSceneViewModel.kt
new file mode 100644
index 000000000000..6525a98b9102
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsSceneViewModel.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2023 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.qs.ui.viewmodel
+
+import com.android.systemui.keyguard.domain.interactor.LockScreenSceneInteractor
+import dagger.assisted.Assisted
+import dagger.assisted.AssistedFactory
+import dagger.assisted.AssistedInject
+
+/** Models UI state and handles user input for the quick settings scene. */
+class QuickSettingsSceneViewModel
+@AssistedInject
+constructor(
+ lockScreenSceneInteractorFactory: LockScreenSceneInteractor.Factory,
+ @Assisted containerName: String,
+) {
+ private val lockScreenSceneInteractor: LockScreenSceneInteractor =
+ lockScreenSceneInteractorFactory.create(containerName)
+
+ /** Notifies that some content in quick settings was clicked. */
+ fun onContentClicked() {
+ lockScreenSceneInteractor.dismissLockScreen()
+ }
+
+ @AssistedFactory
+ interface Factory {
+ fun create(
+ containerName: String,
+ ): QuickSettingsSceneViewModel
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsSceneViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsSceneViewModelTest.kt
new file mode 100644
index 000000000000..e8875bee5276
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/ui/viewmodel/QuickSettingsSceneViewModelTest.kt
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2023 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.qs.ui.viewmodel
+
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.authentication.data.repository.AuthenticationRepositoryImpl
+import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor
+import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
+import com.android.systemui.bouncer.data.repo.BouncerRepository
+import com.android.systemui.bouncer.domain.interactor.BouncerInteractor
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.keyguard.domain.interactor.LockScreenSceneInteractor
+import com.android.systemui.scene.data.repository.fakeSceneContainerRepository
+import com.android.systemui.scene.domain.interactor.SceneInteractor
+import com.android.systemui.scene.shared.model.SceneKey
+import com.android.systemui.scene.shared.model.SceneModel
+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.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@OptIn(ExperimentalCoroutinesApi::class)
+@SmallTest
+@RunWith(JUnit4::class)
+class QuickSettingsSceneViewModelTest : SysuiTestCase() {
+
+ private val testScope = TestScope()
+ private val sceneInteractor =
+ SceneInteractor(
+ repository = fakeSceneContainerRepository(),
+ )
+ private val mAuthenticationInteractor =
+ AuthenticationInteractor(
+ applicationScope = testScope.backgroundScope,
+ repository = AuthenticationRepositoryImpl(),
+ )
+
+ private val underTest =
+ QuickSettingsSceneViewModel(
+ lockScreenSceneInteractorFactory =
+ object : LockScreenSceneInteractor.Factory {
+ override fun create(containerName: String): LockScreenSceneInteractor {
+ return LockScreenSceneInteractor(
+ applicationScope = testScope.backgroundScope,
+ authenticationInteractor = mAuthenticationInteractor,
+ bouncerInteractorFactory =
+ object : BouncerInteractor.Factory {
+ override fun create(containerName: String): BouncerInteractor {
+ return BouncerInteractor(
+ applicationScope = testScope.backgroundScope,
+ applicationContext = context,
+ repository = BouncerRepository(),
+ authenticationInteractor = mAuthenticationInteractor,
+ sceneInteractor = sceneInteractor,
+ containerName = containerName,
+ )
+ }
+ },
+ sceneInteractor = sceneInteractor,
+ containerName = CONTAINER_NAME,
+ )
+ }
+ },
+ containerName = CONTAINER_NAME
+ )
+
+ @Test
+ fun onContentClicked_deviceUnlocked_switchesToGone() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.currentScene(CONTAINER_NAME))
+ mAuthenticationInteractor.setAuthenticationMethod(AuthenticationMethodModel.PIN(1234))
+ mAuthenticationInteractor.unlockDevice()
+ runCurrent()
+
+ underTest.onContentClicked()
+
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Gone))
+ }
+
+ @Test
+ fun onContentClicked_deviceLockedSecurely_switchesToBouncer() =
+ testScope.runTest {
+ val currentScene by collectLastValue(sceneInteractor.currentScene(CONTAINER_NAME))
+ mAuthenticationInteractor.setAuthenticationMethod(AuthenticationMethodModel.PIN(1234))
+ mAuthenticationInteractor.lockDevice()
+ runCurrent()
+
+ underTest.onContentClicked()
+
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Bouncer))
+ }
+
+ companion object {
+ private const val CONTAINER_NAME = "container1"
+ }
+}