Fixes to biometric prompt for app shortcuts

Fixes #1049
This commit is contained in:
Jays2Kings 2021-10-17 04:15:36 -04:00
parent 134c2552f9
commit 8af3742945
3 changed files with 16 additions and 5 deletions

View file

@ -130,6 +130,9 @@ class SearchActivity : MainActivity() {
} }
} }
} }
if (intent.action == SHORTCUT_MANGA_BACK) {
SecureActivityDelegate.promptLockIfNeeded(this, true)
}
router.replaceTopController( router.replaceTopController(
RouterTransaction.with(MangaDetailsController(extras)) RouterTransaction.with(MangaDetailsController(extras))
.pushChangeHandler(SimpleSwapChangeHandler()) .pushChangeHandler(SimpleSwapChangeHandler())
@ -138,6 +141,7 @@ class SearchActivity : MainActivity() {
} }
SHORTCUT_SOURCE -> { SHORTCUT_SOURCE -> {
val extras = intent.extras ?: return false val extras = intent.extras ?: return false
SecureActivityDelegate.promptLockIfNeeded(this, true)
router.replaceTopController( router.replaceTopController(
RouterTransaction.with(BrowseSourceController(extras)) RouterTransaction.with(BrowseSourceController(extras))
.pushChangeHandler(SimpleSwapChangeHandler()) .pushChangeHandler(SimpleSwapChangeHandler())

View file

@ -1203,9 +1203,16 @@ class MangaDetailsController :
} }
private fun isLocked(): Boolean { private fun isLocked(): Boolean {
if (presenter.isLockedFromSearch) {
return SecureActivityDelegate.shouldBeLocked()
}
return false
}
private fun needsToBeUnlocked(): Boolean {
if (presenter.isLockedFromSearch) { if (presenter.isLockedFromSearch) {
SecureActivityDelegate.promptLockIfNeeded(activity) SecureActivityDelegate.promptLockIfNeeded(activity)
return true return SecureActivityDelegate.shouldBeLocked()
} }
return false return false
} }
@ -1352,7 +1359,7 @@ class MangaDetailsController :
} }
override fun favoriteManga(longPress: Boolean) { override fun favoriteManga(longPress: Boolean) {
if (isLocked()) return if (needsToBeUnlocked()) return
val manga = presenter.manga val manga = presenter.manga
val categories = presenter.getCategories() val categories = presenter.getCategories()
if (!manga.favorite) { if (!manga.favorite) {
@ -1469,7 +1476,7 @@ class MangaDetailsController :
} }
override fun showTrackingSheet() { override fun showTrackingSheet() {
if (isLocked()) return if (needsToBeUnlocked()) return
trackingBottomSheet = trackingBottomSheet =
TrackingBottomSheet(this) TrackingBottomSheet(this)
trackingBottomSheet?.show() trackingBottomSheet?.show()

View file

@ -28,13 +28,13 @@ object SecureActivityDelegate {
} }
} }
fun promptLockIfNeeded(activity: Activity?) { fun promptLockIfNeeded(activity: Activity?, requireSuccess: Boolean = false) {
if (activity == null || isAuthenticating) return if (activity == null || isAuthenticating) return
val lockApp = preferences.useBiometrics().get() val lockApp = preferences.useBiometrics().get()
if (lockApp && BiometricManager.from(activity).canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL or BiometricManager.Authenticators.BIOMETRIC_WEAK) == BiometricManager.BIOMETRIC_SUCCESS) { if (lockApp && BiometricManager.from(activity).canAuthenticate(BiometricManager.Authenticators.DEVICE_CREDENTIAL or BiometricManager.Authenticators.BIOMETRIC_WEAK) == BiometricManager.BIOMETRIC_SUCCESS) {
if (isAppLocked()) { if (isAppLocked()) {
val intent = Intent(activity, BiometricActivity::class.java) val intent = Intent(activity, BiometricActivity::class.java)
intent.putExtra("fromSearch", (activity is SearchActivity)) intent.putExtra("fromSearch", (activity is SearchActivity) && !requireSuccess)
activity.startActivity(intent) activity.startActivity(intent)
activity.overridePendingTransition(0, 0) activity.overridePendingTransition(0, 0)
} }