summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ioana Alexandru <aioana@google.com> 2025-01-29 00:49:25 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2025-01-29 00:49:25 -0800
commitb5b48bf83bd2e295e5e889802d0f81cab27bb7be (patch)
treedd4ea16e77d684e3be137c2c3e5f96aa45a5d2d9
parenta64892c55ceb98486a300df2bba903ca0ddbd85b (diff)
parent7c425e66a8f6e078fa0c3b4194fd872b9925ec8b (diff)
Merge "Fix empty shade string not updating on locale change" into main
-rw-r--r--packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt52
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModel.kt21
-rw-r--r--packages/SystemUI/tests/utils/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelKosmos.kt2
3 files changed, 71 insertions, 4 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt
index 9a42f5b02395..163ae47ad78a 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/emptyshade/ui/viewmodel/EmptyShadeViewModelTest.kt
@@ -18,6 +18,8 @@ package com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel
import android.app.Flags
import android.app.NotificationManager.Policy
+import android.content.res.Configuration
+import android.os.LocaleList
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
@@ -27,6 +29,7 @@ import androidx.test.filters.SmallTest
import com.android.settingslib.notification.data.repository.updateNotificationPolicy
import com.android.settingslib.notification.modes.TestModeBuilder
import com.android.systemui.SysuiTestCase
+import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.kosmos.testScope
@@ -36,9 +39,12 @@ import com.android.systemui.statusbar.notification.emptyshade.shared.ModesEmptyS
import com.android.systemui.statusbar.policy.data.repository.zenModeRepository
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
+import java.util.Locale
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
+import org.junit.After
+import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
@@ -53,6 +59,10 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
private val zenModeRepository = kosmos.zenModeRepository
private val activeNotificationListRepository = kosmos.activeNotificationListRepository
private val fakeSecureSettingsRepository = kosmos.fakeSecureSettingsRepository
+ private val fakeConfigurationRepository = kosmos.fakeConfigurationRepository
+
+ /** Backup of the current locales, to be restored at the end of the test if they are changed. */
+ private lateinit var originalLocales: LocaleList
private val underTest by lazy { kosmos.emptyShadeViewModel }
@@ -68,6 +78,18 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
mSetFlagsRule.setFlagsParameterization(flags)
}
+ @Before
+ fun setUp() {
+ originalLocales = context.resources.configuration.locales
+ updateLocales(LocaleList(Locale.US))
+ }
+
+ @After
+ fun tearDown() {
+ // Make sure we restore the original locale even if a test fails after changing it
+ updateLocales(originalLocales)
+ }
+
@Test
fun areNotificationsHiddenInShade_true() =
testScope.runTest {
@@ -144,6 +166,29 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
@Test
@EnableFlags(ModesEmptyShadeFix.FLAG_NAME, Flags.FLAG_MODES_UI, Flags.FLAG_MODES_API)
+ fun text_changesWhenLocaleChanges() =
+ testScope.runTest {
+ val text by collectLastValue(underTest.text)
+
+ zenModeRepository.updateNotificationPolicy(
+ suppressedVisualEffects = Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST
+ )
+ zenModeRepository.updateZenMode(Settings.Global.ZEN_MODE_OFF)
+ runCurrent()
+
+ assertThat(text).isEqualTo("No notifications")
+
+ updateLocales(LocaleList(Locale.GERMAN))
+ runCurrent()
+
+ assertThat(text).isEqualTo("Keine Benachrichtigungen")
+
+ // Make sure we restore the original locales
+ updateLocales(originalLocales)
+ }
+
+ @Test
+ @EnableFlags(ModesEmptyShadeFix.FLAG_NAME, Flags.FLAG_MODES_UI, Flags.FLAG_MODES_API)
fun text_reflectsModesHidingNotifications() =
testScope.runTest {
val text by collectLastValue(underTest.text)
@@ -285,4 +330,11 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
assertThat(onClick?.targetIntent?.action).isEqualTo(Settings.ACTION_ZEN_MODE_SETTINGS)
assertThat(onClick?.backStack).isEmpty()
}
+
+ private fun updateLocales(locales: LocaleList) {
+ val configuration = Configuration()
+ configuration.setLocales(locales)
+ context.resources.updateConfiguration(configuration, context.resources.displayMetrics)
+ fakeConfigurationRepository.onConfigurationChange(configuration)
+ }
}
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 7e2361f24da9..fa0cea15c43f 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,7 @@ package com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel
import android.content.Context
import android.icu.text.MessageFormat
+import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dump.DumpManager
import com.android.systemui.modes.shared.ModesUi
@@ -36,9 +37,11 @@ import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.onStart
/**
* ViewModel for the empty shade (aka the "No notifications" text shown when there are no
@@ -51,6 +54,7 @@ constructor(
zenModeInteractor: ZenModeInteractor,
seenNotificationsInteractor: SeenNotificationsInteractor,
notificationSettingsInteractor: NotificationSettingsInteractor,
+ configurationInteractor: ConfigurationInteractor,
@Background bgDispatcher: CoroutineDispatcher,
dumpManager: DumpManager,
) : FlowDumperImpl(dumpManager) {
@@ -71,6 +75,13 @@ constructor(
"hasFilteredOutSeenNotifications"
)
+ private val primaryLocale by lazy {
+ configurationInteractor.configurationValues
+ .map { it.locales.get(0) ?: Locale.getDefault() }
+ .onStart { emit(Locale.getDefault()) }
+ .distinctUntilChanged()
+ }
+
val text: Flow<String> by lazy {
if (ModesEmptyShadeFix.isUnexpectedlyInLegacyMode()) {
flowOf(context.getString(R.string.empty_shade_text))
@@ -79,14 +90,16 @@ constructor(
// 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 ->
+ combine(zenModeInteractor.modesHidingNotifications, primaryLocale) {
+ modes,
+ locale ->
// Create a string that is either "No notifications" if no modes are
- // filtering
- // them out, or something like "Notifications paused by SomeMode" otherwise.
+ // filtering them out, or something like "Notifications paused by SomeMode"
+ // otherwise.
val msgFormat =
MessageFormat(
context.getString(R.string.modes_suppressing_shade_text),
- Locale.getDefault(),
+ locale,
)
val count = modes.count()
val args: MutableMap<String, Any> = HashMap()
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 ca33a8663a51..f679fa4fafb6 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
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel
import android.content.applicationContext
+import com.android.systemui.common.ui.domain.interactor.configurationInteractor
import com.android.systemui.dump.dumpManager
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testDispatcher
@@ -31,6 +32,7 @@ val Kosmos.emptyShadeViewModel by
zenModeInteractor,
seenNotificationsInteractor,
notificationSettingsInteractor,
+ configurationInteractor,
testDispatcher,
dumpManager,
)