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

Commit 5b685ed0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Further cleanup of SecureSettingsRepository & friends" into main

parents 6f4e52ff 0a048d5e
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