Fix PIN unlock unusable after cancelling biometric prompt (#151)#166
Open
MiMoHo wants to merge 1 commit into
Open
Fix PIN unlock unusable after cancelling biometric prompt (#151)#166MiMoHo wants to merge 1 commit into
MiMoHo wants to merge 1 commit into
Conversation
The app lock passcode screen has no submit button and verifies the code on
every keystroke, but a wrong code was never rejected. After cancelling the
biometric prompt and falling back to the PIN keypad, the user could type
digits endlessly with no feedback and no way to submit, so a correct PIN was
effectively unreachable.
- NCPAppLock: once the entered code reaches the stored passcode length and is
still wrong, show the existing "Incorrect code" error and clear the input.
- AppLockHelper: checkPasscode no longer accepts the hardcoded "0000" fallback
when the stored passcode is unreadable; added a pure, unit-tested helper
shouldRejectPasscodeAttempt.
- Dialogs: InputPasscodeDialog now validates with all { isDigit() } instead of
toIntOrNull(), which silently rejected passcodes longer than ~9 digits even
though the field allows up to 16.
Adds unit tests for the passcode attempt evaluation.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #151. When both PIN and biometric app lock are enabled, cancelling the biometric prompt drops the user onto the PIN keypad — but the passcode was only ever verified as it was typed, with no submit button and no feedback. Because a wrong digit was never rejected, the user could "type in numbers endlessly" and a correct PIN was effectively unreachable once a wrong digit had been entered.
Changes
NCPAppLock.kt— when the typed passcode reaches the length of the stored passcode and is still incorrect, the screen now shows the existing "Incorrect code" error and clears the input, instead of silently accepting further digits. The stored passcode length is loaded asynchronously and the check only runs once it is known, so a correct PIN of any length still unlocks on the last digit as before.AppLockHelper.ktcheckPasscode()no longer falls back to the hardcoded"0000"when the stored passcode cannot be read; it returnsfalseinstead, so the lock can never be opened with a default code.shouldRejectPasscodeAttempt(input, length)that encapsulates the "is this a completed, wrong attempt" decision so it can be unit-tested without the Android runtime.Dialogs.kt—InputPasscodeDialognow filters input withall { it.isDigit() }instead oftoIntOrNull() != null. The old check rejected passcodes longer than 9–10 digits because they overflowedIntparsing, even though the field allows up to 16 digits.Testing
AppLockHelperTest) covering empty / incomplete / full-length-wrong / over-length / unreadable-passcode / long-passcode cases. All green../gradlew testDebugUnitTestpasses;lintDebugshows only pre-existing findings (unchanged by this diff).Note
This contribution was made using AI (Claude). All generated code was proofread and validated by the committer.