Merge "Move EmptyShadeViewModel flows to the bg" into main
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt
index 8c8f200..695e088 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt
@@ -18,6 +18,8 @@
 
 import android.content.Context
 import android.icu.text.MessageFormat
+import com.android.app.tracing.coroutines.flow.flowOn
+import com.android.systemui.dagger.qualifiers.Background
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.modes.shared.ModesUi
 import com.android.systemui.res.R
@@ -32,6 +34,7 @@
 import dagger.assisted.AssistedFactory
 import dagger.assisted.AssistedInject
 import java.util.Locale
+import kotlinx.coroutines.CoroutineDispatcher
 import kotlinx.coroutines.flow.Flow
 import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.StateFlow
@@ -50,11 +53,16 @@
     zenModeInteractor: ZenModeInteractor,
     seenNotificationsInteractor: SeenNotificationsInteractor,
     notificationSettingsInteractor: NotificationSettingsInteractor,
+    @Background bgDispatcher: CoroutineDispatcher,
     dumpManager: DumpManager,
 ) : FlowDumperImpl(dumpManager) {
     val areNotificationsHiddenInShade: Flow<Boolean> by lazy {
         if (FooterViewRefactor.isUnexpectedlyInLegacyMode()) {
             flowOf(false)
+        } else if (ModesEmptyShadeFix.isEnabled) {
+            zenModeInteractor.areNotificationsHiddenInShade
+                .dumpWhileCollecting("areNotificationsHiddenInShade")
+                .flowOn(bgDispatcher)
         } else {
             zenModeInteractor.areNotificationsHiddenInShade.dumpWhileCollecting(
                 "areNotificationsHiddenInShade"
@@ -80,31 +88,33 @@
             // recommended architecture, and making it so it reacts to changes for the new Modes.
             // The former does not depend on the modes flags being on, but the latter does.
             if (ModesUi.isEnabled) {
-                zenModeInteractor.modesHidingNotifications.map { modes ->
-                    // Create a string that is either "No notifications" if no modes are filtering
-                    // them out, or something like "Notifications paused by SomeMode" otherwise.
-                    val msgFormat =
-                        MessageFormat(
-                            context.getString(R.string.modes_suppressing_shade_text),
-                            Locale.getDefault(),
-                        )
-                    val count = modes.count()
-                    val args: MutableMap<String, Any> = HashMap()
-                    args["count"] = count
-                    if (count >= 1) {
-                        args["mode"] = modes[0].name
+                    zenModeInteractor.modesHidingNotifications.map { modes ->
+                        // Create a string that is either "No notifications" if no modes are
+                        // filtering
+                        // them out, or something like "Notifications paused by SomeMode" otherwise.
+                        val msgFormat =
+                            MessageFormat(
+                                context.getString(R.string.modes_suppressing_shade_text),
+                                Locale.getDefault(),
+                            )
+                        val count = modes.count()
+                        val args: MutableMap<String, Any> = HashMap()
+                        args["count"] = count
+                        if (count >= 1) {
+                            args["mode"] = modes[0].name
+                        }
+                        msgFormat.format(args)
                     }
-                    msgFormat.format(args)
-                }
-            } else {
-                areNotificationsHiddenInShade.map { areNotificationsHiddenInShade ->
-                    if (areNotificationsHiddenInShade) {
-                        context.getString(R.string.dnd_suppressing_shade_text)
-                    } else {
-                        context.getString(R.string.empty_shade_text)
+                } else {
+                    areNotificationsHiddenInShade.map { areNotificationsHiddenInShade ->
+                        if (areNotificationsHiddenInShade) {
+                            context.getString(R.string.dnd_suppressing_shade_text)
+                        } else {
+                            context.getString(R.string.empty_shade_text)
+                        }
                     }
                 }
-            }
+                .flowOn(bgDispatcher)
         }
     }
 
@@ -120,23 +130,24 @@
     val onClick: Flow<SettingsIntent> by lazy {
         ModesEmptyShadeFix.assertInNewMode()
         combine(
-            zenModeInteractor.modesHidingNotifications,
-            notificationSettingsInteractor.isNotificationHistoryEnabled,
-        ) { modes, isNotificationHistoryEnabled ->
-            if (modes.isNotEmpty()) {
-                if (modes.size == 1) {
-                    SettingsIntent.forModeSettings(modes[0].id)
+                zenModeInteractor.modesHidingNotifications,
+                notificationSettingsInteractor.isNotificationHistoryEnabled,
+            ) { modes, isNotificationHistoryEnabled ->
+                if (modes.isNotEmpty()) {
+                    if (modes.size == 1) {
+                        SettingsIntent.forModeSettings(modes[0].id)
+                    } else {
+                        SettingsIntent.forModesSettings()
+                    }
                 } else {
-                    SettingsIntent.forModesSettings()
-                }
-            } else {
-                if (isNotificationHistoryEnabled) {
-                    SettingsIntent.forNotificationHistory()
-                } else {
-                    SettingsIntent.forNotificationSettings()
+                    if (isNotificationHistoryEnabled) {
+                        SettingsIntent.forNotificationHistory()
+                    } else {
+                        SettingsIntent.forNotificationSettings()
+                    }
                 }
             }
-        }
+            .flowOn(bgDispatcher)
     }
 
     @AssistedFactory
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelKosmos.kt
index 8fdb948..ca33a86 100644
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelKosmos.kt
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelKosmos.kt
@@ -19,6 +19,7 @@
 import android.content.applicationContext
 import com.android.systemui.dump.dumpManager
 import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.testDispatcher
 import com.android.systemui.shared.notifications.domain.interactor.notificationSettingsInteractor
 import com.android.systemui.statusbar.notification.domain.interactor.seenNotificationsInteractor
 import com.android.systemui.statusbar.policy.domain.interactor.zenModeInteractor
@@ -30,6 +31,7 @@
             zenModeInteractor,
             seenNotificationsInteractor,
             notificationSettingsInteractor,
+            testDispatcher,
             dumpManager,
         )
     }