From ec3002633325324ba5b0c699304bda865f1f2be2 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Fri, 16 Sep 2022 19:34:46 +0700 Subject: [PATCH] Fix always-on app lock on cold start (#8018) --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 4 ++++ .../tachiyomi/ui/base/delegate/SecureActivityDelegate.kt | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index e31e3f99d..37a88933c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -172,6 +172,10 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { }.build() } + override fun onCreate(owner: LifecycleOwner) { + SecureActivityDelegate.onApplicationCreated() + } + override fun onStop(owner: LifecycleOwner) { SecureActivityDelegate.onApplicationStopped() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt index 537dcae23..03822c761 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/delegate/SecureActivityDelegate.kt @@ -23,6 +23,15 @@ interface SecureActivityDelegate { fun registerSecureActivity(activity: AppCompatActivity) companion object { + fun onApplicationCreated() { + val lockDelay = Injekt.get().lockAppAfter().get() + if (lockDelay == 0) { + // Restore always active app lock + // Delayed lock will be restored later on activity resume + lockState = LockState.ACTIVE + } + } + fun onApplicationStopped() { val preferences = Injekt.get() if (!preferences.useAuthenticator().get()) return