Split security preferences from PrefrencesHelper (#8030)

(cherry picked from commit b668364afbfdde9e91fda6621c80c96262c6492a)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateNotifier.kt
#	app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceValues.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt
This commit is contained in:
Andreas 2022-09-18 19:07:48 +02:00 committed by Jobobby04
parent bffecf3833
commit f40477cf6e
16 changed files with 92 additions and 72 deletions

View File

@ -19,6 +19,7 @@ import eu.kanade.data.listOfStringsAndAdapter
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore
import eu.kanade.tachiyomi.core.preference.PreferenceStore import eu.kanade.tachiyomi.core.preference.PreferenceStore
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.cache.CoverCache
import eu.kanade.tachiyomi.data.cache.PagePreviewCache import eu.kanade.tachiyomi.data.cache.PagePreviewCache
@ -169,6 +170,9 @@ class PreferenceModule(val application: Application) : InjektModule {
addSingletonFactory { addSingletonFactory {
SourcePreferences(get()) SourcePreferences(get())
} }
addSingletonFactory {
SecurityPreferences(get())
}
addSingletonFactory { addSingletonFactory {
PreferencesHelper( PreferencesHelper(
context = application, context = application,

View File

@ -5,6 +5,7 @@ import android.os.Build
import androidx.core.content.edit import androidx.core.content.edit
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED import eu.kanade.tachiyomi.data.preference.MANGA_NON_COMPLETED
@ -41,6 +42,7 @@ object Migrations {
preferences: PreferencesHelper, preferences: PreferencesHelper,
networkPreferences: NetworkPreferences, networkPreferences: NetworkPreferences,
sourcePreferences: SourcePreferences, sourcePreferences: SourcePreferences,
securityPreferences: SecurityPreferences,
): Boolean { ): Boolean {
val oldVersion = preferences.lastVersionCode().get() val oldVersion = preferences.lastVersionCode().get()
if (oldVersion < BuildConfig.VERSION_CODE) { if (oldVersion < BuildConfig.VERSION_CODE) {
@ -257,7 +259,7 @@ object Migrations {
if (oldVersion < 75) { if (oldVersion < 75) {
val oldSecureScreen = prefs.getBoolean("secure_screen", false) val oldSecureScreen = prefs.getBoolean("secure_screen", false)
if (oldSecureScreen) { if (oldSecureScreen) {
preferences.secureScreen().set(PreferenceValues.SecureScreenMode.ALWAYS) securityPreferences.secureScreen().set(SecurityPreferences.SecureScreenMode.ALWAYS)
} }
if (DeviceUtil.isMiui && preferences.extensionInstaller().get() == PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER) { if (DeviceUtil.isMiui && preferences.extensionInstaller().get() == PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER) {
preferences.extensionInstaller().set(PreferenceValues.ExtensionInstaller.LEGACY) preferences.extensionInstaller().set(PreferenceValues.ExtensionInstaller.LEGACY)

View File

@ -5,9 +5,9 @@ import android.graphics.BitmapFactory
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import com.hippo.unifile.UniFile import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.storage.getUriCompat import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.system.notificationManager
@ -17,7 +17,7 @@ import java.util.concurrent.TimeUnit
class BackupNotifier(private val context: Context) { class BackupNotifier(private val context: Context) {
private val preferences: PreferencesHelper by injectLazy() private val preferences: SecurityPreferences by injectLazy()
private val progressNotificationBuilder = context.notificationBuilder(Notifications.CHANNEL_BACKUP_RESTORE_PROGRESS) { private val progressNotificationBuilder = context.notificationBuilder(Notifications.CHANNEL_BACKUP_RESTORE_PROGRESS) {
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher)) setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))

View File

@ -5,11 +5,11 @@ import android.content.Context
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.data.notification.NotificationHandler import eu.kanade.tachiyomi.data.notification.NotificationHandler
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.util.lang.chop import eu.kanade.tachiyomi.util.lang.chop
import eu.kanade.tachiyomi.util.system.notificationBuilder import eu.kanade.tachiyomi.util.system.notificationBuilder
import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.system.notificationManager
@ -23,7 +23,7 @@ import java.util.regex.Pattern
*/ */
internal class DownloadNotifier(private val context: Context) { internal class DownloadNotifier(private val context: Context) {
private val preferences: PreferencesHelper by injectLazy() private val preferences: SecurityPreferences by injectLazy()
private val progressNotificationBuilder by lazy { private val progressNotificationBuilder by lazy {
context.notificationBuilder(Notifications.CHANNEL_DOWNLOADER_PROGRESS) { context.notificationBuilder(Notifications.CHANNEL_DOWNLOADER_PROGRESS) {

View File

@ -16,11 +16,11 @@ import coil.transform.CircleCropTransformation
import eu.kanade.domain.chapter.model.Chapter import eu.kanade.domain.chapter.model.Chapter
import eu.kanade.domain.manga.model.Manga import eu.kanade.domain.manga.model.Manga
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.download.Downloader import eu.kanade.tachiyomi.data.download.Downloader
import eu.kanade.tachiyomi.data.notification.NotificationHandler import eu.kanade.tachiyomi.data.notification.NotificationHandler
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.util.lang.chop import eu.kanade.tachiyomi.util.lang.chop
@ -34,7 +34,7 @@ import java.text.DecimalFormatSymbols
class LibraryUpdateNotifier(private val context: Context) { class LibraryUpdateNotifier(private val context: Context) {
private val preferences: PreferencesHelper by injectLazy() private val preferences: SecurityPreferences by injectLazy()
/** /**
* Pending intent of action that cancels the library update * Pending intent of action that cancels the library update

View File

@ -39,8 +39,6 @@ object PreferenceKeys {
const val librarySortingMode = "library_sorting_mode" const val librarySortingMode = "library_sorting_mode"
const val hideNotificationContent = "hide_notification_content"
const val autoUpdateMetadata = "auto_update_metadata" const val autoUpdateMetadata = "auto_update_metadata"
const val autoUpdateTrackers = "auto_update_trackers" const val autoUpdateTrackers = "auto_update_trackers"

View File

@ -79,12 +79,6 @@ object PreferenceValues {
SHIZUKU(R.string.ext_installer_shizuku), SHIZUKU(R.string.ext_installer_shizuku),
} }
enum class SecureScreenMode(val titleResId: Int) {
ALWAYS(R.string.lock_always),
INCOGNITO(R.string.pref_incognito_mode),
NEVER(R.string.lock_never),
}
// SY --> // SY -->
enum class GroupLibraryMode { enum class GroupLibraryMode {
GLOBAL, GLOBAL,

View File

@ -49,20 +49,6 @@ class PreferencesHelper(
fun sideNavIconAlignment() = this.preferenceStore.getInt("pref_side_nav_icon_alignment", 0) fun sideNavIconAlignment() = this.preferenceStore.getInt("pref_side_nav_icon_alignment", 0)
fun useAuthenticator() = this.preferenceStore.getBoolean("use_biometric_lock", false)
fun lockAppAfter() = this.preferenceStore.getInt("lock_app_after", 0)
/**
* For app lock. Will be set when there is a pending timed lock.
* Otherwise this pref should be deleted.
*/
fun lastAppClosed() = this.preferenceStore.getLong("last_app_closed", 0)
fun secureScreen() = this.preferenceStore.getEnum("secure_screen_v2", Values.SecureScreenMode.INCOGNITO)
fun hideNotificationContent() = this.preferenceStore.getBoolean(Keys.hideNotificationContent, false)
fun autoUpdateMetadata() = this.preferenceStore.getBoolean(Keys.autoUpdateMetadata, false) fun autoUpdateMetadata() = this.preferenceStore.getBoolean(Keys.autoUpdateMetadata, false)
fun autoUpdateTrackers() = this.preferenceStore.getBoolean(Keys.autoUpdateTrackers, false) fun autoUpdateTrackers() = this.preferenceStore.getBoolean(Keys.autoUpdateTrackers, false)
@ -439,10 +425,6 @@ class PreferencesHelper(
fun allowLocalSourceHiddenFolders() = this.preferenceStore.getBoolean("allow_local_source_hidden_folders", false) fun allowLocalSourceHiddenFolders() = this.preferenceStore.getBoolean("allow_local_source_hidden_folders", false)
fun authenticatorTimeRanges() = this.preferenceStore.getStringSet("biometric_time_ranges", mutableSetOf())
fun authenticatorDays() = this.preferenceStore.getInt("biometric_days", 0x7F)
fun sortTagsForLibrary() = this.preferenceStore.getStringSet("sort_tags_for_library", mutableSetOf()) fun sortTagsForLibrary() = this.preferenceStore.getStringSet("sort_tags_for_library", mutableSetOf())
fun extensionRepos() = this.preferenceStore.getStringSet("extension_repos", emptySet()) fun extensionRepos() = this.preferenceStore.getStringSet("extension_repos", emptySet())

View File

@ -46,7 +46,7 @@ import coil.transform.RoundedCornersTransformation
import eu.kanade.data.DatabaseHandler import eu.kanade.data.DatabaseHandler
import eu.kanade.domain.manga.model.MangaCover import eu.kanade.domain.manga.model.MangaCover
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
@ -61,7 +61,7 @@ import java.util.Date
class UpdatesGridGlanceWidget : GlanceAppWidget() { class UpdatesGridGlanceWidget : GlanceAppWidget() {
private val app: Application by injectLazy() private val app: Application by injectLazy()
private val preferences: PreferencesHelper by injectLazy() private val preferences: SecurityPreferences by injectLazy()
private val coroutineScope = MainScope() private val coroutineScope = MainScope()

View File

@ -5,7 +5,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate.Companion.LOCK_ALL_DAYS import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate.Companion.LOCK_ALL_DAYS
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate.Companion.LOCK_FRIDAY import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate.Companion.LOCK_FRIDAY
@ -47,7 +47,7 @@ interface SecureActivityDelegate {
// SY <-- // SY <--
fun onApplicationCreated() { fun onApplicationCreated() {
val lockDelay = Injekt.get<PreferencesHelper>().lockAppAfter().get() val lockDelay = Injekt.get<SecurityPreferences>().lockAppAfter().get()
if (lockDelay == 0) { if (lockDelay == 0) {
// Restore always active app lock // Restore always active app lock
// Delayed lock will be restored later on activity resume // Delayed lock will be restored later on activity resume
@ -56,7 +56,7 @@ interface SecureActivityDelegate {
} }
fun onApplicationStopped() { fun onApplicationStopped() {
val preferences = Injekt.get<PreferencesHelper>() val preferences = Injekt.get<SecurityPreferences>()
if (!preferences.useAuthenticator().get()) return if (!preferences.useAuthenticator().get()) return
if (lockState != LockState.ACTIVE) { if (lockState != LockState.ACTIVE) {
preferences.lastAppClosed().set(Date().time) preferences.lastAppClosed().set(Date().time)
@ -72,7 +72,7 @@ interface SecureActivityDelegate {
fun unlock() { fun unlock() {
lockState = LockState.INACTIVE lockState = LockState.INACTIVE
Injekt.get<PreferencesHelper>().lastAppClosed().delete() Injekt.get<SecurityPreferences>().lastAppClosed().delete()
} }
} }
} }
@ -90,6 +90,7 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser
private lateinit var activity: AppCompatActivity private lateinit var activity: AppCompatActivity
private val preferences: PreferencesHelper by injectLazy() private val preferences: PreferencesHelper by injectLazy()
private val securityPreferences: SecurityPreferences by injectLazy()
override fun registerSecureActivity(activity: AppCompatActivity) { override fun registerSecureActivity(activity: AppCompatActivity) {
this.activity = activity this.activity = activity
@ -105,31 +106,31 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser
} }
private fun setSecureScreen() { private fun setSecureScreen() {
val secureScreenFlow = preferences.secureScreen().changes() val secureScreenFlow = securityPreferences.secureScreen().changes()
val incognitoModeFlow = preferences.incognitoMode().changes() val incognitoModeFlow = preferences.incognitoMode().changes()
combine(secureScreenFlow, incognitoModeFlow) { secureScreen, incognitoMode -> combine(secureScreenFlow, incognitoModeFlow) { secureScreen, incognitoMode ->
secureScreen == PreferenceValues.SecureScreenMode.ALWAYS || secureScreen == SecurityPreferences.SecureScreenMode.ALWAYS ||
secureScreen == PreferenceValues.SecureScreenMode.INCOGNITO && incognitoMode secureScreen == SecurityPreferences.SecureScreenMode.INCOGNITO && incognitoMode
} }
.onEach { activity.window.setSecureScreen(it) } .onEach { activity.window.setSecureScreen(it) }
.launchIn(activity.lifecycleScope) .launchIn(activity.lifecycleScope)
} }
private fun setAppLock() { private fun setAppLock() {
if (!preferences.useAuthenticator().get()) return if (!securityPreferences.useAuthenticator().get()) return
if (activity.isAuthenticationSupported()) { if (activity.isAuthenticationSupported()) {
updatePendingLockStatus() updatePendingLockStatus()
if (!isAppLocked()) return if (!isAppLocked()) return
activity.startActivity(Intent(activity, UnlockActivity::class.java)) activity.startActivity(Intent(activity, UnlockActivity::class.java))
activity.overridePendingTransition(0, 0) activity.overridePendingTransition(0, 0)
} else { } else {
preferences.useAuthenticator().set(false) securityPreferences.useAuthenticator().set(false)
} }
} }
private fun updatePendingLockStatus() { private fun updatePendingLockStatus() {
val lastClosedPref = preferences.lastAppClosed() val lastClosedPref = securityPreferences.lastAppClosed()
val lockDelay = 60000 * preferences.lockAppAfter().get() val lockDelay = 60000 * securityPreferences.lockAppAfter().get()
if (lastClosedPref.isSet() && lockDelay > 0) { if (lastClosedPref.isSet() && lockDelay > 0) {
// Restore pending status in case app was killed // Restore pending status in case app was killed
lockState = LockState.PENDING lockState = LockState.PENDING
@ -146,7 +147,7 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser
private fun isAppLocked(): Boolean { private fun isAppLocked(): Boolean {
// SY --> // SY -->
val today: Calendar = Calendar.getInstance() val today: Calendar = Calendar.getInstance()
val timeRanges = preferences.authenticatorTimeRanges().get() val timeRanges = securityPreferences.authenticatorTimeRanges().get()
.mapNotNull { TimeRange.fromPreferenceString(it) } .mapNotNull { TimeRange.fromPreferenceString(it) }
if (timeRanges.isNotEmpty()) { if (timeRanges.isNotEmpty()) {
val now = today.get(Calendar.HOUR_OF_DAY).hours + today.get(Calendar.MINUTE).minutes val now = today.get(Calendar.HOUR_OF_DAY).hours + today.get(Calendar.MINUTE).minutes
@ -156,7 +157,7 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser
} }
} }
val lockedDays = preferences.authenticatorDays().get() val lockedDays = securityPreferences.authenticatorDays().get()
val lockedToday = lockedDays == LOCK_ALL_DAYS || when (today.get(Calendar.DAY_OF_WEEK)) { val lockedToday = lockedDays == LOCK_ALL_DAYS || when (today.get(Calendar.DAY_OF_WEEK)) {
Calendar.SUNDAY -> (lockedDays and LOCK_SUNDAY) == LOCK_SUNDAY Calendar.SUNDAY -> (lockedDays and LOCK_SUNDAY) == LOCK_SUNDAY
Calendar.MONDAY -> (lockedDays and LOCK_MONDAY) == LOCK_MONDAY Calendar.MONDAY -> (lockedDays and LOCK_MONDAY) == LOCK_MONDAY

View File

@ -4,7 +4,7 @@ import android.app.Application
import android.os.Bundle import android.os.Bundle
import eu.kanade.presentation.category.BiometricTimesState import eu.kanade.presentation.category.BiometricTimesState
import eu.kanade.presentation.category.BiometricTimesStateImpl import eu.kanade.presentation.category.BiometricTimesStateImpl
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.preference.plusAssign import eu.kanade.tachiyomi.util.preference.plusAssign
@ -19,10 +19,9 @@ import uy.kohesive.injekt.api.get
*/ */
class BiometricTimesPresenter( class BiometricTimesPresenter(
private val state: BiometricTimesStateImpl = BiometricTimesState() as BiometricTimesStateImpl, private val state: BiometricTimesStateImpl = BiometricTimesState() as BiometricTimesStateImpl,
private val preferences: SecurityPreferences = Injekt.get(),
) : BasePresenter<BiometricTimesController>(), BiometricTimesState by state { ) : BasePresenter<BiometricTimesController>(), BiometricTimesState by state {
val preferences: PreferencesHelper = Injekt.get()
private val _events: Channel<Event> = Channel(Int.MAX_VALUE) private val _events: Channel<Event> = Channel(Int.MAX_VALUE)
val events = _events.consumeAsFlow() val events = _events.consumeAsFlow()

View File

@ -143,6 +143,7 @@ class MainActivity : BaseActivity() {
preferences = preferences, preferences = preferences,
networkPreferences = Injekt.get(), networkPreferences = Injekt.get(),
sourcePreferences = sourcePreferences, sourcePreferences = sourcePreferences,
securityPreferences = Injekt.get(),
) )
} else { } else {
false false

View File

@ -8,14 +8,12 @@ import androidx.preference.Preference
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.controller.pushController import eu.kanade.tachiyomi.ui.base.controller.pushController
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate
import eu.kanade.tachiyomi.ui.category.biometric.BiometricTimesController import eu.kanade.tachiyomi.ui.category.biometric.BiometricTimesController
import eu.kanade.tachiyomi.util.preference.bindTo import eu.kanade.tachiyomi.util.preference.bindTo
import eu.kanade.tachiyomi.util.preference.defaultValue
import eu.kanade.tachiyomi.util.preference.entriesRes import eu.kanade.tachiyomi.util.preference.entriesRes
import eu.kanade.tachiyomi.util.preference.infoPreference import eu.kanade.tachiyomi.util.preference.infoPreference
import eu.kanade.tachiyomi.util.preference.intListPreference import eu.kanade.tachiyomi.util.preference.intListPreference
@ -31,16 +29,17 @@ import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupport
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.startAuthentication import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.startAuthentication
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
class SettingsSecurityController : SettingsController() { class SettingsSecurityController : SettingsController() {
private val securityPreferences: SecurityPreferences by injectLazy()
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.pref_category_security titleRes = R.string.pref_category_security
if (context.isAuthenticationSupported()) { if (context.isAuthenticationSupported()) {
switchPreference { switchPreference {
bindTo(preferences.useAuthenticator()) bindTo(securityPreferences.useAuthenticator())
titleRes = R.string.lock_with_biometrics titleRes = R.string.lock_with_biometrics
requireAuthentication( requireAuthentication(
@ -51,7 +50,7 @@ class SettingsSecurityController : SettingsController() {
} }
intListPreference { intListPreference {
bindTo(preferences.lockAppAfter()) bindTo(securityPreferences.lockAppAfter())
titleRes = R.string.lock_when_idle titleRes = R.string.lock_when_idle
val values = arrayOf("0", "1", "2", "5", "10", "-1") val values = arrayOf("0", "1", "2", "5", "10", "-1")
entries = values.mapNotNull { entries = values.mapNotNull {
@ -91,22 +90,21 @@ class SettingsSecurityController : SettingsController() {
false false
} }
visibleIf(preferences.useAuthenticator()) { it } visibleIf(securityPreferences.useAuthenticator()) { it }
} }
} }
switchPreference { switchPreference {
key = Keys.hideNotificationContent bindTo(securityPreferences.hideNotificationContent())
titleRes = R.string.hide_notification_content titleRes = R.string.hide_notification_content
defaultValue = false
} }
listPreference { listPreference {
bindTo(preferences.secureScreen()) bindTo(securityPreferences.secureScreen())
titleRes = R.string.secure_screen titleRes = R.string.secure_screen
summary = "%s" summary = "%s"
entriesRes = PreferenceValues.SecureScreenMode.values().map { it.titleResId }.toTypedArray() entriesRes = SecurityPreferences.SecureScreenMode.values().map { it.titleResId }.toTypedArray()
entryValues = PreferenceValues.SecureScreenMode.values().map { it.name }.toTypedArray() entryValues = SecurityPreferences.SecureScreenMode.values().map { it.name }.toTypedArray()
} }
// SY --> // SY -->
@ -114,10 +112,10 @@ class SettingsSecurityController : SettingsController() {
key = "pref_edit_lock_times" key = "pref_edit_lock_times"
titleRes = R.string.action_edit_biometric_lock_times titleRes = R.string.action_edit_biometric_lock_times
val timeRanges = preferences.authenticatorTimeRanges().get().size val timeRanges = securityPreferences.authenticatorTimeRanges().get().size
summary = context.resources.getQuantityString(R.plurals.num_lock_times, timeRanges, timeRanges) summary = context.resources.getQuantityString(R.plurals.num_lock_times, timeRanges, timeRanges)
visibleIf(preferences.useAuthenticator()) { it } visibleIf(securityPreferences.useAuthenticator()) { it }
onClick { onClick {
router.pushController(BiometricTimesController()) router.pushController(BiometricTimesController())
@ -128,7 +126,7 @@ class SettingsSecurityController : SettingsController() {
titleRes = R.string.biometric_lock_days titleRes = R.string.biometric_lock_days
summaryRes = R.string.biometric_lock_days_summary summaryRes = R.string.biometric_lock_days_summary
visibleIf(preferences.useAuthenticator()) { it } visibleIf(securityPreferences.useAuthenticator()) { it }
onClick { onClick {
SetLockedDaysDialog().showDialog(router) SetLockedDaysDialog().showDialog(router)
@ -141,7 +139,7 @@ class SettingsSecurityController : SettingsController() {
// SY --> // SY -->
class SetLockedDaysDialog(bundle: Bundle? = null) : DialogController(bundle) { class SetLockedDaysDialog(bundle: Bundle? = null) : DialogController(bundle) {
val preferences: PreferencesHelper by injectLazy() val securityPreferences: SecurityPreferences by injectLazy()
override fun onCreateDialog(savedViewState: Bundle?): Dialog { override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val activity = activity!! val activity = activity!!
@ -157,7 +155,7 @@ class SettingsSecurityController : SettingsController() {
.map { activity.getString(it) } .map { activity.getString(it) }
.toTypedArray() .toTypedArray()
val lockDays = preferences.authenticatorDays().get() val lockDays = securityPreferences.authenticatorDays().get()
val selection = BooleanArray(7) { val selection = BooleanArray(7) {
when (it) { when (it) {
0 -> (lockDays and SecureActivityDelegate.LOCK_SUNDAY) == SecureActivityDelegate.LOCK_SUNDAY 0 -> (lockDays and SecureActivityDelegate.LOCK_SUNDAY) == SecureActivityDelegate.LOCK_SUNDAY
@ -195,7 +193,7 @@ class SettingsSecurityController : SettingsController() {
} }
} }
preferences.authenticatorDays().set(flags) securityPreferences.authenticatorDays().set(flags)
} }
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.create() .create()

View File

@ -20,6 +20,7 @@ import eu.kanade.domain.source.interactor.InsertFeedSavedSearch
import eu.kanade.domain.source.interactor.InsertSavedSearch import eu.kanade.domain.source.interactor.InsertSavedSearch
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.backup.BackupCreatorJob import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
@ -95,6 +96,7 @@ object EXHMigrations {
preferences: PreferencesHelper, preferences: PreferencesHelper,
networkPreferences: NetworkPreferences, networkPreferences: NetworkPreferences,
sourcePreferences: SourcePreferences, sourcePreferences: SourcePreferences,
securityPreferences: SecurityPreferences,
): Boolean { ): Boolean {
val oldVersion = preferences.ehLastVersionCode().get() val oldVersion = preferences.ehLastVersionCode().get()
try { try {
@ -354,7 +356,7 @@ object EXHMigrations {
if (oldVersion under 27) { if (oldVersion under 27) {
val oldSecureScreen = prefs.getBoolean("secure_screen", false) val oldSecureScreen = prefs.getBoolean("secure_screen", false)
if (oldSecureScreen) { if (oldSecureScreen) {
preferences.secureScreen().set(PreferenceValues.SecureScreenMode.ALWAYS) securityPreferences.secureScreen().set(SecurityPreferences.SecureScreenMode.ALWAYS)
} }
if (DeviceUtil.isMiui && preferences.extensionInstaller().get() == PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER) { if (DeviceUtil.isMiui && preferences.extensionInstaller().get() == PreferenceValues.ExtensionInstaller.PACKAGEINSTALLER) {
preferences.extensionInstaller().set(PreferenceValues.ExtensionInstaller.LEGACY) preferences.extensionInstaller().set(PreferenceValues.ExtensionInstaller.LEGACY)

View File

@ -11,6 +11,7 @@ import eu.kanade.domain.manga.interactor.GetSearchMetadata
import eu.kanade.domain.manga.interactor.InsertFlatMetadata import eu.kanade.domain.manga.interactor.InsertFlatMetadata
import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.interactor.UpdateManga
import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.network.NetworkPreferences
import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.source.SourceManager
@ -34,6 +35,7 @@ object DebugFunctions {
val prefs: PreferencesHelper by injectLazy() val prefs: PreferencesHelper by injectLazy()
val networkPrefs: NetworkPreferences by injectLazy() val networkPrefs: NetworkPreferences by injectLazy()
val sourcePrefs: SourcePreferences by injectLazy() val sourcePrefs: SourcePreferences by injectLazy()
val securityPrefs: SecurityPreferences by injectLazy()
val sourceManager: SourceManager by injectLazy() val sourceManager: SourceManager by injectLazy()
val updateManga: UpdateManga by injectLazy() val updateManga: UpdateManga by injectLazy()
val getFavorites: GetFavorites by injectLazy() val getFavorites: GetFavorites by injectLazy()
@ -45,12 +47,12 @@ object DebugFunctions {
fun forceUpgradeMigration() { fun forceUpgradeMigration() {
prefs.ehLastVersionCode().set(1) prefs.ehLastVersionCode().set(1)
EXHMigrations.upgrade(app, prefs, networkPrefs, sourcePrefs) EXHMigrations.upgrade(app, prefs, networkPrefs, sourcePrefs, securityPrefs)
} }
fun forceSetupJobs() { fun forceSetupJobs() {
prefs.ehLastVersionCode().set(0) prefs.ehLastVersionCode().set(0)
EXHMigrations.upgrade(app, prefs, networkPrefs, sourcePrefs) EXHMigrations.upgrade(app, prefs, networkPrefs, sourcePrefs, securityPrefs)
} }
fun resetAgedFlagInEXHManga() { fun resetAgedFlagInEXHManga() {

View File

@ -0,0 +1,37 @@
package eu.kanade.tachiyomi.core.security
import eu.kanade.tachiyomi.core.R
import eu.kanade.tachiyomi.core.preference.PreferenceStore
import eu.kanade.tachiyomi.core.preference.getEnum
class SecurityPreferences(
private val preferenceStore: PreferenceStore
) {
fun useAuthenticator() = this.preferenceStore.getBoolean("use_biometric_lock", false)
fun lockAppAfter() = this.preferenceStore.getInt("lock_app_after", 0)
fun secureScreen() = this.preferenceStore.getEnum("secure_screen_v2", SecureScreenMode.INCOGNITO)
fun hideNotificationContent() = this.preferenceStore.getBoolean("hide_notification_content", false)
// SY -->
fun authenticatorTimeRanges() = this.preferenceStore.getStringSet("biometric_time_ranges", mutableSetOf())
fun authenticatorDays() = this.preferenceStore.getInt("biometric_days", 0x7F)
// SY <--
/**
* For app lock. Will be set when there is a pending timed lock.
* Otherwise this pref should be deleted.
*/
fun lastAppClosed() = this.preferenceStore.getLong("last_app_closed", 0)
enum class SecureScreenMode(val titleResId: Int) {
ALWAYS(R.string.lock_always),
INCOGNITO(R.string.pref_incognito_mode),
NEVER(R.string.lock_never),
}
}