Device: Recover from revoked Bluetooth scan permission#576
Merged
Conversation
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.
What changed
Fixed an issue where the app could stop scanning when Android silently revoked the Bluetooth scan operation at runtime — for example, when AppOps blocks the call while the formal permission grant remains in place. The app now detects the revocation, refreshes which permissions it considers missing, and re-prompts the user instead of failing silently for the rest of the session.
Technical Context
ContextCompat.checkSelfPermissiononly inspects the manifest/runtime grant, so the app missed AppOps-level denials. When the BLE stack threwSecurityExceptionfromstartScan, theretryWhenreturnedfalseand the device flow died until the next process restart.PermissionChecker.checkSelfPermission, which consults AppOps too —missingScanPermissionsnow reflects the effective state and the existing missing-permissions UI surfaces immediately.BleScanner.scan()wrapsstartScan,flushPendingScanResults, andstopScanintry/catch (SecurityException)so revocation closes the flow cleanly. The flush job now also only launches afterstartScanreturns, so a denied start no longer leaves an orphan flush coroutine that would itself throw on every iteration.BlePodMonitorcatchesSecurityExceptionfrom the scan flow, callsPermissionTool.recheck(), and emits an empty list. The outerretryWhenretries onSecurityException(after recheck) instead of giving up — recovery happens without an app restart once the user re-grants.Review checklist
PermissionChecker.PERMISSION_GRANTEDsemantics match the previousPackageManager.PERMISSION_GRANTEDfor normally granted permissions (no AppOps interference).