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

Commit 59fa415f authored by Jacky Wang's avatar Jacky Wang
Browse files

Add common APIs for settings datastore

Bug: 325144964
Flag: EXEMPT Add API
Test: N/A
Change-Id: Iec2687f4222d18e582319d73f21a0d77303cab3a
parent 6dcdf8bc
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -99,6 +99,37 @@ abstract class SettingsStore(protected val contentResolver: ContentResolver) :
        contentResolver.unregisterContentObserver(contentObserver)
    }

    /** Gets the boolean value of given key. */
    fun getBoolean(key: String): Boolean? = getValue(key, Boolean::class.javaObjectType)

    /** Sets boolean value for given key, null value means delete the key from data store. */
    fun setBoolean(key: String, value: Boolean?) =
        setValue(key, Boolean::class.javaObjectType, value)

    /** Gets the float value of given key. */
    fun getFloat(key: String): Float? = getValue(key, Float::class.javaObjectType)

    /** Sets float value for given key, null value means delete the key from data store. */
    fun setFloat(key: String, value: Float?) = setValue(key, Float::class.javaObjectType, value)

    /** Gets the int value of given key. */
    fun getInt(key: String): Int? = getValue(key, Int::class.javaObjectType)

    /** Sets int value for given key, null value means delete the key from data store. */
    fun setInt(key: String, value: Int?) = setValue(key, Int::class.javaObjectType, value)

    /** Gets the long value of given key. */
    fun getLong(key: String): Long? = getValue(key, Long::class.javaObjectType)

    /** Sets long value for given key, null value means delete the key from data store. */
    fun setLong(key: String, value: Long?) = setValue(key, Long::class.javaObjectType, value)

    /** Gets the string value of given key. */
    fun getString(key: String): String? = getValue(key, String::class.javaObjectType)

    /** Sets string value for given key, null value means delete the key from data store. */
    fun setString(key: String, value: String?) = setValue(key, String::class.javaObjectType, value)

    /** Tag for logging. */
    abstract val tag: String
}