summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lucas Silva <lusilva@google.com> 2024-01-26 21:07:57 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-01-26 21:07:57 +0000
commit9dcdc9699607f80c3a38f8b116c2b5324f6cec43 (patch)
tree6572a3fd6374ebe2b0fe4111ec60ced963ebc53e
parent935ee0def561baeac48866ec170364f918ec0fba (diff)
parentfdda7b485b0d12f9a9be618b9870e0b9e012756a (diff)
Merge "Cleanup hub disabled flow by consolidating logic" into main
-rw-r--r--packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt8
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt23
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractorTest.kt22
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt3
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartableTest.kt4
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt34
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt2
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt8
-rw-r--r--packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java2
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt2
11 files changed, 48 insertions, 62 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
index 4fdcf7579dc6..ff5a69801c56 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt
@@ -64,14 +64,6 @@ fun CommunalContainer(
transitions = sceneTransitions,
)
- // Don't show hub mode UI if communal is not available. Communal is only available if it has
- // been enabled via settings and either keyguard is showing, or, the device is currently
- // dreaming.
- val isCommunalAvailable by viewModel.isCommunalAvailable.collectAsState()
- if (!isCommunalAvailable) {
- return
- }
-
// This effect exposes the SceneTransitionLayout's observable transition state to the rest of
// the system, and unsets it when the view is disposed to avoid a memory leak.
DisposableEffect(viewModel, sceneTransitionLayoutState) {
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt
index b1224ffa702e..ee01bf9c26e4 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt
@@ -125,7 +125,7 @@ class CommunalInteractorTest : SysuiTestCase() {
keyguardRepository.setIsEncryptedOrLockdown(false)
userRepository.setSelectedUserInfo(mainUser)
keyguardRepository.setKeyguardShowing(true)
- runCurrent()
+ communalRepository.setCommunalEnabledState(true)
assertThat(isAvailable).isTrue()
}
@@ -138,7 +138,8 @@ class CommunalInteractorTest : SysuiTestCase() {
keyguardRepository.setIsEncryptedOrLockdown(true)
userRepository.setSelectedUserInfo(mainUser)
- runCurrent()
+ keyguardRepository.setKeyguardShowing(true)
+ communalRepository.setCommunalEnabledState(true)
assertThat(isAvailable).isFalse()
}
@@ -152,7 +153,7 @@ class CommunalInteractorTest : SysuiTestCase() {
keyguardRepository.setIsEncryptedOrLockdown(false)
userRepository.setSelectedUserInfo(secondaryUser)
keyguardRepository.setKeyguardShowing(true)
- runCurrent()
+ communalRepository.setCommunalEnabledState(true)
assertThat(isAvailable).isFalse()
}
@@ -166,12 +167,26 @@ class CommunalInteractorTest : SysuiTestCase() {
keyguardRepository.setIsEncryptedOrLockdown(false)
userRepository.setSelectedUserInfo(mainUser)
keyguardRepository.setDreaming(true)
- runCurrent()
+ communalRepository.setCommunalEnabledState(true)
assertThat(isAvailable).isTrue()
}
@Test
+ fun isCommunalAvailable_communalDisabled_false() =
+ testScope.runTest {
+ val isAvailable by collectLastValue(underTest.isCommunalAvailable)
+ assertThat(isAvailable).isFalse()
+
+ keyguardRepository.setIsEncryptedOrLockdown(false)
+ userRepository.setSelectedUserInfo(mainUser)
+ keyguardRepository.setKeyguardShowing(true)
+ communalRepository.setCommunalEnabledState(false)
+
+ assertThat(isAvailable).isFalse()
+ }
+
+ @Test
fun widget_tutorialCompletedAndWidgetsAvailable_showWidgetContent() =
testScope.runTest {
// Keyguard showing, and tutorial completed.
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 352463f5a198..6c87e0f2eb23 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
@@ -34,20 +34,15 @@ import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.user.data.repository.fakeUserRepository
-import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
-import org.mockito.Mock
-import org.mockito.MockitoAnnotations
@SmallTest
@RunWith(AndroidJUnit4::class)
class CommunalTutorialInteractorTest : SysuiTestCase() {
- @Mock lateinit var user: UserInfo
-
private val kosmos = testKosmos()
private val testScope = kosmos.testScope
@@ -60,14 +55,14 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
@Before
fun setUp() {
- MockitoAnnotations.initMocks(this)
-
keyguardRepository = kosmos.fakeKeyguardRepository
communalTutorialRepository = kosmos.fakeCommunalTutorialRepository
communalRepository = kosmos.fakeCommunalRepository
communalInteractor = kosmos.communalInteractor
userRepository = kosmos.fakeUserRepository
+ userRepository.setUserInfos(listOf(MAIN_USER_INFO))
+
underTest = kosmos.communalTutorialInteractor
}
@@ -204,12 +199,17 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
private suspend fun setCommunalAvailable(available: Boolean) {
if (available) {
communalRepository.setIsCommunalEnabled(true)
+ communalRepository.setCommunalEnabledState(true)
keyguardRepository.setIsEncryptedOrLockdown(false)
- whenever(user.isMain).thenReturn(true)
- userRepository.setUserInfos(listOf(user))
- userRepository.setSelectedUserInfo(user)
+ userRepository.setSelectedUserInfo(MAIN_USER_INFO)
+ keyguardRepository.setKeyguardShowing(true)
} else {
- keyguardRepository.setIsEncryptedOrLockdown(true)
+ communalRepository.setIsCommunalEnabled(false)
+ communalRepository.setCommunalEnabledState(false)
}
}
+
+ private companion object {
+ val MAIN_USER_INFO = UserInfo(0, "primary", UserInfo.FLAG_MAIN)
+ }
}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt
index c814f3f1db6a..0723e8306f71 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt
@@ -27,6 +27,7 @@ import com.android.systemui.communal.data.repository.FakeCommunalMediaRepository
import com.android.systemui.communal.data.repository.FakeCommunalTutorialRepository
import com.android.systemui.communal.data.repository.FakeCommunalWidgetRepository
import com.android.systemui.communal.data.repository.fakeCommunalMediaRepository
+import com.android.systemui.communal.data.repository.fakeCommunalRepository
import com.android.systemui.communal.data.repository.fakeCommunalTutorialRepository
import com.android.systemui.communal.data.repository.fakeCommunalWidgetRepository
import com.android.systemui.communal.domain.interactor.communalInteractor
@@ -90,6 +91,8 @@ class CommunalViewModelTest : SysuiTestCase() {
mediaRepository = kosmos.fakeCommunalMediaRepository
userRepository = kosmos.fakeUserRepository
+ kosmos.fakeCommunalRepository.setCommunalEnabledState(true)
+
underTest =
CommunalViewModel(
testScope,
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartableTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartableTest.kt
index 112b0c797854..a3654b6e8963 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartableTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartableTest.kt
@@ -20,6 +20,7 @@ import android.content.pm.UserInfo
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
+import com.android.systemui.communal.data.repository.fakeCommunalRepository
import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.kosmos.applicationCoroutineScope
@@ -121,9 +122,10 @@ class CommunalAppWidgetHostStartableTest : SysuiTestCase() {
private suspend fun setCommunalAvailable(available: Boolean) =
with(kosmos) {
- fakeKeyguardRepository.setIsEncryptedOrLockdown(!available)
+ fakeKeyguardRepository.setIsEncryptedOrLockdown(false)
fakeUserRepository.setSelectedUserInfo(MAIN_USER_INFO)
fakeKeyguardRepository.setKeyguardShowing(true)
+ fakeCommunalRepository.setCommunalEnabledState(available)
}
private companion object {
diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt
index 89e31f383c43..80fee640974d 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt
@@ -33,7 +33,6 @@ import com.android.systemui.communal.widgets.CommunalAppWidgetHost
import com.android.systemui.communal.widgets.EditWidgetsActivityStarter
import com.android.systemui.communal.widgets.WidgetConfigurator
import com.android.systemui.dagger.SysUISingleton
-import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.smartspace.data.repository.SmartspaceRepository
import com.android.systemui.user.data.repository.UserRepository
@@ -41,11 +40,9 @@ import com.android.systemui.util.kotlin.BooleanFlowOperators.and
import com.android.systemui.util.kotlin.BooleanFlowOperators.not
import com.android.systemui.util.kotlin.BooleanFlowOperators.or
import javax.inject.Inject
-import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
@@ -53,7 +50,6 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.flow.stateIn
/** Encapsulates business-logic related to communal mode. */
@OptIn(ExperimentalCoroutinesApi::class)
@@ -61,7 +57,6 @@ import kotlinx.coroutines.flow.stateIn
class CommunalInteractor
@Inject
constructor(
- @Application applicationScope: CoroutineScope,
private val communalRepository: CommunalRepository,
private val widgetRepository: CommunalWidgetRepository,
private val communalPrefsRepository: CommunalPrefsRepository,
@@ -81,30 +76,15 @@ constructor(
val isCommunalEnabled: Boolean
get() = communalRepository.isCommunalEnabled
- /** A {@link StateFlow} that tracks whether communal features are enabled. */
- val communalEnabledState: StateFlow<Boolean>
- get() = communalRepository.communalEnabledState
-
/** Whether communal features are enabled and available. */
- val isCommunalAvailable: StateFlow<Boolean> =
- flowOf(isCommunalEnabled)
- .flatMapLatest { enabled ->
- if (enabled) {
- val isMainUser = userRepository.selectedUserInfo.map { it.isMain }
- and(
- isMainUser,
- not(keyguardInteractor.isEncryptedOrLockdown),
- or(keyguardInteractor.isKeyguardVisible, keyguardInteractor.isDreaming),
- )
- } else {
- flowOf(false)
- }
- }
- .stateIn(
- scope = applicationScope,
- started = SharingStarted.WhileSubscribed(),
- initialValue = false,
+ val isCommunalAvailable: Flow<Boolean> =
+ and(
+ communalRepository.communalEnabledState,
+ userRepository.selectedUserInfo.map { it.isMain },
+ not(keyguardInteractor.isEncryptedOrLockdown),
+ or(keyguardInteractor.isKeyguardVisible, keyguardInteractor.isDreaming)
)
+ .distinctUntilChanged()
/**
* Target scene as requested by the underlying [SceneTransitionLayout] or through
diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt
index 91df8289ca64..a87ebd7e8e9f 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt
@@ -33,8 +33,6 @@ abstract class BaseCommunalViewModel(
private val communalInteractor: CommunalInteractor,
val mediaHost: MediaHost,
) {
- val isCommunalAvailable: StateFlow<Boolean> = communalInteractor.isCommunalAvailable
-
val currentScene: StateFlow<CommunalSceneKey> = communalInteractor.desiredScene
/** Whether widgets are currently being re-ordered. */
diff --git a/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt b/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt
index 97ec3f98cf0c..1c7cc007cbc7 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt
+++ b/packages/SystemUI/src/com/android/systemui/shade/GlanceableHubContainerController.kt
@@ -34,7 +34,7 @@ import com.android.systemui.res.R
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.util.kotlin.collectFlow
import javax.inject.Inject
-import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.Flow
/**
* Controller that's responsible for the glanceable hub container view and its touch handling.
@@ -110,10 +110,8 @@ constructor(
return communalInteractor.isCommunalEnabled && isComposeAvailable()
}
- /** Returns a {@link StateFlow} that tracks whether communal hub is enabled. */
- fun enabledState(): StateFlow<Boolean> {
- return communalInteractor.communalEnabledState
- }
+ /** Returns a {@link StateFlow} that tracks whether communal hub is available. */
+ fun communalAvailable(): Flow<Boolean> = communalInteractor.isCommunalAvailable
/**
* Creates the container view containing the glanceable hub UI.
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java
index 5ecc54b09806..19a58401cbec 100644
--- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java
@@ -607,7 +607,7 @@ public class NotificationShadeWindowViewController implements Dumpable {
public void setupCommunalHubLayout() {
collectFlow(
mView,
- mGlanceableHubContainerController.enabledState(),
+ mGlanceableHubContainerController.communalAvailable(),
isEnabled -> {
if (isEnabled) {
View communalPlaceholder = mView.findViewById(R.id.communal_ui_stub);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt
index 6681ceee3d09..22b05be507c6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt
@@ -514,7 +514,7 @@ class NotificationShadeWindowViewControllerTest : SysuiTestCase() {
}
whenever(mGlanceableHubContainerController.isEnabled()).thenReturn(false)
- whenever(mGlanceableHubContainerController.enabledState())
+ whenever(mGlanceableHubContainerController.communalAvailable())
.thenReturn(MutableStateFlow(false))
val mockCommunalPlaceholder = mock(View::class.java)
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt
index 1abf71fde14c..c818e9c8971c 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorKosmos.kt
@@ -24,14 +24,12 @@ import com.android.systemui.communal.widgets.EditWidgetsActivityStarter
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
-import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.smartspace.data.repository.smartspaceRepository
import com.android.systemui.user.data.repository.userRepository
import com.android.systemui.util.mockito.mock
val Kosmos.communalInteractor by Fixture {
CommunalInteractor(
- applicationScope = applicationCoroutineScope,
communalRepository = communalRepository,
widgetRepository = communalWidgetRepository,
mediaRepository = communalMediaRepository,