From ee2cbac74472e72b37d08e9fbb1e60d3bdc2fddc Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 29 Sep 2019 00:31:00 -0700 Subject: Fix crash for dialog prompt --- .../main/kotlin/com/pitchedapps/frost/StartActivity.kt | 2 +- .../pitchedapps/frost/activities/BaseMainActivity.kt | 3 +++ .../pitchedapps/frost/activities/WebOverlayActivity.kt | 5 +++-- .../com/pitchedapps/frost/utils/BiometricUtils.kt | 17 ++++++++++++++++- app/src/main/play/en-US/whatsnew | 4 ++-- 5 files changed, 25 insertions(+), 6 deletions(-) (limited to 'app') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt index 547718dd..0f8bd9d1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt @@ -70,9 +70,9 @@ class StartActivity : KauBaseActivity() { showInvalidWebView() } - val authDefer = BiometricUtils.authenticate(this@StartActivity) launch { try { + val authDefer = BiometricUtils.authenticate(this@StartActivity) FbCookie.switchBackUser() val cookies = ArrayList(cookieDao.selectAll()) L.i { "Cookies loaded at time ${System.currentTimeMillis()}" } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt index 798ee4b3..858f8590 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -87,6 +87,7 @@ import com.pitchedapps.frost.fragments.BaseFragment import com.pitchedapps.frost.fragments.WebFragment import com.pitchedapps.frost.services.scheduleNotificationsFromPrefs import com.pitchedapps.frost.utils.ACTIVITY_SETTINGS +import com.pitchedapps.frost.utils.BiometricUtils import com.pitchedapps.frost.utils.EXTRA_COOKIES import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.MAIN_TIMEOUT_DURATION @@ -521,7 +522,9 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, lastAccessTime = System.currentTimeMillis() // precaution to avoid loops controlWebview?.resumeTimers() launch { + val authDefer = BiometricUtils.authenticate(this@BaseMainActivity) FbCookie.switchBackUser() + authDefer.await() if (shouldReload && Prefs.autoRefreshFeed) { refreshAll() } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt index 628ab5dc..3a6af146 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -224,10 +224,11 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT with(web) { userAgentString = userAgent Prefs.prevId = Prefs.userId - val authDefer = BiometricUtils.authenticate(this@WebOverlayActivityBase) launch { - if (userId != Prefs.userId) + val authDefer = BiometricUtils.authenticate(this@WebOverlayActivityBase) + if (userId != Prefs.userId) { FbCookie.switchUser(userId) + } authDefer.await() reloadBase(true) if (Showcase.firstWebOverlay) { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt index 136fe28f..597b4921 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt @@ -21,6 +21,9 @@ import android.hardware.fingerprint.FingerprintManager import android.os.Build import androidx.biometric.BiometricPrompt import androidx.fragment.app.FragmentActivity +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleObserver +import androidx.lifecycle.OnLifecycleEvent import ca.allanwang.kau.utils.string import com.pitchedapps.frost.R import kotlinx.coroutines.CompletableDeferred @@ -80,7 +83,19 @@ object BiometricUtils { .setTitle(activity.string(R.string.biometrics_prompt_title)) .setNegativeButtonText(activity.string(R.string.kau_cancel)) .build() - BiometricPrompt(activity, executor, Callback(activity, deferred)).authenticate(info) + val prompt = BiometricPrompt(activity, executor, Callback(activity, deferred)) + activity.lifecycle.addObserver(object : LifecycleObserver { + @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) + fun onPause() { + if (!deferred.isCompleted) { + prompt.cancelAuthentication() + deferred.cancel() + activity.finish() + } + activity.lifecycle.removeObserver(this) + } + }) + prompt.authenticate(info) return deferred } diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index 8e47d7d4..4a51e79b 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -1,5 +1,5 @@ v2.4.1 -* Convert facebook desktop urls to mobile ones +* Add better support for mobile url conversions * Notification tab will keep first page in the same window; fixes marking notifications as read -* Fix nav and status bar icon colors for custom themes (Android O+) +* Fix nav and status bar icon colors for custom themes (Android O+) \ No newline at end of file -- cgit v1.2.3 From a7e0ad1c50c37f82184774174f1e0f6fb72165aa Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 29 Sep 2019 00:33:28 -0700 Subject: Update changelog --- .../main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt | 2 +- app/src/main/play/en-US/whatsnew | 3 ++- app/src/main/res/xml/frost_changelog.xml | 2 +- docs/Changelog.md | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt index 3df3b2c2..9e5e6c63 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostUrlOverlayValidator.kt @@ -79,7 +79,7 @@ fun FrostWebView.requestWebOverlay(url: String): Boolean { if (!Prefs.overlayEnabled) return false if (context is WebOverlayActivityBase) { val shouldUseDesktop = url.isFacebookUrl - //already overlay; manage user agent + // already overlay; manage user agent if (userAgentString != USER_AGENT_DESKTOP_CONST && shouldUseDesktop) { L._i { "Switch to desktop agent overlay" } context.launchWebOverlayDesktop(url) diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index 4a51e79b..2c68cc55 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -2,4 +2,5 @@ v2.4.1 * Add better support for mobile url conversions * Notification tab will keep first page in the same window; fixes marking notifications as read -* Fix nav and status bar icon colors for custom themes (Android O+) \ No newline at end of file +* Fix nav and status bar icon colors for custom themes (Android O+) +* Fix biometric prompt, and prompt on activity resume \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 955e1239..88216d63 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -10,7 +10,7 @@ - + diff --git a/docs/Changelog.md b/docs/Changelog.md index 54684053..30820aa0 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -4,6 +4,7 @@ * Add better support for mobile url conversions * Notification tab will keep first page in the same window; fixes marking notifications as read * Fix nav and status bar icon colors for custom themes (Android O+) +* Fix biometric prompt, and prompt on activity resume ## v2.4.0 * Removed request services, which potentially caused phishing warnings. -- cgit v1.2.3