fix: only show camera preview after granting permission - #57
Open
OS-pedrogustavobilro wants to merge 2 commits into
Open
fix: only show camera preview after granting permission#57OS-pedrogustavobilro wants to merge 2 commits into
OS-pedrogustavobilro wants to merge 2 commits into
Conversation
References: Discovered while working on https://outsystemsrd.atlassian.net/browse/RMET-5329
OS-pedrogustavobilro
requested review from
ItsChaceD,
alexgerardojacinto,
andredestro,
eric-horodyski,
markemer and
theproducer
and removed request for
a team
August 3, 2026 12:12
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.
Description
This PR fixes the permission logic so that the camera preview only occurs after the permission has been granted. Accessing it was showing
SecurityExceptionin logs, and for Cap 9 was causing a bug (see Context section for more info)List of changes:
PreviewViewinstantiation inside apermissionGivenif block (the main fix). TheScanScreenUIdoesn't access camera directly so that can remain outside the permission check (and it should imo, to make the scanner UI visibile even without permission being granted, to maintain same UI as before this fix)bindToLifecyclehappening outside of thePreviewView. From myself and Claude's analysis, this seems to be leftover code from before the screen was migrated to have a Compose UI State, and from my tests it wasn't doing anything there anymore.permissionGivento be class-wide. Because of this permission logic change, the camera version was not getting initialized after granting permission via app settings (e.g. clickingCameraPermissionRequiredDialog) -> this requiredpermissionGivento be updated insideonResume, hence the extraction to be classwide, staying alongsideshowDialog.updatePermissionState.Boxthat wraps the Scanner UI.UI or behavior-wise you shouldn't notice changes, everything should still work as before.
Context
Discovered while working on https://outsystemsrd.atlassian.net/browse/RMET-5329 for the Capacitor Barcode Plugin.
What was happening was: when the scanner screen would prompt for permission, after granting, the scanner would be in a black screen. This would not happen after in subsequent opens if permission was granted prior
Root-cause: After updating the Androidx
camera2(aka CameraX) dependencies in the Capacitor Plugin (for Cap 9) to latest version. CameraX 1.6.x introduced a newcamera-camera2-pipebackend that changed how camera-open failures are handled. The previous backend (used byOSBarcodeLib-Android, currently at 1.4.0) silently tolerated a failed open, leaving the camera in a recoverable state. The pipe backend actively retries once and then enters a terminalGRAPH_ERRORstate with no further recovery.Type of changes
Tests
I tested with the consuming Capacitor and Cordova Plugins:
Checklist