summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-10-25 20:32:36 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-10-25 20:32:36 +0000
commit39529764ef98d18dc86acc37bdfe255d7dcfec09 (patch)
treed6cb95a52ae22c2c4f704686886d01c5f7748235
parent478117662409a5bfe03c51ea0e5c1d43db64110e (diff)
parent343d03d434959afd13b9f1b81adbc5e125e57932 (diff)
Merge "Refactor SharedNotificationContainerInteractor/ViewModel." into main
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt43
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractor.kt30
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt153
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractorKosmos.kt2
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt6
5 files changed, 135 insertions, 99 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt
index 33bf3507adb0..d5a7c89e6c71 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelTest.kt
@@ -64,7 +64,6 @@ 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.model.Scenes
-import com.android.systemui.shade.data.repository.fakeShadeRepository
import com.android.systemui.shade.mockLargeScreenHeaderHelper
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.statusbar.notification.stack.domain.interactor.sharedNotificationContainerInteractor
@@ -116,36 +115,18 @@ class SharedNotificationContainerViewModelTest(flags: FlagsParameterization) : S
kosmos.aodBurnInViewModel = aodBurnInViewModel
}
- val testScope = kosmos.testScope
- val configurationRepository
- get() = kosmos.fakeConfigurationRepository
-
- val keyguardRepository
- get() = kosmos.fakeKeyguardRepository
-
- val keyguardInteractor
- get() = kosmos.keyguardInteractor
-
- val keyguardRootViewModel
- get() = kosmos.keyguardRootViewModel
-
- val keyguardTransitionRepository
- get() = kosmos.fakeKeyguardTransitionRepository
-
- val shadeTestUtil
- get() = kosmos.shadeTestUtil
-
- val sharedNotificationContainerInteractor
- get() = kosmos.sharedNotificationContainerInteractor
-
- val largeScreenHeaderHelper
- get() = kosmos.mockLargeScreenHeaderHelper
-
- val communalSceneRepository
- get() = kosmos.communalSceneRepository
-
- val shadeRepository
- get() = kosmos.fakeShadeRepository
+ private val testScope = kosmos.testScope
+ private val configurationRepository by lazy { kosmos.fakeConfigurationRepository }
+ private val keyguardRepository by lazy { kosmos.fakeKeyguardRepository }
+ private val keyguardInteractor by lazy { kosmos.keyguardInteractor }
+ private val keyguardRootViewModel by lazy { kosmos.keyguardRootViewModel }
+ private val keyguardTransitionRepository by lazy { kosmos.fakeKeyguardTransitionRepository }
+ private val shadeTestUtil by lazy { kosmos.shadeTestUtil }
+ private val sharedNotificationContainerInteractor by lazy {
+ kosmos.sharedNotificationContainerInteractor
+ }
+ private val largeScreenHeaderHelper by lazy { kosmos.mockLargeScreenHeaderHelper }
+ private val communalSceneRepository by lazy { kosmos.communalSceneRepository }
lateinit var underTest: SharedNotificationContainerViewModel
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractor.kt
index 4894ad3f1192..e644815960aa 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractor.kt
@@ -26,7 +26,6 @@ import com.android.systemui.res.R
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.shade.LargeScreenHeaderHelper
import com.android.systemui.shade.ShadeDisplayAware
-import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.statusbar.policy.SplitShadeStateController
import dagger.Lazy
import javax.inject.Inject
@@ -48,7 +47,6 @@ class SharedNotificationContainerInteractor
constructor(
@ShadeDisplayAware private val context: Context,
private val splitShadeStateController: Lazy<SplitShadeStateController>,
- private val shadeInteractor: Lazy<ShadeInteractor>,
configurationInteractor: ConfigurationInteractor,
keyguardInteractor: KeyguardInteractor,
deviceEntryUdfpsInteractor: DeviceEntryUdfpsInteractor,
@@ -67,23 +65,14 @@ constructor(
* distinctUntilChanged() to this would cause configurationBasedDimensions to miss configuration
* updates that affect other resources, like margins or the large screen header flag.
*/
- private val dimensionsUpdateEventsWithShouldUseSplitShade: Flow<Boolean> =
- if (SceneContainerFlag.isEnabled) {
- combine(
- configurationInteractor.onAnyConfigurationChange,
- shadeInteractor.get().isShadeLayoutWide,
- ) { _, isShadeLayoutWide ->
- isShadeLayoutWide
- }
- } else {
- configurationInteractor.onAnyConfigurationChange.map {
- splitShadeStateController.get().shouldUseSplitNotificationShade(context.resources)
- }
- }
-
+ @Deprecated("Use SharedNotificationContainerViewModel.ConfigurationBasedDimensions instead")
val configurationBasedDimensions: Flow<ConfigurationBasedDimensions> =
- dimensionsUpdateEventsWithShouldUseSplitShade
- .map { shouldUseSplitShade ->
+ configurationInteractor.onAnyConfigurationChange
+ .map {
+ val shouldUseSplitShade =
+ splitShadeStateController
+ .get()
+ .shouldUseSplitNotificationShade(context.resources)
with(context.resources) {
ConfigurationBasedDimensions(
useSplitShade = shouldUseSplitShade,
@@ -102,6 +91,10 @@ constructor(
}
}
.distinctUntilChanged()
+ get() {
+ SceneContainerFlag.assertInLegacyMode()
+ return field
+ }
/**
* The notification shelf can extend over the lock icon area if:
@@ -126,6 +119,7 @@ constructor(
_notificationStackChanged.value = _notificationStackChanged.value + 1
}
+ @Deprecated("Use SharedNotificationContainerViewModel.ConfigurationBasedDimensions instead")
data class ConfigurationBasedDimensions(
val useSplitShade: Boolean,
val useLargeScreenHeader: Boolean,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
index eeebac06206c..e6663d51aed5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModel.kt
@@ -19,9 +19,11 @@
package com.android.systemui.statusbar.notification.stack.ui.viewmodel
+import android.content.Context
import androidx.annotation.VisibleForTesting
import com.android.app.tracing.coroutines.flow.flowName
import com.android.systemui.common.shared.model.NotificationContainerBounds
+import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
@@ -66,10 +68,14 @@ import com.android.systemui.keyguard.ui.viewmodel.OffToLockscreenTransitionViewM
import com.android.systemui.keyguard.ui.viewmodel.PrimaryBouncerToGoneTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.PrimaryBouncerToLockscreenTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.ViewStateAccessor
+import com.android.systemui.res.R
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.shared.model.Scenes
+import com.android.systemui.shade.LargeScreenHeaderHelper
import com.android.systemui.shade.domain.interactor.ShadeInteractor
-import com.android.systemui.shade.shared.flag.DualShade
+import com.android.systemui.shade.shared.model.ShadeMode.Dual
+import com.android.systemui.shade.shared.model.ShadeMode.Single
+import com.android.systemui.shade.shared.model.ShadeMode.Split
import com.android.systemui.statusbar.notification.domain.interactor.HeadsUpNotificationInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.NotificationStackAppearanceInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.SharedNotificationContainerInteractor
@@ -90,6 +96,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combineTransform
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
+import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
@@ -108,6 +115,8 @@ constructor(
private val interactor: SharedNotificationContainerInteractor,
dumpManager: DumpManager,
@Application applicationScope: CoroutineScope,
+ private val context: Context,
+ configurationInteractor: ConfigurationInteractor,
private val keyguardInteractor: KeyguardInteractor,
private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
private val shadeInteractor: ShadeInteractor,
@@ -145,6 +154,7 @@ constructor(
private val communalSceneInteractor: CommunalSceneInteractor,
// Lazy because it's only used in the SceneContainer + Dual Shade configuration.
headsUpNotificationInteractor: Lazy<HeadsUpNotificationInteractor>,
+ private val largeScreenHeaderHelperLazy: Lazy<LargeScreenHeaderHelper>,
unfoldTransitionInteractor: UnfoldTransitionInteractor,
) : FlowDumperImpl(dumpManager) {
@@ -187,33 +197,62 @@ constructor(
@VisibleForTesting
val paddingTopDimen: Flow<Int> =
- interactor.configurationBasedDimensions
- .map {
- when {
- it.useLargeScreenHeader -> it.marginTopLargeScreen
- else -> it.marginTop
+ if (SceneContainerFlag.isEnabled) {
+ configurationInteractor.onAnyConfigurationChange.map {
+ with(context.resources) {
+ val useLargeScreenHeader =
+ getBoolean(R.bool.config_use_large_screen_shade_header)
+ if (useLargeScreenHeader) {
+ largeScreenHeaderHelperLazy.get().getLargeScreenHeaderHeight()
+ } else {
+ getDimensionPixelSize(R.dimen.notification_panel_margin_top)
+ }
+ }
+ }
+ } else {
+ interactor.configurationBasedDimensions.map {
+ when {
+ it.useLargeScreenHeader -> it.marginTopLargeScreen
+ else -> it.marginTop
+ }
}
}
.distinctUntilChanged()
.dumpWhileCollecting("paddingTopDimen")
val configurationBasedDimensions: Flow<ConfigurationBasedDimensions> =
- interactor.configurationBasedDimensions
- .map {
- val marginTop =
- when {
- // y position of the NSSL in the window needs to be 0 under scene container
- SceneContainerFlag.isEnabled -> 0
- it.useLargeScreenHeader -> it.marginTopLargeScreen
- else -> it.marginTop
+ if (SceneContainerFlag.isEnabled) {
+ combine(
+ shadeInteractor.isShadeLayoutWide,
+ configurationInteractor.onAnyConfigurationChange,
+ ) { isShadeLayoutWide, _ ->
+ with(context.resources) {
+ // TODO(b/338033836): Define separate horizontal margins for dual shade.
+ val marginHorizontal =
+ getDimensionPixelSize(R.dimen.notification_panel_margin_horizontal)
+ ConfigurationBasedDimensions(
+ marginStart = if (isShadeLayoutWide) 0 else marginHorizontal,
+ marginEnd = marginHorizontal,
+ marginBottom =
+ getDimensionPixelSize(R.dimen.notification_panel_margin_bottom),
+ // y position of the NSSL in the window needs to be 0 under scene
+ // container
+ marginTop = 0,
+ useSplitShade = isShadeLayoutWide,
+ )
}
- ConfigurationBasedDimensions(
- marginStart = if (it.useSplitShade) 0 else it.marginHorizontal,
- marginEnd = it.marginHorizontal,
- marginBottom = it.marginBottom,
- marginTop = marginTop,
- useSplitShade = it.useSplitShade,
- )
+ }
+ } else {
+ interactor.configurationBasedDimensions.map {
+ ConfigurationBasedDimensions(
+ marginStart = if (it.useSplitShade) 0 else it.marginHorizontal,
+ marginEnd = it.marginHorizontal,
+ marginBottom = it.marginBottom,
+ marginTop =
+ if (it.useLargeScreenHeader) it.marginTopLargeScreen else it.marginTop,
+ useSplitShade = it.useSplitShade,
+ )
+ }
}
.distinctUntilChanged()
.dumpWhileCollecting("configurationBasedDimensions")
@@ -406,42 +445,60 @@ constructor(
* notifications unless in splitshade.
*/
private val alphaForShadeAndQsExpansion: Flow<Float> =
- if (DualShade.isEnabled) {
- combineTransform(
- headsUpNotificationInteractor.get().isHeadsUpOrAnimatingAway,
- shadeInteractor.shadeExpansion,
- shadeInteractor.qsExpansion,
- ) { isHeadsUpOrAnimatingAway, shadeExpansion, qsExpansion ->
- if (isHeadsUpOrAnimatingAway) {
- // Ensure HUNs will be visible in QS shade (at least while unlocked)
- emit(1f)
- } else if (shadeExpansion > 0f || qsExpansion > 0f) {
- // Fade out as QS shade expands
- emit(1f - qsExpansion)
- }
- }
- } else {
- interactor.configurationBasedDimensions.flatMapLatest { configurationBasedDimensions
- ->
- combineTransform(shadeInteractor.shadeExpansion, shadeInteractor.qsExpansion) {
- shadeExpansion,
- qsExpansion ->
- if (shadeExpansion > 0f || qsExpansion > 0f) {
- if (configurationBasedDimensions.useSplitShade) {
- emit(1f)
- } else if (qsExpansion == 1f) {
+ if (SceneContainerFlag.isEnabled) {
+ shadeInteractor.shadeMode.flatMapLatest { shadeMode ->
+ when (shadeMode) {
+ Single ->
+ combineTransform(
+ shadeInteractor.shadeExpansion,
+ shadeInteractor.qsExpansion,
+ ) { shadeExpansion, qsExpansion ->
+ if (qsExpansion == 1f) {
// Ensure HUNs will be visible in QS shade (at least while unlocked)
emit(1f)
- } else {
+ } else if (shadeExpansion > 0f || qsExpansion > 0f) {
// Fade as QS shade expands
emit(1f - qsExpansion)
}
}
+ Split -> isAnyExpanded.filter { it }.map { 1f }
+ Dual ->
+ combineTransform(
+ headsUpNotificationInteractor.get().isHeadsUpOrAnimatingAway,
+ shadeInteractor.shadeExpansion,
+ shadeInteractor.qsExpansion,
+ ) { isHeadsUpOrAnimatingAway, shadeExpansion, qsExpansion ->
+ if (isHeadsUpOrAnimatingAway) {
+ // Ensure HUNs will be visible in QS shade (at least while unlocked)
+ emit(1f)
+ } else if (shadeExpansion > 0f || qsExpansion > 0f) {
+ // Fade out as QS shade expands
+ emit(1f - qsExpansion)
+ }
+ }
+ }
+ }
+ } else {
+ interactor.configurationBasedDimensions.flatMapLatest { configurationBasedDimensions ->
+ combineTransform(shadeInteractor.shadeExpansion, shadeInteractor.qsExpansion) {
+ shadeExpansion,
+ qsExpansion ->
+ if (shadeExpansion > 0f || qsExpansion > 0f) {
+ if (configurationBasedDimensions.useSplitShade) {
+ emit(1f)
+ } else if (qsExpansion == 1f) {
+ // Ensure HUNs will be visible in QS shade (at least while unlocked)
+ emit(1f)
+ } else {
+ // Fade as QS shade expands
+ emit(1f - qsExpansion)
+ }
}
}
}
- .onStart { emit(1f) }
- .dumpWhileCollecting("alphaForShadeAndQsExpansion")
+ }
+ .onStart { emit(1f) }
+ .dumpWhileCollecting("alphaForShadeAndQsExpansion")
val panelAlpha = keyguardInteractor.panelAlpha
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractorKosmos.kt
index 83fc3e9f0c58..b1e9d89dfd42 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractorKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/domain/interactor/SharedNotificationContainerInteractorKosmos.kt
@@ -23,7 +23,6 @@ import com.android.systemui.common.ui.domain.interactor.configurationInteractor
import com.android.systemui.deviceentry.domain.interactor.deviceEntryUdfpsInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.kosmos.Kosmos
-import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.largeScreenHeaderHelper
import com.android.systemui.statusbar.policy.splitShadeStateController
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -33,7 +32,6 @@ val Kosmos.sharedNotificationContainerInteractor by
SharedNotificationContainerInteractor(
context = applicationContext,
splitShadeStateController = { splitShadeStateController },
- shadeInteractor = { shadeInteractor },
configurationInteractor = configurationInteractor,
keyguardInteractor = keyguardInteractor,
deviceEntryUdfpsInteractor = deviceEntryUdfpsInteractor,
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
index a25a3c0c2044..7fbf4e495feb 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/SharedNotificationContainerViewModelKosmos.kt
@@ -16,6 +16,8 @@
package com.android.systemui.statusbar.notification.stack.ui.viewmodel
+import android.content.applicationContext
+import com.android.systemui.common.ui.domain.interactor.configurationInteractor
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.dump.dumpManager
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
@@ -49,6 +51,7 @@ import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.shade.domain.interactor.shadeInteractor
+import com.android.systemui.shade.largeScreenHeaderHelper
import com.android.systemui.statusbar.notification.stack.domain.interactor.headsUpNotificationInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.notificationStackAppearanceInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.sharedNotificationContainerInteractor
@@ -61,6 +64,8 @@ val Kosmos.sharedNotificationContainerViewModel by Fixture {
interactor = sharedNotificationContainerInteractor,
dumpManager = dumpManager,
applicationScope = applicationCoroutineScope,
+ context = applicationContext,
+ configurationInteractor = configurationInteractor,
keyguardInteractor = keyguardInteractor,
keyguardTransitionInteractor = keyguardTransitionInteractor,
shadeInteractor = shadeInteractor,
@@ -94,6 +99,7 @@ val Kosmos.sharedNotificationContainerViewModel by Fixture {
aodBurnInViewModel = aodBurnInViewModel,
communalSceneInteractor = communalSceneInteractor,
headsUpNotificationInteractor = { headsUpNotificationInteractor },
+ largeScreenHeaderHelperLazy = { largeScreenHeaderHelper },
unfoldTransitionInteractor = unfoldTransitionInteractor,
)
}