Don't include "app state" preferences in backups

This commit is contained in:
arkon
2023-10-29 12:24:02 -04:00
parent 1aa5222c99
commit ce7bf396eb
9 changed files with 100 additions and 28 deletions

View File

@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.core.security
import eu.kanade.tachiyomi.core.R
import tachiyomi.core.preference.Preference
import tachiyomi.core.preference.PreferenceStore
import tachiyomi.core.preference.getEnum
@ -20,7 +21,10 @@ class SecurityPreferences(
* For app lock. Will be set when there is a pending timed lock.
* Otherwise this pref should be deleted.
*/
fun lastAppClosed() = preferenceStore.getLong("last_app_closed", 0)
fun lastAppClosed() = preferenceStore.getLong(
Preference.appStateKey("last_app_closed"),
0,
)
enum class SecureScreenMode(val titleResId: Int) {
ALWAYS(R.string.lock_always),

View File

@ -22,21 +22,29 @@ interface Preference<T> {
fun stateIn(scope: CoroutineScope): StateFlow<T>
val isPrivate: Boolean
get() = key().startsWith(PRIVATE_PREFIX)
companion object {
/**
* A preference that should not be exposed in places like backups.
* A preference that should not be exposed in places like backups without user consent.
*/
fun isPrivate(key: String): Boolean {
return key.startsWith(PRIVATE_PREFIX)
}
fun privateKey(key: String): String {
return "${PRIVATE_PREFIX}$key"
}
/**
* A preference used for internal app state that isn't really a user preference
* and therefore should not be inplaces like backips.
*/
fun isAppState(key: String): Boolean {
return key.startsWith(APP_STATE_PREFIX)
}
fun appStateKey(key: String): String {
return "${APP_STATE_PREFIX}$key"
}
private const val APP_STATE_PREFIX = "__APP_STATE_"
private const val PRIVATE_PREFIX = "__PRIVATE_"
}
}