Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a048d5e authored by Matías Hernández's avatar Matías Hernández
Browse files

Further cleanup of SecureSettingsRepository & friends

* Add a boolSetting() method to Secure/SystemSettingsRepository so that they can be used as a drop-in replacement in places that today inject the UserAware variants.
* Add unit tests for both concrete implementations of UserAwareSettingsRepository.

Bug: 356099784
Test: atest UserAwareSystemSettingsRepositoryTest
Flag: com.android.systemui.user_aware_settings_repositories
Change-Id: I904853ddac85b4040730560fb88de92dbed8f14d
parent 0087eef2
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ interface SecureSettingsRepository {
    /** Returns a [Flow] tracking the value of a setting as an [Int]. */
    fun intSetting(name: String, defaultValue: Int = 0): Flow<Int>

    /** Returns a [Flow] tracking the value of a setting as a [Boolean]. */
    fun boolSetting(name: String, defaultValue: Boolean = false): Flow<Boolean>

    /** Updates the value of the setting with the given name. */
    suspend fun setInt(name: String, value: Int)

+4 −0
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ class SecureSettingsRepositoryImpl(
            .flowOn(backgroundDispatcher)
    }

    override fun boolSetting(name: String, defaultValue: Boolean): Flow<Boolean> {
        return intSetting(name, if (defaultValue) 1 else 0).map { it != 0 }
    }

    override suspend fun setInt(name: String, value: Int) {
        withContext(backgroundDispatcher) { Settings.Secure.putInt(contentResolver, name, value) }
    }
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,9 @@ interface SystemSettingsRepository {
    /** Returns a [Flow] tracking the value of a setting as an [Int]. */
    fun intSetting(name: String, defaultValue: Int = 0): Flow<Int>

    /** Returns a [Flow] tracking the value of a setting as a [Boolean]. */
    fun boolSetting(name: String, defaultValue: Boolean = false): Flow<Boolean>

    /** Updates the value of the setting with the given name. */
    suspend fun setInt(name: String, value: Int)

+4 −0
Original line number Diff line number Diff line
@@ -63,6 +63,10 @@ class SystemSettingsRepositoryImpl(
            .flowOn(backgroundDispatcher)
    }

    override fun boolSetting(name: String, defaultValue: Boolean): Flow<Boolean> {
        return intSetting(name, if (defaultValue) 1 else 0).map { it != 0 }
    }

    override suspend fun setInt(name: String, value: Int) {
        withContext(backgroundDispatcher) { Settings.System.putInt(contentResolver, name, value) }
    }
+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,10 @@ class FakeSecureSettingsRepository : SecureSettingsRepository {
        return settings.map { it.getOrDefault(name, defaultValue.toString()) }.map { it.toInt() }
    }

    override fun boolSetting(name: String, defaultValue: Boolean): Flow<Boolean> {
        return intSetting(name, if (defaultValue) 1 else 0).map { it != 0 }
    }

    override suspend fun setInt(name: String, value: Int) {
        settings.value = settings.value.toMutableMap().apply { this[name] = value.toString() }
    }
Loading