Skip to content

Fix crash on single-lens devices by validating initial lens facing#474

Merged
temcguir merged 5 commits intomainfrom
temcguir/fix_single_front_camera_crash
Feb 12, 2026
Merged

Fix crash on single-lens devices by validating initial lens facing#474
temcguir merged 5 commits intomainfrom
temcguir/fix_single_front_camera_crash

Conversation

@temcguir
Copy link
Collaborator

Previously, the app could crash if the stored or default preference
was set to a lens (e.g., BACK) that did not exist on the device
(e.g., a front-facing only device).

This change adds a validation step during CameraXCameraSystem
initialization:

  • It checks if the requested cameraLensFacing is actually
    present in the list of available lenses.
  • If the requested lens is unavailable, it falls back to the first
    available lens found.
  • Updates usage of cameraAppSettings to validatedAppSettings
    when generating illuminants and applying constraints to ensure
    consistency throughout the initialization flow.

This ensures the app starts correctly on devices with restricted
camera configurations or single-lens setups.

 This tests that the camera can start and the switch camera button
 is disabled when it only has a single lens.
Previously, the app could crash if the stored or default preference
was set to a lens (e.g., BACK) that did not exist on the device
(e.g., a front-facing only device).

This change adds a validation step during `CameraXCameraSystem`
initialization:
*   It checks if the requested `cameraLensFacing` is actually
    present in the list of available lenses.
*   If the requested lens is unavailable, it falls back to the first
    available lens found.
*   Updates usage of `cameraAppSettings` to `validatedAppSettings`
    when generating illuminants and applying constraints to ensure
    consistency throughout the initialization flow.

This ensures the app starts correctly on devices with restricted
camera configurations or single-lens setups.
@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@temcguir
Copy link
Collaborator Author

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses a crash on devices with single or non-standard camera configurations by validating the lens facing preference during initialization. The core logic change in CameraXCameraSystem is sound, ensuring the app falls back to an available lens if the preferred one is missing. The addition of SingleLensModeTest provides good test coverage for this scenario, and the refactoring in UiTestUtil improves code clarity. I have one minor suggestion to make the validation logic in CameraXCameraSystem slightly more idiomatic.

@temcguir temcguir enabled auto-merge (squash) February 12, 2026 20:10
@temcguir temcguir merged commit d2d6f15 into main Feb 12, 2026
8 checks passed
@temcguir temcguir deleted the temcguir/fix_single_front_camera_crash branch February 12, 2026 20:38
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.

2 participants