Skip to content

Conversation

@camsim99
Copy link
Contributor

@camsim99 camsim99 commented Jan 21, 2026

Changes manual detection of the camera direction via filtering to querying it directly from the camera info.

Fixes flutter/flutter#118730.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@camsim99 camsim99 changed the title [camera_android_camerax] Retrieve lens direction from CameraX directly instead of guessing [camera_android_camerax] Retrieve lens direction from CameraX directly Jan 23, 2026
@camsim99 camsim99 marked this pull request as ready for review January 29, 2026 21:08
@camsim99 camsim99 requested review from a team and jesswrd January 29, 2026 21:09
Copy link

@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 refactors the camera lens direction detection by querying it directly from CameraX's CameraInfo instead of using a manual filtering workaround. This simplifies the code, removes a TODO, and improves maintainability. The changes are consistently applied across Dart and native Android code, including updates to pigeon files and tests.

I've found a critical issue in the Dart code where break statements are missing in a switch block, which will cause incorrect behavior. I've also provided a couple of suggestions to modernize the Java code by using switch expressions for better readability. Overall, this is a valuable simplification, and with the suggested fixes, it will be a great improvement.

Comment on lines +32 to +42
int lensFacing = pigeonInstance.getLensFacing();
switch (lensFacing) {
case CameraSelector.LENS_FACING_FRONT:
return LensFacing.FRONT;
case CameraSelector.LENS_FACING_BACK:
return LensFacing.BACK;
case CameraSelector.LENS_FACING_EXTERNAL:
return LensFacing.EXTERNAL;
default:
return LensFacing.UNKNOWN;
}

Choose a reason for hiding this comment

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

medium

For improved conciseness and readability, you can use a Java switch expression here, as the project's Java version supports it. This modern language feature can make the code more streamlined.

    return switch (pigeonInstance.getLensFacing()) {
      case CameraSelector.LENS_FACING_FRONT -> LensFacing.FRONT;
      case CameraSelector.LENS_FACING_BACK -> LensFacing.BACK;
      case CameraSelector.LENS_FACING_EXTERNAL -> LensFacing.EXTERNAL;
      default -> LensFacing.UNKNOWN;
    };

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indifferent. Also I think our formatter is too outdated for this, so this would require an update to that tool. Tried this locally and I get errors.

Comment on lines +48 to +62
LensFacing expected;
switch (testedLensFacingValue) {
case CameraSelector.LENS_FACING_BACK:
expected = LensFacing.BACK;
break;
case CameraSelector.LENS_FACING_FRONT:
expected = LensFacing.FRONT;
break;
case CameraSelector.LENS_FACING_EXTERNAL:
expected = LensFacing.EXTERNAL;
break;
default:
expected = LensFacing.UNKNOWN;
break;
}

Choose a reason for hiding this comment

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

medium

Similar to the implementation in CameraInfoProxyApi, you can use a Java switch expression here in the test to make the code more concise and readable. This also helps keep the test code style consistent with the implementation.

      LensFacing expected = 
          switch (testedLensFacingValue) {
            case CameraSelector.LENS_FACING_BACK -> LensFacing.BACK;
            case CameraSelector.LENS_FACING_FRONT -> LensFacing.FRONT;
            case CameraSelector.LENS_FACING_EXTERNAL -> LensFacing.EXTERNAL;
            default -> LensFacing.UNKNOWN;
          };

Co-authored-by: Gray Mackall <34871572+gmackall@users.noreply.github.com>
@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Jan 29, 2026
@auto-submit auto-submit bot merged commit d878913 into flutter:main Jan 29, 2026
81 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 30, 2026
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Jan 30, 2026
flutter/packages@cd4fd61...510dd40

2026-01-30 engine-flutter-autoroll@skia.org Roll Flutter (stable) from
bd7a4a6 to 67323de (3 revisions) (flutter/packages#10924)
2026-01-29 engine-flutter-autoroll@skia.org Roll Flutter from
dfd92b7 to da72d59 (39 revisions) (flutter/packages#10923)
2026-01-29 43054281+camsim99@users.noreply.github.com
[camera_android_camerax] Retrieve lens direction from CameraX directly
(flutter/packages#10847)
2026-01-29 stuartmorgan@google.com [tool] Adjust error message when
`downgrade` fails (flutter/packages#10734)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App p: camera platform-android

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[camera] Modify availableCameras() to use CameraInfo.getLensFacing()

2 participants