diff options
Diffstat (limited to 'app/src/main/kotlin/com')
6 files changed, 11 insertions, 14 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt index 4bcf4aca..40fe422e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/StartActivity.kt @@ -75,7 +75,7 @@ class StartActivity : KauBaseActivity() { launch { try { - val authDefer = BiometricUtils.authenticate(this@StartActivity) + val authDefer = BiometricUtils.authenticate(this@StartActivity, prefs) 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 2cd01988..3641c2f3 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/BaseMainActivity.kt @@ -756,7 +756,7 @@ abstract class BaseMainActivity : BaseActivity(), MainActivityContract, lastAccessTime = System.currentTimeMillis() // precaution to avoid loops controlWebview?.resumeTimers() launch { - val authDefer = BiometricUtils.authenticate(this@BaseMainActivity) + val authDefer = BiometricUtils.authenticate(this@BaseMainActivity, prefs) fbCookie.switchBackUser() authDefer.await() if (shouldReload && prefs.autoRefreshFeed) { 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 6db3690a..ac02a052 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/WebOverlayActivity.kt @@ -225,7 +225,7 @@ abstract class WebOverlayActivityBase(private val userAgent: String = USER_AGENT userAgentString = userAgent prefs.prevId = prefs.userId launch { - val authDefer = BiometricUtils.authenticate(this@WebOverlayActivityBase) + val authDefer = BiometricUtils.authenticate(this@WebOverlayActivityBase, prefs) if (userId != prefs.userId) { fbCookie.switchUser(userId) } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt index 84cd60c8..0c29bb76 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/FragmentBase.kt @@ -40,7 +40,6 @@ import com.pitchedapps.frost.utils.Prefs import com.pitchedapps.frost.utils.REQUEST_REFRESH import com.pitchedapps.frost.utils.REQUEST_TEXT_ZOOM import com.pitchedapps.frost.utils.frostEvent -import kotlin.coroutines.CoroutineContext import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job @@ -48,8 +47,8 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.channels.ReceiveChannel import kotlinx.coroutines.isActive import kotlinx.coroutines.launch -import org.koin.core.KoinComponent -import org.koin.core.inject +import org.koin.android.ext.android.inject +import kotlin.coroutines.CoroutineContext /** * Created by Allan Wang on 2017-11-07. @@ -58,7 +57,7 @@ import org.koin.core.inject * Must be attached to activities implementing [MainActivityContract] */ @UseExperimental(ExperimentalCoroutinesApi::class) -abstract class BaseFragment : Fragment(), CoroutineScope, KoinComponent, FragmentContract, +abstract class BaseFragment : Fragment(), CoroutineScope, FragmentContract, DynamicUiContract { companion object { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt b/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt index aba17ed8..aa38fffd 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/settings/Security.kt @@ -38,7 +38,7 @@ fun SettingsActivity.getSecurityPrefs(): KPrefAdapterBuilder.() -> Unit = { * - enabling to ensure that it is supported * - disabling to ensure that it is permitted */ - BiometricUtils.authenticate(this@getSecurityPrefs, force = true).await() + BiometricUtils.authenticate(this@getSecurityPrefs, prefs, force = true).await() prefs.biometricsEnabled = it reloadByTitle(R.string.enable_biometrics) } 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 5a157a36..a7fb3b2d 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/BiometricUtils.kt @@ -39,13 +39,11 @@ typealias BiometricDeferred = CompletableDeferred<BiometricPrompt.CryptoObject?> * Container for [BiometricPrompt] * Inspired by coroutine's CommonPool */ -object BiometricUtils : KoinComponent { +object BiometricUtils { private val executor: Executor get() = pool ?: getOrCreatePoolSync() - private val prefs: Prefs by inject() - @Volatile private var pool: ExecutorService? = null @@ -68,7 +66,7 @@ object BiometricUtils : KoinComponent { private fun getOrCreatePoolSync(): Executor = pool ?: Executors.newSingleThreadExecutor().also { pool = it } - private fun shouldPrompt(context: Context): Boolean { + private fun shouldPrompt(context: Context, prefs: Prefs): Boolean { return prefs.biometricsEnabled && System.currentTimeMillis() - lastUnlockTime > UNLOCK_TIME_INTERVAL } @@ -77,9 +75,9 @@ object BiometricUtils : KoinComponent { * Note that the underlying request will call [androidx.fragment.app.FragmentTransaction.commit], * so this cannot happen after onSaveInstanceState. */ - fun authenticate(activity: FragmentActivity, force: Boolean = false): BiometricDeferred { + fun authenticate(activity: FragmentActivity, prefs: Prefs, force: Boolean = false): BiometricDeferred { val deferred: BiometricDeferred = CompletableDeferred() - if (!force && !shouldPrompt(activity)) { + if (!force && !shouldPrompt(activity, prefs)) { deferred.complete(null) return deferred } |