Properly support multi-user in NotificationSettingsRepository
(And also in every place that injected SecureSettingsRepository / SystemSettingsRepository).
This also:
* adds some methods to UserAwareSecureSettingsRepository (via the base class) and their tests.
* removes the UserAwareSecureSettingsRepository interface/impl/fake split.
* adds a UserAwareSystemSettingsRepository (same base class, but interacting with SystemSettings instead of SecureSettings).
Bug: 356099784
Test: manual, as described in b/356099784
Flag: com.android.systemui.user_aware_settings_repositories
Change-Id: Ic8d759de9cc93e59ae279ecce0c818b1f3d200e3
diff --git a/packages/SystemUI/aconfig/systemui.aconfig b/packages/SystemUI/aconfig/systemui.aconfig
index 83b7566..13c22d0 100644
--- a/packages/SystemUI/aconfig/systemui.aconfig
+++ b/packages/SystemUI/aconfig/systemui.aconfig
@@ -1508,6 +1508,16 @@
}
flag {
+ namespace: "systemui"
+ name: "user_aware_settings_repositories"
+ description: "Provide user-aware versions of SecureSettingsRepository and SystemSettingsRepository in SystemUI modules (see doc linked from b/356099784)."
+ bug: "356099784"
+ metadata {
+ purpose: PURPOSE_BUGFIX
+ }
+}
+
+flag {
name: "notify_password_text_view_user_activity_in_background"
namespace: "systemui"
description: "Decide whether to notify the user activity in password text view, to power manager in the background thread."
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SecureSettingsRepository.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SecureSettingsRepository.kt
index 2a87452..ae18aac 100644
--- a/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SecureSettingsRepository.kt
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SecureSettingsRepository.kt
@@ -16,102 +16,19 @@
package com.android.systemui.shared.settings.data.repository
-import android.content.ContentResolver
-import android.database.ContentObserver
import android.provider.Settings
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.callbackFlow
-import kotlinx.coroutines.flow.flowOn
-import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.withContext
-/**
- * Defines interface for classes that can provide access to data from [Settings.Secure].
- * This repository doesn't guarantee to provide value across different users. For that
- * see: [UserAwareSecureSettingsRepository]
- */
+/** Defines interface for classes that can provide access to data from [Settings.Secure]. */
interface SecureSettingsRepository {
/** Returns a [Flow] tracking the value of a setting as an [Int]. */
- fun intSetting(
- name: String,
- defaultValue: Int = 0,
- ): Flow<Int>
+ fun intSetting(name: String, defaultValue: Int = 0): Flow<Int>
/** Updates the value of the setting with the given name. */
- suspend fun setInt(
- name: String,
- value: Int,
- )
+ suspend fun setInt(name: String, value: Int)
- suspend fun getInt(
- name: String,
- defaultValue: Int = 0,
- ): Int
+ suspend fun getInt(name: String, defaultValue: Int = 0): Int
suspend fun getString(name: String): String?
}
-
-class SecureSettingsRepositoryImpl(
- private val contentResolver: ContentResolver,
- private val backgroundDispatcher: CoroutineDispatcher,
-) : SecureSettingsRepository {
-
- override fun intSetting(
- name: String,
- defaultValue: Int,
- ): Flow<Int> {
- return callbackFlow {
- val observer =
- object : ContentObserver(null) {
- override fun onChange(selfChange: Boolean) {
- trySend(Unit)
- }
- }
-
- contentResolver.registerContentObserver(
- Settings.Secure.getUriFor(name),
- /* notifyForDescendants= */ false,
- observer,
- )
- send(Unit)
-
- awaitClose { contentResolver.unregisterContentObserver(observer) }
- }
- .map { Settings.Secure.getInt(contentResolver, name, defaultValue) }
- // The above work is done on the background thread (which is important for accessing
- // settings through the content resolver).
- .flowOn(backgroundDispatcher)
- }
-
- override suspend fun setInt(name: String, value: Int) {
- withContext(backgroundDispatcher) {
- Settings.Secure.putInt(
- contentResolver,
- name,
- value,
- )
- }
- }
-
- override suspend fun getInt(name: String, defaultValue: Int): Int {
- return withContext(backgroundDispatcher) {
- Settings.Secure.getInt(
- contentResolver,
- name,
- defaultValue,
- )
- }
- }
-
- override suspend fun getString(name: String): String? {
- return withContext(backgroundDispatcher) {
- Settings.Secure.getString(
- contentResolver,
- name,
- )
- }
- }
-}
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SecureSettingsRepositoryImpl.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SecureSettingsRepositoryImpl.kt
new file mode 100644
index 0000000..8b9fcb4
--- /dev/null
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SecureSettingsRepositoryImpl.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.shared.settings.data.repository
+
+import android.content.ContentResolver
+import android.database.ContentObserver
+import android.provider.Settings
+import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.channels.awaitClose
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.callbackFlow
+import kotlinx.coroutines.flow.flowOn
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.withContext
+
+/**
+ * Simple implementation of [SecureSettingsRepository].
+ *
+ * This repository doesn't guarantee to provide value across different users, and therefore
+ * shouldn't be used in SystemUI. For that see: [UserAwareSecureSettingsRepository]
+ */
+// TODO: b/377244768 - Move to Theme/WallpaperPicker, away from SystemUI.
+class SecureSettingsRepositoryImpl(
+ private val contentResolver: ContentResolver,
+ private val backgroundDispatcher: CoroutineDispatcher,
+) : SecureSettingsRepository {
+
+ override fun intSetting(name: String, defaultValue: Int): Flow<Int> {
+ return callbackFlow {
+ val observer =
+ object : ContentObserver(null) {
+ override fun onChange(selfChange: Boolean) {
+ trySend(Unit)
+ }
+ }
+
+ contentResolver.registerContentObserver(
+ Settings.Secure.getUriFor(name),
+ /* notifyForDescendants= */ false,
+ observer,
+ )
+ send(Unit)
+
+ awaitClose { contentResolver.unregisterContentObserver(observer) }
+ }
+ .map { Settings.Secure.getInt(contentResolver, name, defaultValue) }
+ // The above work is done on the background thread (which is important for accessing
+ // settings through the content resolver).
+ .flowOn(backgroundDispatcher)
+ }
+
+ override suspend fun setInt(name: String, value: Int) {
+ withContext(backgroundDispatcher) { Settings.Secure.putInt(contentResolver, name, value) }
+ }
+
+ override suspend fun getInt(name: String, defaultValue: Int): Int {
+ return withContext(backgroundDispatcher) {
+ Settings.Secure.getInt(contentResolver, name, defaultValue)
+ }
+ }
+
+ override suspend fun getString(name: String): String? {
+ return withContext(backgroundDispatcher) {
+ Settings.Secure.getString(contentResolver, name)
+ }
+ }
+}
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SystemSettingsRepository.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SystemSettingsRepository.kt
index afe82fb..8cda9b3 100644
--- a/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SystemSettingsRepository.kt
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SystemSettingsRepository.kt
@@ -16,102 +16,19 @@
package com.android.systemui.shared.settings.data.repository
-import android.content.ContentResolver
-import android.database.ContentObserver
import android.provider.Settings
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.callbackFlow
-import kotlinx.coroutines.flow.flowOn
-import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.withContext
-/**
- * Defines interface for classes that can provide access to data from [Settings.System]. This
- * repository doesn't guarantee to provide value across different users. For that see:
- * [UserAwareSecureSettingsRepository] which does that for secure settings.
- */
+/** Interface for classes that can provide access to data from [Settings.System]. */
interface SystemSettingsRepository {
/** Returns a [Flow] tracking the value of a setting as an [Int]. */
- fun intSetting(
- name: String,
- defaultValue: Int = 0,
- ): Flow<Int>
+ fun intSetting(name: String, defaultValue: Int = 0): Flow<Int>
/** Updates the value of the setting with the given name. */
- suspend fun setInt(
- name: String,
- value: Int,
- )
+ suspend fun setInt(name: String, value: Int)
- suspend fun getInt(
- name: String,
- defaultValue: Int = 0,
- ): Int
+ suspend fun getInt(name: String, defaultValue: Int = 0): Int
suspend fun getString(name: String): String?
}
-
-class SystemSettingsRepositoryImpl(
- private val contentResolver: ContentResolver,
- private val backgroundDispatcher: CoroutineDispatcher,
-) : SystemSettingsRepository {
-
- override fun intSetting(
- name: String,
- defaultValue: Int,
- ): Flow<Int> {
- return callbackFlow {
- val observer =
- object : ContentObserver(null) {
- override fun onChange(selfChange: Boolean) {
- trySend(Unit)
- }
- }
-
- contentResolver.registerContentObserver(
- Settings.System.getUriFor(name),
- /* notifyForDescendants= */ false,
- observer,
- )
- send(Unit)
-
- awaitClose { contentResolver.unregisterContentObserver(observer) }
- }
- .map { Settings.System.getInt(contentResolver, name, defaultValue) }
- // The above work is done on the background thread (which is important for accessing
- // settings through the content resolver).
- .flowOn(backgroundDispatcher)
- }
-
- override suspend fun setInt(name: String, value: Int) {
- withContext(backgroundDispatcher) {
- Settings.System.putInt(
- contentResolver,
- name,
- value,
- )
- }
- }
-
- override suspend fun getInt(name: String, defaultValue: Int): Int {
- return withContext(backgroundDispatcher) {
- Settings.System.getInt(
- contentResolver,
- name,
- defaultValue,
- )
- }
- }
-
- override suspend fun getString(name: String): String? {
- return withContext(backgroundDispatcher) {
- Settings.System.getString(
- contentResolver,
- name,
- )
- }
- }
-}
diff --git a/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SystemSettingsRepositoryImpl.kt b/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SystemSettingsRepositoryImpl.kt
new file mode 100644
index 0000000..b039a32
--- /dev/null
+++ b/packages/SystemUI/customization/src/com/android/systemui/shared/settings/data/repository/SystemSettingsRepositoryImpl.kt
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.shared.settings.data.repository
+
+import android.content.ContentResolver
+import android.database.ContentObserver
+import android.provider.Settings
+import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.channels.awaitClose
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.callbackFlow
+import kotlinx.coroutines.flow.flowOn
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.withContext
+
+/**
+ * Defines interface for classes that can provide access to data from [Settings.System].
+ *
+ * This repository doesn't guarantee to provide value across different users. For that see:
+ * [UserAwareSystemSettingsRepository].
+ */
+// TODO: b/377244768 - Move to Theme/WallpaperPicker, away from SystemUI.
+class SystemSettingsRepositoryImpl(
+ private val contentResolver: ContentResolver,
+ private val backgroundDispatcher: CoroutineDispatcher,
+) : SystemSettingsRepository {
+
+ override fun intSetting(name: String, defaultValue: Int): Flow<Int> {
+ return callbackFlow {
+ val observer =
+ object : ContentObserver(null) {
+ override fun onChange(selfChange: Boolean) {
+ trySend(Unit)
+ }
+ }
+
+ contentResolver.registerContentObserver(
+ Settings.System.getUriFor(name),
+ /* notifyForDescendants= */ false,
+ observer,
+ )
+ send(Unit)
+
+ awaitClose { contentResolver.unregisterContentObserver(observer) }
+ }
+ .map { Settings.System.getInt(contentResolver, name, defaultValue) }
+ // The above work is done on the background thread (which is important for accessing
+ // settings through the content resolver).
+ .flowOn(backgroundDispatcher)
+ }
+
+ override suspend fun setInt(name: String, value: Int) {
+ withContext(backgroundDispatcher) { Settings.System.putInt(contentResolver, name, value) }
+ }
+
+ override suspend fun getInt(name: String, defaultValue: Int): Int {
+ return withContext(backgroundDispatcher) {
+ Settings.System.getInt(contentResolver, name, defaultValue)
+ }
+ }
+
+ override suspend fun getString(name: String): String? {
+ return withContext(backgroundDispatcher) {
+ Settings.System.getString(contentResolver, name)
+ }
+ }
+}
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/stickykeys/ui/viewmodel/StickyKeysIndicatorViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/stickykeys/ui/viewmodel/StickyKeysIndicatorViewModelTest.kt
index 26ce67d..7ec53df 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/stickykeys/ui/viewmodel/StickyKeysIndicatorViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/stickykeys/ui/viewmodel/StickyKeysIndicatorViewModelTest.kt
@@ -40,8 +40,8 @@
import com.android.systemui.user.data.repository.fakeUserRepository
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.mock
+import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository
import com.android.systemui.util.settings.fakeSettings
-import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepositoryImpl
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
@@ -72,14 +72,13 @@
@Before
fun setup() {
- val settingsRepository =
- UserAwareSecureSettingsRepositoryImpl(secureSettings, userRepository, dispatcher)
+ val settingsRepository = kosmos.userAwareSecureSettingsRepository
val stickyKeysRepository =
StickyKeysRepositoryImpl(
inputManager,
dispatcher,
settingsRepository,
- mock<StickyKeysLogger>()
+ mock<StickyKeysLogger>(),
)
setStickyKeySetting(enabled = false)
viewModel =
@@ -114,7 +113,7 @@
verify(inputManager)
.registerStickyModifierStateListener(
any(),
- any(InputManager.StickyModifierStateListener::class.java)
+ any(InputManager.StickyModifierStateListener::class.java),
)
}
}
@@ -187,11 +186,7 @@
assertThat(stickyKeys)
.isEqualTo(
- mapOf(
- ALT to Locked(false),
- META to Locked(false),
- SHIFT to Locked(false),
- )
+ mapOf(ALT to Locked(false), META to Locked(false), SHIFT to Locked(false))
)
}
}
@@ -218,7 +213,7 @@
mapOf(
META to false,
SHIFT to false, // shift is sticky but not locked
- CTRL to false
+ CTRL to false,
)
)
val previousShiftIndex = stickyKeys?.toList()?.indexOf(SHIFT to Locked(false))
@@ -228,7 +223,7 @@
SHIFT to false,
SHIFT to true, // shift is now locked
META to false,
- CTRL to false
+ CTRL to false,
)
)
assertThat(stickyKeys?.toList()?.indexOf(SHIFT to Locked(true)))
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/util/settings/repository/UserAwareSecureSettingsRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/util/settings/repository/UserAwareSecureSettingsRepositoryTest.kt
index a0cfab4d..e88dbd2 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/util/settings/repository/UserAwareSecureSettingsRepositoryTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/util/settings/repository/UserAwareSecureSettingsRepositoryTest.kt
@@ -22,11 +22,10 @@
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
-import com.android.systemui.kosmos.Kosmos
-import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.user.data.repository.fakeUserRepository
+import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository
import com.android.systemui.util.settings.fakeSettings
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -42,70 +41,127 @@
class UserAwareSecureSettingsRepositoryTest : SysuiTestCase() {
private val kosmos = testKosmos()
- private val dispatcher = kosmos.testDispatcher
private val testScope = kosmos.testScope
private val secureSettings = kosmos.fakeSettings
- private val userRepository = Kosmos().fakeUserRepository
- private lateinit var repository: UserAwareSecureSettingsRepository
+ private val userRepository = kosmos.fakeUserRepository
+ private lateinit var underTest: UserAwareSecureSettingsRepository
@Before
fun setup() {
- repository =
- UserAwareSecureSettingsRepositoryImpl(
- secureSettings,
- userRepository,
- dispatcher,
- )
+ underTest = kosmos.userAwareSecureSettingsRepository
+
userRepository.setUserInfos(USER_INFOS)
- setSettingValueForUser(enabled = true, userInfo = SETTING_ENABLED_USER)
- setSettingValueForUser(enabled = false, userInfo = SETTING_DISABLED_USER)
+
+ secureSettings.putBoolForUser(BOOL_SETTING_NAME, true, USER_1.id)
+ secureSettings.putBoolForUser(BOOL_SETTING_NAME, false, USER_2.id)
+ secureSettings.putIntForUser(INT_SETTING_NAME, 1337, USER_1.id)
+ secureSettings.putIntForUser(INT_SETTING_NAME, 818, USER_2.id)
}
@Test
- fun settingEnabledEmitsValueForCurrentUser() {
+ fun boolSetting_emitsInitialValue() {
testScope.runTest {
- userRepository.setSelectedUserInfo(SETTING_ENABLED_USER)
+ userRepository.setSelectedUserInfo(USER_1)
- val enabled by collectLastValue(repository.boolSettingForActiveUser(SETTING_NAME))
+ val enabled by collectLastValue(underTest.boolSetting(BOOL_SETTING_NAME, false))
assertThat(enabled).isTrue()
}
}
@Test
- fun settingEnabledEmitsNewValueWhenSettingChanges() {
+ fun boolSetting_whenSettingChanges_emitsNewValue() {
testScope.runTest {
- userRepository.setSelectedUserInfo(SETTING_ENABLED_USER)
- val enabled by collectValues(repository.boolSettingForActiveUser(SETTING_NAME))
+ userRepository.setSelectedUserInfo(USER_1)
+ val enabled by collectValues(underTest.boolSetting(BOOL_SETTING_NAME, false))
runCurrent()
- setSettingValueForUser(enabled = false, userInfo = SETTING_ENABLED_USER)
+ secureSettings.putBoolForUser(BOOL_SETTING_NAME, false, USER_1.id)
assertThat(enabled).containsExactly(true, false).inOrder()
}
}
@Test
- fun settingEnabledEmitsValueForNewUserWhenUserChanges() {
+ fun boolSetting_whenWhenUserChanges_emitsNewValue() {
testScope.runTest {
- userRepository.setSelectedUserInfo(SETTING_ENABLED_USER)
- val enabled by collectLastValue(repository.boolSettingForActiveUser(SETTING_NAME))
+ userRepository.setSelectedUserInfo(USER_1)
+ val enabled by collectLastValue(underTest.boolSetting(BOOL_SETTING_NAME, false))
runCurrent()
- userRepository.setSelectedUserInfo(SETTING_DISABLED_USER)
+ userRepository.setSelectedUserInfo(USER_2)
assertThat(enabled).isFalse()
}
}
- private fun setSettingValueForUser(enabled: Boolean, userInfo: UserInfo) {
- secureSettings.putBoolForUser(SETTING_NAME, enabled, userInfo.id)
+ @Test
+ fun intSetting_emitsInitialValue() {
+ testScope.runTest {
+ userRepository.setSelectedUserInfo(USER_1)
+
+ val number by collectLastValue(underTest.intSetting(INT_SETTING_NAME, 0))
+
+ assertThat(number).isEqualTo(1337)
+ }
}
+ @Test
+ fun intSetting_whenSettingChanges_emitsNewValue() {
+ testScope.runTest {
+ userRepository.setSelectedUserInfo(USER_1)
+ val number by collectValues(underTest.intSetting(INT_SETTING_NAME, 0))
+ runCurrent()
+
+ secureSettings.putIntForUser(INT_SETTING_NAME, 1338, USER_1.id)
+
+ assertThat(number).containsExactly(1337, 1338).inOrder()
+ }
+ }
+
+ @Test
+ fun intSetting_whenWhenUserChanges_emitsNewValue() {
+ testScope.runTest {
+ userRepository.setSelectedUserInfo(USER_1)
+ val number by collectLastValue(underTest.intSetting(INT_SETTING_NAME, 0))
+ runCurrent()
+
+ userRepository.setSelectedUserInfo(USER_2)
+
+ assertThat(number).isEqualTo(818)
+ }
+ }
+
+ @Test
+ fun getInt_returnsInitialValue() =
+ testScope.runTest {
+ userRepository.setSelectedUserInfo(USER_1)
+
+ assertThat(underTest.getInt(INT_SETTING_NAME, 0)).isEqualTo(1337)
+ }
+
+ @Test
+ fun getInt_whenSettingChanges_returnsNewValue() =
+ testScope.runTest {
+ userRepository.setSelectedUserInfo(USER_1)
+ secureSettings.putIntForUser(INT_SETTING_NAME, 999, USER_1.id)
+
+ assertThat(underTest.getInt(INT_SETTING_NAME, 0)).isEqualTo(999)
+ }
+
+ @Test
+ fun getInt_whenUserChanges_returnsThatUserValue() =
+ testScope.runTest {
+ userRepository.setSelectedUserInfo(USER_2)
+
+ assertThat(underTest.getInt(INT_SETTING_NAME, 0)).isEqualTo(818)
+ }
+
private companion object {
- const val SETTING_NAME = "SETTING_NAME"
- val SETTING_ENABLED_USER = UserInfo(/* id= */ 0, "user1", /* flags= */ 0)
- val SETTING_DISABLED_USER = UserInfo(/* id= */ 1, "user2", /* flags= */ 0)
- val USER_INFOS = listOf(SETTING_ENABLED_USER, SETTING_DISABLED_USER)
+ const val BOOL_SETTING_NAME = "BOOL_SETTING_NAME"
+ const val INT_SETTING_NAME = "INT_SETTING_NAME"
+ val USER_1 = UserInfo(/* id= */ 0, "user1", /* flags= */ 0)
+ val USER_2 = UserInfo(/* id= */ 1, "user2", /* flags= */ 0)
+ val USER_INFOS = listOf(USER_1, USER_2)
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/stickykeys/data/repository/StickyKeysRepository.kt b/packages/SystemUI/src/com/android/systemui/keyboard/stickykeys/data/repository/StickyKeysRepository.kt
index 89cdd25..585f7ed 100644
--- a/packages/SystemUI/src/com/android/systemui/keyboard/stickykeys/data/repository/StickyKeysRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyboard/stickykeys/data/repository/StickyKeysRepository.kt
@@ -33,13 +33,13 @@
import com.android.systemui.keyboard.stickykeys.shared.model.ModifierKey.META
import com.android.systemui.keyboard.stickykeys.shared.model.ModifierKey.SHIFT
import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepository
+import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
-import javax.inject.Inject
interface StickyKeysRepository {
val stickyKeys: Flow<LinkedHashMap<ModifierKey, Locked>>
@@ -71,7 +71,7 @@
override val settingEnabled: Flow<Boolean> =
secureSettingsRepository
- .boolSettingForActiveUser(SETTING_KEY, defaultValue = false)
+ .boolSetting(SETTING_KEY, defaultValue = false)
.onEach { stickyKeysLogger.logNewSettingValue(it) }
.flowOn(backgroundDispatcher)
diff --git a/packages/SystemUI/src/com/android/systemui/settings/SecureSettingsRepositoryModule.kt b/packages/SystemUI/src/com/android/systemui/settings/SecureSettingsRepositoryModule.kt
deleted file mode 100644
index 6199a83..0000000
--- a/packages/SystemUI/src/com/android/systemui/settings/SecureSettingsRepositoryModule.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.settings
-
-import android.content.ContentResolver
-import com.android.systemui.dagger.SysUISingleton
-import com.android.systemui.dagger.qualifiers.Background
-import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository
-import com.android.systemui.shared.settings.data.repository.SecureSettingsRepositoryImpl
-import dagger.Module
-import dagger.Provides
-import kotlinx.coroutines.CoroutineDispatcher
-
-@Module
-object SecureSettingsRepositoryModule {
- @JvmStatic
- @Provides
- @SysUISingleton
- fun provideSecureSettingsRepository(
- contentResolver: ContentResolver,
- @Background backgroundDispatcher: CoroutineDispatcher,
- ): SecureSettingsRepository =
- SecureSettingsRepositoryImpl(contentResolver, backgroundDispatcher)
-}
diff --git a/packages/SystemUI/src/com/android/systemui/settings/SystemSettingsRepositoryModule.kt b/packages/SystemUI/src/com/android/systemui/settings/SystemSettingsRepositoryModule.kt
deleted file mode 100644
index 02ce74a..0000000
--- a/packages/SystemUI/src/com/android/systemui/settings/SystemSettingsRepositoryModule.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.settings
-
-import android.content.ContentResolver
-import com.android.systemui.dagger.SysUISingleton
-import com.android.systemui.dagger.qualifiers.Background
-import com.android.systemui.shared.settings.data.repository.SystemSettingsRepository
-import com.android.systemui.shared.settings.data.repository.SystemSettingsRepositoryImpl
-import dagger.Module
-import dagger.Provides
-import kotlinx.coroutines.CoroutineDispatcher
-
-@Module
-object SystemSettingsRepositoryModule {
- @JvmStatic
- @Provides
- @SysUISingleton
- fun provideSystemSettingsRepository(
- contentResolver: ContentResolver,
- @Background backgroundDispatcher: CoroutineDispatcher,
- ): SystemSettingsRepository =
- SystemSettingsRepositoryImpl(contentResolver, backgroundDispatcher)
-}
diff --git a/packages/SystemUI/src/com/android/systemui/settings/UserSettingsRepositoryModule.kt b/packages/SystemUI/src/com/android/systemui/settings/UserSettingsRepositoryModule.kt
new file mode 100644
index 0000000..3d7b2ea
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/settings/UserSettingsRepositoryModule.kt
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.settings
+
+import android.content.ContentResolver
+import com.android.systemui.Flags
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Background
+import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository
+import com.android.systemui.shared.settings.data.repository.SecureSettingsRepositoryImpl
+import com.android.systemui.shared.settings.data.repository.SystemSettingsRepository
+import com.android.systemui.shared.settings.data.repository.SystemSettingsRepositoryImpl
+import com.android.systemui.user.data.repository.UserRepository
+import com.android.systemui.util.settings.SecureSettings
+import com.android.systemui.util.settings.SystemSettings
+import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepository
+import com.android.systemui.util.settings.repository.UserAwareSystemSettingsRepository
+import dagger.Lazy
+import dagger.Module
+import dagger.Provides
+import kotlin.coroutines.CoroutineContext
+import kotlinx.coroutines.CoroutineDispatcher
+
+@Module
+object UserSettingsRepositoryModule {
+ @JvmStatic
+ @Provides
+ @SysUISingleton
+ fun provideSecureSettingsRepository(
+ secureSettings: Lazy<SecureSettings>,
+ userRepository: Lazy<UserRepository>,
+ contentResolver: Lazy<ContentResolver>,
+ @Background backgroundDispatcher: CoroutineDispatcher,
+ @Background backgroundContext: CoroutineContext,
+ ): SecureSettingsRepository {
+ return if (Flags.userAwareSettingsRepositories()) {
+ UserAwareSecureSettingsRepository(
+ secureSettings.get(),
+ userRepository.get(),
+ backgroundDispatcher,
+ backgroundContext,
+ )
+ } else {
+ SecureSettingsRepositoryImpl(contentResolver.get(), backgroundDispatcher)
+ }
+ }
+
+ @JvmStatic
+ @Provides
+ @SysUISingleton
+ fun provideSystemSettingsRepository(
+ systemSettings: Lazy<SystemSettings>,
+ userRepository: Lazy<UserRepository>,
+ contentResolver: Lazy<ContentResolver>,
+ @Background backgroundDispatcher: CoroutineDispatcher,
+ @Background backgroundContext: CoroutineContext,
+ ): SystemSettingsRepository {
+ return if (Flags.userAwareSettingsRepositories()) {
+ UserAwareSystemSettingsRepository(
+ systemSettings.get(),
+ userRepository.get(),
+ backgroundDispatcher,
+ backgroundContext,
+ )
+ } else {
+ SystemSettingsRepositoryImpl(contentResolver.get(), backgroundDispatcher)
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/data/NotificationSettingsRepositoryModule.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/data/NotificationSettingsRepositoryModule.kt
index 7d374b0..dbe5833 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/data/NotificationSettingsRepositoryModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/data/NotificationSettingsRepositoryModule.kt
@@ -16,12 +16,12 @@
package com.android.systemui.statusbar.notification.data
+import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.systemui.CoreStartable
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
-import com.android.systemui.settings.SecureSettingsRepositoryModule
-import com.android.systemui.settings.SystemSettingsRepositoryModule
+import com.android.systemui.settings.UserSettingsRepositoryModule
import com.android.systemui.shared.notifications.data.repository.NotificationSettingsRepository
import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository
import com.android.systemui.shared.settings.data.repository.SystemSettingsRepository
@@ -32,9 +32,8 @@
import dagger.multibindings.IntoMap
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
-import com.android.app.tracing.coroutines.launchTraced as launch
-@Module(includes = [SecureSettingsRepositoryModule::class, SystemSettingsRepositoryModule::class])
+@Module(includes = [UserSettingsRepositoryModule::class])
object NotificationSettingsRepositoryModule {
@Provides
@SysUISingleton
@@ -48,7 +47,8 @@
backgroundScope,
backgroundDispatcher,
secureSettingsRepository,
- systemSettingsRepository)
+ systemSettingsRepository,
+ )
@Provides
@IntoMap
@@ -57,7 +57,7 @@
fun provideCoreStartable(
@Application applicationScope: CoroutineScope,
repository: NotificationSettingsRepository,
- logger: VisualInterruptionDecisionLogger
+ logger: VisualInterruptionDecisionLogger,
) = CoreStartable {
applicationScope.launch {
repository.isCooldownEnabled.collect { value -> logger.logCooldownSetting(value) }
diff --git a/packages/SystemUI/src/com/android/systemui/util/settings/SettingsUtilModule.java b/packages/SystemUI/src/com/android/systemui/util/settings/SettingsUtilModule.java
index d509b2d..f36c335e 100644
--- a/packages/SystemUI/src/com/android/systemui/util/settings/SettingsUtilModule.java
+++ b/packages/SystemUI/src/com/android/systemui/util/settings/SettingsUtilModule.java
@@ -16,9 +16,6 @@
package com.android.systemui.util.settings;
-import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepository;
-import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepositoryImpl;
-
import dagger.Binds;
import dagger.Module;
@@ -39,9 +36,4 @@
/** Bind GlobalSettingsImpl to GlobalSettings. */
@Binds
GlobalSettings bindsGlobalSettings(GlobalSettingsImpl impl);
-
- /** Bind UserAwareSecureSettingsRepositoryImpl to UserAwareSecureSettingsRepository. */
- @Binds
- UserAwareSecureSettingsRepository bindsUserAwareSecureSettingsRepository(
- UserAwareSecureSettingsRepositoryImpl impl);
}
diff --git a/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSecureSettingsRepository.kt b/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSecureSettingsRepository.kt
index d3e5080..71335ec 100644
--- a/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSecureSettingsRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSecureSettingsRepository.kt
@@ -19,52 +19,25 @@
import android.provider.Settings
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
+import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository
import com.android.systemui.user.data.repository.UserRepository
import com.android.systemui.util.settings.SecureSettings
-import com.android.systemui.util.settings.SettingsProxy
-import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.distinctUntilChanged
-import kotlinx.coroutines.flow.flatMapLatest
-import kotlinx.coroutines.flow.flowOn
-import kotlinx.coroutines.flow.map
-import kotlinx.coroutines.flow.onStart
import javax.inject.Inject
+import kotlin.coroutines.CoroutineContext
+import kotlinx.coroutines.CoroutineDispatcher
/**
* Repository for observing values of [Settings.Secure] for the currently active user. That means
* when user is switched and the new user has different value, flow will emit new value.
*/
-interface UserAwareSecureSettingsRepository {
-
- /**
- * Emits boolean value of the setting for active user. Also emits starting value when
- * subscribed.
- * See: [SettingsProxy.getBool].
- */
- fun boolSettingForActiveUser(name: String, defaultValue: Boolean = false): Flow<Boolean>
-}
-
@SysUISingleton
-@OptIn(ExperimentalCoroutinesApi::class)
-class UserAwareSecureSettingsRepositoryImpl @Inject constructor(
- private val secureSettings: SecureSettings,
- private val userRepository: UserRepository,
- @Background private val backgroundDispatcher: CoroutineDispatcher,
-) : UserAwareSecureSettingsRepository {
-
- override fun boolSettingForActiveUser(name: String, defaultValue: Boolean): Flow<Boolean> =
- userRepository.selectedUserInfo
- .flatMapLatest { userInfo -> settingObserver(name, defaultValue, userInfo.id) }
- .distinctUntilChanged()
- .flowOn(backgroundDispatcher)
-
- private fun settingObserver(name: String, defaultValue: Boolean, userId: Int): Flow<Boolean> {
- return secureSettings
- .observerFlow(userId, name)
- .onStart { emit(Unit) }
- .map { secureSettings.getBoolForUser(name, defaultValue, userId) }
- }
-}
\ No newline at end of file
+class UserAwareSecureSettingsRepository
+@Inject
+constructor(
+ secureSettings: SecureSettings,
+ userRepository: UserRepository,
+ @Background backgroundDispatcher: CoroutineDispatcher,
+ @Background bgContext: CoroutineContext,
+) :
+ UserAwareSettingsRepository(secureSettings, userRepository, backgroundDispatcher, bgContext),
+ SecureSettingsRepository
diff --git a/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSettingsRepository.kt b/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSettingsRepository.kt
new file mode 100644
index 0000000..a31b8d9
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSettingsRepository.kt
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.util.settings.repository
+
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Background
+import com.android.systemui.user.data.repository.UserRepository
+import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
+import com.android.systemui.util.settings.UserSettingsProxy
+import kotlin.coroutines.CoroutineContext
+import kotlinx.coroutines.CoroutineDispatcher
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.flow.Flow
+import kotlinx.coroutines.flow.distinctUntilChanged
+import kotlinx.coroutines.flow.flatMapLatest
+import kotlinx.coroutines.flow.flowOn
+import kotlinx.coroutines.flow.map
+import kotlinx.coroutines.flow.onStart
+import kotlinx.coroutines.withContext
+
+/**
+ * Repository for observing values of a [UserSettingsProxy], for the currently active user. That
+ * means that when user is switched and the new user has a different value, the flow will emit the
+ * new value.
+ */
+@SysUISingleton
+@OptIn(ExperimentalCoroutinesApi::class)
+abstract class UserAwareSettingsRepository(
+ private val userSettings: UserSettingsProxy,
+ private val userRepository: UserRepository,
+ @Background private val backgroundDispatcher: CoroutineDispatcher,
+ @Background private val bgContext: CoroutineContext,
+) {
+
+ fun boolSetting(name: String, defaultValue: Boolean): Flow<Boolean> =
+ userRepository.selectedUserInfo
+ .flatMapLatest { userInfo ->
+ settingObserver(name, userInfo.id) {
+ userSettings.getBoolForUser(name, defaultValue, userInfo.id)
+ }
+ }
+ .distinctUntilChanged()
+ .flowOn(backgroundDispatcher)
+
+ fun intSetting(name: String, defaultValue: Int): Flow<Int> {
+ return userRepository.selectedUserInfo
+ .flatMapLatest { userInfo ->
+ settingObserver(name, userInfo.id) {
+ userSettings.getIntForUser(name, defaultValue, userInfo.id)
+ }
+ }
+ .distinctUntilChanged()
+ .flowOn(backgroundDispatcher)
+ }
+
+ private fun <T> settingObserver(name: String, userId: Int, settingsReader: () -> T): Flow<T> {
+ return userSettings
+ .observerFlow(userId, name)
+ .onStart { emit(Unit) }
+ .map { settingsReader.invoke() }
+ }
+
+ suspend fun setInt(name: String, value: Int) {
+ withContext(bgContext) {
+ userSettings.putIntForUser(name, value, userRepository.getSelectedUserInfo().id)
+ }
+ }
+
+ suspend fun getInt(name: String, defaultValue: Int): Int {
+ return withContext(bgContext) {
+ userSettings.getIntForUser(name, defaultValue, userRepository.getSelectedUserInfo().id)
+ }
+ }
+
+ suspend fun getString(name: String): String? {
+ return withContext(bgContext) {
+ userSettings.getStringForUser(name, userRepository.getSelectedUserInfo().id)
+ }
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSystemSettingsRepository.kt b/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSystemSettingsRepository.kt
new file mode 100644
index 0000000..8b1fca5
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/util/settings/repository/UserAwareSystemSettingsRepository.kt
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.util.settings.repository
+
+import android.provider.Settings
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.dagger.qualifiers.Background
+import com.android.systemui.shared.settings.data.repository.SystemSettingsRepository
+import com.android.systemui.user.data.repository.UserRepository
+import com.android.systemui.util.settings.SystemSettings
+import javax.inject.Inject
+import kotlin.coroutines.CoroutineContext
+import kotlinx.coroutines.CoroutineDispatcher
+
+/**
+ * Repository for observing values of [Settings.Secure] for the currently active user. That means
+ * when user is switched and the new user has different value, flow will emit new value.
+ */
+@SysUISingleton
+class UserAwareSystemSettingsRepository
+@Inject
+constructor(
+ systemSettings: SystemSettings,
+ userRepository: UserRepository,
+ @Background backgroundDispatcher: CoroutineDispatcher,
+ @Background bgContext: CoroutineContext,
+) :
+ UserAwareSettingsRepository(systemSettings, userRepository, backgroundDispatcher, bgContext),
+ SystemSettingsRepository
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeUserAwareSecureSettingsRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeUserAwareSecureSettingsRepository.kt
deleted file mode 100644
index 5054e29..0000000
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/FakeUserAwareSecureSettingsRepository.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.util.settings
-
-import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepository
-import kotlinx.coroutines.flow.Flow
-import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.flow.map
-
-class FakeUserAwareSecureSettingsRepository : UserAwareSecureSettingsRepository {
-
- private val settings = MutableStateFlow<Map<String, Boolean>>(mutableMapOf())
-
- override fun boolSettingForActiveUser(name: String, defaultValue: Boolean): Flow<Boolean> {
- return settings.map { it.getOrDefault(name, defaultValue) }
- }
-
- fun setBoolSettingForActiveUser(name: String, value: Boolean) {
- settings.value = settings.value.toMutableMap().apply { this[name] = value }
- }
-}
\ No newline at end of file
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/UserAwareSecureSettingsRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/UserAwareSecureSettingsRepositoryKosmos.kt
deleted file mode 100644
index 94b2bdf..0000000
--- a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/UserAwareSecureSettingsRepositoryKosmos.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2024 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.systemui.util.settings
-
-import com.android.systemui.kosmos.Kosmos
-
-val Kosmos.userAwareSecureSettingsRepository by
- Kosmos.Fixture { FakeUserAwareSecureSettingsRepository() }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/data/repository/UserAwareSecureSettingsRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/data/repository/UserAwareSecureSettingsRepositoryKosmos.kt
new file mode 100644
index 0000000..dc10ca9
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/data/repository/UserAwareSecureSettingsRepositoryKosmos.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.util.settings.data.repository
+
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.backgroundCoroutineContext
+import com.android.systemui.kosmos.testDispatcher
+import com.android.systemui.user.data.repository.userRepository
+import com.android.systemui.util.settings.fakeSettings
+import com.android.systemui.util.settings.repository.UserAwareSecureSettingsRepository
+
+val Kosmos.userAwareSecureSettingsRepository by
+ Kosmos.Fixture {
+ UserAwareSecureSettingsRepository(
+ fakeSettings,
+ userRepository,
+ testDispatcher,
+ backgroundCoroutineContext,
+ )
+ }
diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/data/repository/UserAwareSystemSettingsRepositoryKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/data/repository/UserAwareSystemSettingsRepositoryKosmos.kt
new file mode 100644
index 0000000..ff77908
--- /dev/null
+++ b/packages/SystemUI/tests/utils/src/com/android/systemui/util/settings/data/repository/UserAwareSystemSettingsRepositoryKosmos.kt
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.util.settings.data.repository
+
+import com.android.systemui.kosmos.Kosmos
+import com.android.systemui.kosmos.backgroundCoroutineContext
+import com.android.systemui.kosmos.testDispatcher
+import com.android.systemui.user.data.repository.userRepository
+import com.android.systemui.util.settings.fakeSettings
+import com.android.systemui.util.settings.repository.UserAwareSystemSettingsRepository
+
+val Kosmos.userAwareSystemSettingsRepository by
+ Kosmos.Fixture {
+ UserAwareSystemSettingsRepository(
+ fakeSettings,
+ userRepository,
+ testDispatcher,
+ backgroundCoroutineContext,
+ )
+ }