Skip to content

fix(scanner): fall back to any camera when there is no back camera - #1752

Merged
bmc08gt merged 3 commits into
code/cashfrom
fix/scanner-camera-fallback
Oct 10, 2026
Merged

bmc08gt merged 3 commits into
code/cashfrom
fix/scanner-camera-fallback

Conversation

@bmc08gt

@bmc08gt bmc08gt commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

The scanner required LENS_FACING_BACK. An Infinix X688B exposes a single camera to CameraX and reports it as front facing, so every bind threw IllegalArgumentException: No available camera can be found. bindWithRetry tried three times, a second apart, and the user got a blank preview. Each return to the screen repeated it: 9 events on 2026.10.2 (Bugsnag 6aca4823396a2e952015e21d).

  • CodeScanner.kt: choose the camera at bind time. Use the back camera when there is one, otherwise the first camera the device exposes. A code held up to a front camera still scans.
  • bindWithRetry: don't retry IllegalArgumentException. CameraX throws it when no camera matches or the use cases can't be combined, and neither changes between attempts.
  • On a front-camera fallback the scan screen shows a floating toast once: "No back camera found. Using your front camera" It takes no input, so the scanner stays usable under it.
  • No camera at all now fails with NoCamerasAvailableException, so Scanner.kt shows the unavailable state. That case is no longer sent to ErrorUtils.handleError, since it describes the device rather than a bug.

The front-camera preview is mirrored. Analysis runs on the raw frames, but Kik code decoding on a front camera hasn't been tried.

ScannerCameraSelectionTest covers the camera choice and the retry behaviour.

The scanner required LENS_FACING_BACK. An Infinix X688B exposes one camera
to CameraX and reports it as front facing, so every bind threw
IllegalArgumentException("No available camera can be found"), was retried
three times a second apart, and left a blank preview (Bugsnag
6aca4823396a2e952015e21d, 9 events on 2026.10.2).

Prefer the back camera and otherwise bind the first camera the device
exposes. Stop retrying IllegalArgumentException, which doesn't change
between attempts. A device with no camera now fails with
NoCamerasAvailableException, which shows the unavailable state and is no
longer reported as an error.
@bmc08gt bmc08gt self-assigned this Oct 10, 2026
@github-actions github-actions Bot added type: fix Bug fix area: ui Compose UI, theme, components, resources area: scanner QR/Kikcode scanning, camera and removed type: fix Bug fix labels Oct 10, 2026
When the device has no back camera, CodeScanner reports the front-camera
fallback and the scan screen shows a floating toast, once per scanner:
"No back camera found. Using your front camera."
@github-actions github-actions Bot added the type: fix Bug fix label Oct 10, 2026
@bmc08gt
bmc08gt merged commit 6bed84a into code/cash Oct 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: scanner QR/Kikcode scanning, camera area: ui Compose UI, theme, components, resources type: fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant