mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-27 09:44:55 +03:00
Add secure screen setting
This commit is contained in:
parent
b06f1c81bc
commit
61d2107e9c
10 changed files with 49 additions and 15 deletions
|
@ -15,7 +15,7 @@ import eu.kanade.tachiyomi.data.notification.Notifications
|
|||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
||||
import eu.kanade.tachiyomi.ui.security.BiometricUnlockDelegate
|
||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||
import org.acra.ACRA
|
||||
import org.acra.annotation.ReportsCrashes
|
||||
|
@ -64,7 +64,7 @@ open class App : Application(), LifecycleObserver {
|
|||
fun onAppBackgrounded() {
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
if (preferences.lockAppAfter().getOrDefault() >= 0) {
|
||||
BiometricUnlockDelegate.locked = true
|
||||
SecureActivityDelegate.locked = true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,8 @@ object PreferenceKeys {
|
|||
|
||||
const val lastAppUnlock = "last_app_unlock"
|
||||
|
||||
const val secureScreen = "secure_screen"
|
||||
|
||||
const val downloadNew = "download_new"
|
||||
|
||||
const val downloadNewCategories = "download_new_categories"
|
||||
|
|
|
@ -58,6 +58,8 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun lastAppUnlock() = rxPrefs.getLong(Keys.lastAppUnlock, 0)
|
||||
|
||||
fun secureScreen() = rxPrefs.getBoolean(Keys.secureScreen, false)
|
||||
|
||||
fun clear() = prefs.edit().clear().apply()
|
||||
|
||||
fun themeMode() = rxPrefs.getString(Keys.themeMode, Values.THEME_MODE_SYSTEM)
|
||||
|
|
|
@ -8,7 +8,7 @@ import androidx.appcompat.app.AppCompatDelegate
|
|||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.ui.security.BiometricUnlockDelegate
|
||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
|
||||
|
@ -45,11 +45,14 @@ abstract class BaseActivity : AppCompatActivity() {
|
|||
})
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
SecureActivityDelegate.onCreate(this)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
BiometricUnlockDelegate.onResume(this)
|
||||
|
||||
SecureActivityDelegate.onResume(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package eu.kanade.tachiyomi.ui.base.activity
|
||||
|
||||
import android.os.Bundle
|
||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||
import nucleus.view.NucleusAppCompatActivity
|
||||
|
||||
|
@ -11,4 +13,16 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
|
|||
LocaleHelper.updateConfiguration(this)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
SecureActivityDelegate.onCreate(this)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
SecureActivityDelegate.onResume(this)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import eu.kanade.tachiyomi.ui.reader.viewer.pager.L2RPagerViewer
|
|||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.pager.VerticalPagerViewer
|
||||
import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
|
||||
import eu.kanade.tachiyomi.ui.security.BiometricUnlockDelegate
|
||||
import eu.kanade.tachiyomi.util.lang.plusAssign
|
||||
import eu.kanade.tachiyomi.util.storage.getUriCompat
|
||||
import eu.kanade.tachiyomi.util.system.GLUtil
|
||||
|
@ -150,11 +149,6 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
|||
initializeMenu()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
BiometricUnlockDelegate.onResume(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity is destroyed. Cleans up the viewer, configuration and any view.
|
||||
*/
|
||||
|
|
|
@ -28,7 +28,7 @@ class BiometricUnlockActivity : AppCompatActivity() {
|
|||
|
||||
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
|
||||
super.onAuthenticationSucceeded(result)
|
||||
BiometricUnlockDelegate.locked = false
|
||||
SecureActivityDelegate.locked = false
|
||||
preferences.lastAppUnlock().set(Date().time)
|
||||
finish()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.kanade.tachiyomi.ui.security
|
||||
|
||||
import android.content.Intent
|
||||
import android.view.WindowManager
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
|
@ -8,12 +9,23 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault
|
|||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
|
||||
object BiometricUnlockDelegate {
|
||||
object SecureActivityDelegate {
|
||||
|
||||
private val preferences by injectLazy<PreferencesHelper>()
|
||||
|
||||
var locked: Boolean = true
|
||||
|
||||
fun onCreate(activity: FragmentActivity) {
|
||||
preferences.secureScreen().asObservable()
|
||||
.subscribe {
|
||||
if (it) {
|
||||
activity.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
|
||||
} else {
|
||||
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onResume(activity: FragmentActivity) {
|
||||
val lockApp = preferences.useBiometricLock().getOrDefault()
|
||||
if (lockApp && BiometricManager.from(activity).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
|
|
@ -117,10 +117,10 @@ class SettingsGeneralController : SettingsController() {
|
|||
summary = "%s"
|
||||
}
|
||||
|
||||
if (BiometricManager.from(context).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
preferenceCategory {
|
||||
titleRes = R.string.pref_category_security
|
||||
preferenceCategory {
|
||||
titleRes = R.string.pref_category_security
|
||||
|
||||
if (BiometricManager.from(context).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
switchPreference {
|
||||
key = Keys.useBiometricLock
|
||||
titleRes = R.string.lock_with_biometrics
|
||||
|
@ -145,6 +145,12 @@ class SettingsGeneralController : SettingsController() {
|
|||
.subscribeUntilDestroy { isVisible = it }
|
||||
}
|
||||
}
|
||||
|
||||
switchPreference {
|
||||
key = Keys.secureScreen
|
||||
titleRes = R.string.secure_screen
|
||||
defaultValue = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@
|
|||
<item quantity="one">After 1 minute</item>
|
||||
<item quantity="other">After %1$s minutes</item>
|
||||
</plurals>
|
||||
<string name="secure_screen">Secure screen</string>
|
||||
|
||||
<!-- Library section -->
|
||||
<string name="pref_category_library_display">Display</string>
|
||||
|
|
Loading…
Reference in a new issue