@@ -1,55 +0,0 @@
|
||||
package eu.kanade.tachiyomi.ui.security
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.isAuthenticationSupported
|
||||
import eu.kanade.tachiyomi.util.view.setSecureScreen
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.util.Date
|
||||
|
||||
class SecureActivityDelegate(private val activity: FragmentActivity) {
|
||||
|
||||
private val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
fun onCreate() {
|
||||
val secureScreenFlow = preferences.secureScreen().asFlow()
|
||||
val incognitoModeFlow = preferences.incognitoMode().asFlow()
|
||||
combine(secureScreenFlow, incognitoModeFlow) { secureScreen, incognitoMode ->
|
||||
secureScreen == PreferenceValues.SecureScreenMode.ALWAYS || secureScreen == PreferenceValues.SecureScreenMode.INCOGNITO && incognitoMode
|
||||
}
|
||||
.onEach { activity.window.setSecureScreen(it) }
|
||||
.launchIn(activity.lifecycleScope)
|
||||
}
|
||||
|
||||
fun onResume() {
|
||||
if (preferences.useAuthenticator().get()) {
|
||||
if (activity.isAuthenticationSupported()) {
|
||||
if (isAppLocked()) {
|
||||
activity.startActivity(Intent(activity, UnlockActivity::class.java))
|
||||
activity.overridePendingTransition(0, 0)
|
||||
}
|
||||
} else {
|
||||
preferences.useAuthenticator().set(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun isAppLocked(): Boolean {
|
||||
if (!locked) {
|
||||
return false
|
||||
}
|
||||
|
||||
return preferences.lockAppAfter().get() <= 0 ||
|
||||
Date().time >= preferences.lastAppUnlock().get() + 60 * 1000 * preferences.lockAppAfter().get()
|
||||
}
|
||||
|
||||
companion object {
|
||||
var locked: Boolean = true
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import android.os.Bundle
|
||||
import androidx.biometric.BiometricPrompt
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseThemedActivity
|
||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||
import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate
|
||||
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil
|
||||
import eu.kanade.tachiyomi.util.system.AuthenticatorUtil.startAuthentication
|
||||
import eu.kanade.tachiyomi.util.system.logcat
|
||||
@@ -14,7 +15,7 @@ import java.util.Date
|
||||
/**
|
||||
* Blank activity with a BiometricPrompt.
|
||||
*/
|
||||
class UnlockActivity : BaseThemedActivity() {
|
||||
class UnlockActivity : BaseActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
Reference in New Issue
Block a user