mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
Use blank activity for biometric activity
also using less deprecated methods for it Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
parent
b37a010a77
commit
adb62a3fe6
4 changed files with 12 additions and 9 deletions
|
@ -62,7 +62,7 @@ open class App : Application(), LifecycleObserver {
|
|||
@Suppress("unused")
|
||||
fun onAppBackgrounded() {
|
||||
// App in background
|
||||
if (preferences.lockAfter().getOrDefault() >= 0) {
|
||||
if (!SecureActivityDelegate.isAuthenticating && preferences.lockAfter().getOrDefault() >= 0) {
|
||||
SecureActivityDelegate.locked = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.viewbinding.ViewBinding
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.main.SearchActivity
|
||||
import eu.kanade.tachiyomi.ui.security.BiometricActivity
|
||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.system.getThemeWithExtras
|
||||
import eu.kanade.tachiyomi.util.system.setThemeAndNight
|
||||
|
@ -29,7 +28,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (this !is BiometricActivity && this !is SearchActivity) {
|
||||
if (this !is SearchActivity) {
|
||||
SecureActivityDelegate.promptLockIfNeeded(this)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
package eu.kanade.tachiyomi.ui.security
|
||||
|
||||
import android.os.Bundle
|
||||
import androidx.biometric.BiometricManager
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.databinding.MainActivityBinding
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseThemedActivity
|
||||
import java.util.Date
|
||||
import java.util.concurrent.ExecutorService
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
class BiometricActivity : BaseActivity<MainActivityBinding>() {
|
||||
class BiometricActivity : BaseThemedActivity() {
|
||||
private val executor: ExecutorService = Executors.newSingleThreadExecutor()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val fromSearch = intent.getBooleanExtra("fromSearch", false)
|
||||
SecureActivityDelegate.isAuthenticating = true
|
||||
val biometricPrompt = BiometricPrompt(
|
||||
this,
|
||||
executor,
|
||||
|
@ -23,6 +24,7 @@ class BiometricActivity : BaseActivity<MainActivityBinding>() {
|
|||
|
||||
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
|
||||
super.onAuthenticationError(errorCode, errString)
|
||||
SecureActivityDelegate.isAuthenticating = false
|
||||
if (fromSearch) finish()
|
||||
else finishAffinity()
|
||||
}
|
||||
|
@ -30,6 +32,7 @@ class BiometricActivity : BaseActivity<MainActivityBinding>() {
|
|||
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
|
||||
super.onAuthenticationSucceeded(result)
|
||||
SecureActivityDelegate.locked = false
|
||||
SecureActivityDelegate.isAuthenticating = false
|
||||
preferences.lastUnlock().set(Date().time)
|
||||
finish()
|
||||
}
|
||||
|
@ -38,7 +41,7 @@ class BiometricActivity : BaseActivity<MainActivityBinding>() {
|
|||
|
||||
val promptInfo = BiometricPrompt.PromptInfo.Builder()
|
||||
.setTitle(getString(R.string.unlock_library))
|
||||
.setDeviceCredentialAllowed(true)
|
||||
.setAllowedAuthenticators(BiometricManager.Authenticators.DEVICE_CREDENTIAL or BiometricManager.Authenticators.BIOMETRIC_WEAK)
|
||||
.build()
|
||||
|
||||
biometricPrompt.authenticate(promptInfo)
|
||||
|
|
|
@ -15,6 +15,7 @@ object SecureActivityDelegate {
|
|||
private val preferences by injectLazy<PreferencesHelper>()
|
||||
|
||||
var locked: Boolean = true
|
||||
var isAuthenticating: Boolean = false
|
||||
|
||||
fun setSecure(activity: Activity?, force: Boolean? = null) {
|
||||
val enabled = force ?: preferences.secureScreen().getOrDefault()
|
||||
|
@ -29,9 +30,9 @@ object SecureActivityDelegate {
|
|||
}
|
||||
|
||||
fun promptLockIfNeeded(activity: Activity?) {
|
||||
if (activity == null) return
|
||||
if (activity == null || isAuthenticating) return
|
||||
val lockApp = preferences.useBiometrics().getOrDefault()
|
||||
if (lockApp && BiometricManager.from(activity).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
if (lockApp && BiometricManager.from(activity).canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL or BiometricManager.Authenticators.BIOMETRIC_WEAK) == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
if (isAppLocked()) {
|
||||
val intent = Intent(activity, BiometricActivity::class.java)
|
||||
intent.putExtra("fromSearch", (activity is SearchActivity))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue