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