Fix notifications undo system (2/2)
Adjust so NotficationSettingsRepository in frameworks/base emits the
show notifications boolean in a suspend function, after it is retrieved
from SecureSettingsRepository, instead of returning a default value
immediately.
Flag: EXEMPT bug fix
Bug: 326440143
Test: manually verified notifications toggle sets and resets correctly
Test: manually verified reset button shows and hides correctly
Test: existing notifications unit tests pass
Test: new ThemePicker test NotificationsSnapshotRestorerTest
Change-Id: If580a54fdb920a6a17f7c605caf5359a868f0ec0
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepository.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepository.kt
index e39d7ed..9e857deb 100644
--- a/packages/SystemUI/customization/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepository.kt
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepository.kt
@@ -21,16 +21,16 @@
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.withContext
/** Provides access to state related to notification settings. */
class NotificationSettingsRepository(
- scope: CoroutineScope,
+ private val scope: CoroutineScope,
private val backgroundDispatcher: CoroutineDispatcher,
private val secureSettingsRepository: SecureSettingsRepository,
) {
@@ -41,16 +41,15 @@
.distinctUntilChanged()
/** The current state of the notification setting. */
- val isShowNotificationsOnLockScreenEnabled: StateFlow<Boolean> =
+ suspend fun isShowNotificationsOnLockScreenEnabled(): StateFlow<Boolean> =
secureSettingsRepository
.intSetting(
name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
)
.map { it == 1 }
+ .flowOn(backgroundDispatcher)
.stateIn(
scope = scope,
- started = SharingStarted.WhileSubscribed(),
- initialValue = false,
)
suspend fun setShowNotificationsOnLockscreenEnabled(enabled: Boolean) {
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/notifications/domain/interactor/NotificationSettingsInteractor.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/notifications/domain/interactor/NotificationSettingsInteractor.kt
index 04e8090..b4105bd 100644
--- a/packages/SystemUI/customization/src/com/android/systemui/shared/notifications/domain/interactor/NotificationSettingsInteractor.kt
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/notifications/domain/interactor/NotificationSettingsInteractor.kt
@@ -26,8 +26,8 @@
val isNotificationHistoryEnabled = repository.isNotificationHistoryEnabled
/** Should notifications be visible on the lockscreen? */
- val isShowNotificationsOnLockScreenEnabled: StateFlow<Boolean> =
- repository.isShowNotificationsOnLockScreenEnabled
+ suspend fun isShowNotificationsOnLockScreenEnabled(): StateFlow<Boolean> =
+ repository.isShowNotificationsOnLockScreenEnabled()
suspend fun setShowNotificationsOnLockscreenEnabled(enabled: Boolean) {
repository.setShowNotificationsOnLockscreenEnabled(enabled)
@@ -35,7 +35,7 @@
/** Toggles the setting to show or hide notifications on the lock screen. */
suspend fun toggleShowNotificationsOnLockscreenEnabled() {
- val current = repository.isShowNotificationsOnLockScreenEnabled.value
+ val current = repository.isShowNotificationsOnLockScreenEnabled().value
repository.setShowNotificationsOnLockscreenEnabled(!current)
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryTest.kt
index 0dd988d..40f7b7fb 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/shared/notifications/data/repository/NotificationSettingsRepositoryTest.kt
@@ -56,7 +56,7 @@
@Test
fun testGetIsShowNotificationsOnLockscreenEnabled() =
testScope.runTest {
- val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled)
+ val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled())
secureSettingsRepository.setInt(
name = Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS,
@@ -74,7 +74,7 @@
@Test
fun testSetIsShowNotificationsOnLockscreenEnabled() =
testScope.runTest {
- val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled)
+ val showNotifs by collectLastValue(underTest.isShowNotificationsOnLockScreenEnabled())
underTest.setShowNotificationsOnLockscreenEnabled(true)
assertThat(showNotifs).isEqualTo(true)