mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-22 17:01:48 +01:00
Fix secure screen option subscription memory leak
This commit is contained in:
parent
572f58a3a4
commit
022cde2c00
@ -15,6 +15,9 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||
|
||||
val preferences: PreferencesHelper by injectLazy()
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
private val secureActivityDelegate = SecureActivityDelegate(this)
|
||||
|
||||
private val darkTheme: Int by lazy {
|
||||
when (preferences.themeDark()) {
|
||||
Values.THEME_DARK_DEFAULT -> R.style.Theme_Tachiyomi_Dark
|
||||
@ -43,12 +46,18 @@ abstract class BaseActivity : AppCompatActivity() {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
SecureActivityDelegate.onCreate(this)
|
||||
secureActivityDelegate.onCreate()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
SecureActivityDelegate.onResume(this)
|
||||
secureActivityDelegate.onResume()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
secureActivityDelegate.onDestroy()
|
||||
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ import nucleus.view.NucleusAppCompatActivity
|
||||
|
||||
abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>() {
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
private val secureActivityDelegate = SecureActivityDelegate(this)
|
||||
|
||||
init {
|
||||
@Suppress("LeakingThis")
|
||||
LocaleHelper.updateConfiguration(this)
|
||||
@ -16,12 +19,18 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
SecureActivityDelegate.onCreate(this)
|
||||
secureActivityDelegate.onCreate()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
SecureActivityDelegate.onResume(this)
|
||||
secureActivityDelegate.onResume()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
secureActivityDelegate.onDestroy()
|
||||
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
@ -7,16 +7,17 @@ import androidx.fragment.app.FragmentActivity
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import java.util.Date
|
||||
import rx.Subscription
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
object SecureActivityDelegate {
|
||||
class SecureActivityDelegate(private val activity: FragmentActivity) {
|
||||
|
||||
private val preferences by injectLazy<PreferencesHelper>()
|
||||
|
||||
var locked: Boolean = true
|
||||
private var secureScreenSubscription: Subscription? = null
|
||||
|
||||
fun onCreate(activity: FragmentActivity) {
|
||||
preferences.secureScreen().asObservable()
|
||||
fun onCreate() {
|
||||
secureScreenSubscription = preferences.secureScreen().asObservable()
|
||||
.subscribe {
|
||||
if (it) {
|
||||
activity.window.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
|
||||
@ -26,7 +27,7 @@ object SecureActivityDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
fun onResume(activity: FragmentActivity) {
|
||||
fun onResume() {
|
||||
val lockApp = preferences.useBiometricLock().getOrDefault()
|
||||
if (lockApp && BiometricManager.from(activity).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||
if (isAppLocked()) {
|
||||
@ -39,9 +40,17 @@ object SecureActivityDelegate {
|
||||
}
|
||||
}
|
||||
|
||||
fun onDestroy() {
|
||||
secureScreenSubscription?.unsubscribe()
|
||||
}
|
||||
|
||||
private fun isAppLocked(): Boolean {
|
||||
return locked &&
|
||||
(preferences.lockAppAfter().getOrDefault() <= 0 ||
|
||||
Date().time >= preferences.lastAppUnlock().getOrDefault() + 60 * 1000 * preferences.lockAppAfter().getOrDefault())
|
||||
}
|
||||
|
||||
companion object {
|
||||
var locked: Boolean = true
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user