Skip to content

Commit 0fdddd3

Browse files
fix: prevent white screen on resume by auto-retrying biometric prompt on system cancel
1 parent 9f73115 commit 0fdddd3

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

app/src/main/java/me/bmax/apatch/ui/MainActivity.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class MainActivity : AppCompatActivity() {
239239
private val isLocked = mutableStateOf(false)
240240
private var isAuthenticated = false
241241
private var biometricPromptShowing = false
242+
private var startupSoundPlayed = false
242243
private var pendingActionModuleId by mutableStateOf<String?>(null)
243244
private var pendingScriptId by mutableStateOf<String?>(null)
244245

@@ -402,6 +403,12 @@ class MainActivity : AppCompatActivity() {
402403
biometricPromptShowing = false
403404
if (errorCode == androidx.biometric.BiometricPrompt.ERROR_USER_CANCELED) {
404405
finishAndRemoveTask()
406+
} else {
407+
Handler(Looper.getMainLooper()).postDelayed({
408+
if (!isAuthenticated && !biometricPromptShowing) {
409+
showBiometricPromptIfNeeded()
410+
}
411+
}, 300)
405412
}
406413
}
407414

@@ -410,7 +417,10 @@ class MainActivity : AppCompatActivity() {
410417
isLocked.value = false
411418
isAuthenticated = true
412419
biometricPromptShowing = false
413-
me.bmax.apatch.util.SoundEffectManager.playStartup(this@MainActivity)
420+
if (!startupSoundPlayed) {
421+
startupSoundPlayed = true
422+
me.bmax.apatch.util.SoundEffectManager.playStartup(this@MainActivity)
423+
}
414424
}
415425
})
416426
val promptInfo = androidx.biometric.BiometricPrompt.PromptInfo.Builder()
@@ -421,7 +431,11 @@ class MainActivity : AppCompatActivity() {
421431
biometricPrompt.authenticate(promptInfo)
422432
} else if (!biometricLogin || !canAuthenticate || isShareIntent) {
423433
isAuthenticated = true
424-
me.bmax.apatch.util.SoundEffectManager.playStartup(this)
434+
isLocked.value = false
435+
if (!startupSoundPlayed) {
436+
startupSoundPlayed = true
437+
me.bmax.apatch.util.SoundEffectManager.playStartup(this)
438+
}
425439
}
426440
}
427441

0 commit comments

Comments
 (0)