Skip to content

fix: only show camera preview after granting permission - #57

Open
OS-pedrogustavobilro wants to merge 2 commits into
mainfrom
fix/RMET-5329/permission-logic-new-camerax-version
Open

fix: only show camera preview after granting permission#57
OS-pedrogustavobilro wants to merge 2 commits into
mainfrom
fix/RMET-5329/permission-logic-new-camerax-version

Conversation

@OS-pedrogustavobilro

Copy link
Copy Markdown
Collaborator

⚠️ 🤖 AI-assisted development with Claude Code, with manual review and testing by me

Description

This PR fixes the permission logic so that the camera preview only occurs after the permission has been granted. Accessing it was showing SecurityException in logs, and for Cap 9 was causing a bug (see Context section for more info)

List of changes:

  1. Wrap the camera PreviewView instantiation inside a permissionGiven if block (the main fix). The ScanScreenUI doesn'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)
  2. Remove duplicate bindToLifecycle happening outside of the PreviewView. 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.
  3. Extracted permissionGiven to be class-wide. Because of this permission logic change, the camera version was not getting initialized after granting permission via app settings (e.g. clicking CameraPermissionRequiredDialog) -> this required permissionGiven to be updated inside onResume, hence the extraction to be classwide, staying alongside showDialog.
  4. Also extracted common permission setting logic to new helper method updatePermissionState.
  5. This change in logic was resulting in a slight tint change inside the scanner frame after granting camera permission. Fixed it by adding a black background to the Box that 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 new camera-camera2-pipe backend that changed how camera-open failures are handled. The previous backend (used by OSBarcodeLib-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 terminal GRAPH_ERROR state with no further recovery.

Type of changes

  • Fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Refactor (cosmetic changes)
  • Breaking change (change that would cause existing functionality to not work as expected)

Tests

I tested with the consuming Capacitor and Cordova Plugins:

  1. Example Capacitor app in the following PR (that has the camera2 version that breaks this lib): chore(android): native dependency updates to latest version ionic-team/capacitor-barcode-scanner#134
  2. OutSystems O11 Cordova app: https://intranet.outsystems.net/MABS_Lite/BuildDetail?id=f175686a67ba252f5c44d0b77a9055c07898a8d2&stg=dev

Checklist

  • Code follows code style of this project
  • CHANGELOG.md file is correctly updated
  • Changes require an update to the documentation
    • Documentation has been updated accordingly

@OS-pedrogustavobilro
OS-pedrogustavobilro requested a review from a team as a code owner August 3, 2026 12:12
@OS-pedrogustavobilro OS-pedrogustavobilro changed the title fix: only show camera preview after grating permission fix: only show camera preview after granting permission Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant