Repository navigation
Keep an unlock when Android refuses to foreground the lock service - #2273
Draft
mpretty-cyro wants to merge 1 commit into
Draft
mpretty-cyro wants to merge 1 commit into
mpretty-cyro wants to merge 1 commit into
Conversation
Since the lock screen stopped crashing on a refused start in onResume, the same background unlock now reaches startForeground through setMasterSecret, which Android 12+ also refuses there. Catch it like the start; the secret is already set, and an unforegrounded service that dies clears it, so the app asks for the lock again rather than crashing.
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.
Contributor checklist
playflavour,qaFixes #1234syntaxDescription
New crash cluster in 1.33.9:
ForegroundServiceStartNotAllowedExceptionfromKeyCachingService.foregroundService, reached fromScreenLockActivity.handleAuthenticated→setMasterSecretafter the device-credential prompt returns (6 users / 6 events).#2263 stopped
onResumecrashing when Android refuses to startKeyCachingServicebecause the app still counts as background. The same unlock now carries on tosetMasterSecret, whosestartForegroundAndroid 12+ also refuses in that state. 1.33.8'sonResumecluster (29 users / 30 events) is gone from 1.33.9's top crashes, and this is what's left of that path.foregroundServicenow catches the refusal (ForegroundServiceStartNotAllowedExceptionis anIllegalStateException) and logs it. The secret is set before the call, so the unlock goes through. If the service then dies without being foregrounded,onDestroyclears the key and the app asks for the lock again, so it fails locked rather than unlocked.Confidence: high that it stops the crash.
Testing: a local-only hook (not in this PR) made
startForegroundthrow the way Android refuses it. With app lock on and a device PIN, a cold launch and PIN unlock went throughonActivityResult→handleAuthenticated→setMasterSecret, the same path as the crash. The refusal was logged and caught, and the home screen opened with no crash. Turning app lock on, which goes throughhandleLockToggled, was caught the same way. Without the hook, a cold launch and PIN unlock still foregrounds the service (dumpsys activity services:isForeground=true) and opens the home screen. The real background refusal was not reproduced. Tested on aqabuild, because app lock doesn't engage indebug.