diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index fd68315bb..cffddba7e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -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 } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt index d714dbd4c..48b5be406 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferenceKeys.kt @@ -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" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index d4500176c..6dd69a2c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -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) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 2935982f1..e284d94b7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -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) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt index 7d120f5cb..5105ac048 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt @@ -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

> : NucleusAppCompatActivity

() { initializeMenu() } - override fun onResume() { - super.onResume() - BiometricUnlockDelegate.onResume(this) - } - /** * Called when the activity is destroyed. Cleans up the viewer, configuration and any view. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/security/BiometricUnlockActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/security/BiometricUnlockActivity.kt index fdfaad2b8..654628211 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/security/BiometricUnlockActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/security/BiometricUnlockActivity.kt @@ -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() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/security/BiometricUnlockDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/security/SecureActivityDelegate.kt similarity index 71% rename from app/src/main/java/eu/kanade/tachiyomi/ui/security/BiometricUnlockDelegate.kt rename to app/src/main/java/eu/kanade/tachiyomi/ui/security/SecureActivityDelegate.kt index ab684fa64..d9310c086 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/security/BiometricUnlockDelegate.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/security/SecureActivityDelegate.kt @@ -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() 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) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index b82ead818..b768def6d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -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 + } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 49a9e922e..637b1bf8a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -141,6 +141,7 @@ After 1 minute After %1$s minutes + Secure screen Display