-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[camera_android_camerax] Retrieve lens direction from CameraX directly #10847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart
Show resolved
Hide resolved
| 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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;
};There was a problem hiding this comment.
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.
| 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>
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
Changes manual detection of the camera direction via filtering to querying it directly from the camera info.
Fixes flutter/flutter#118730.
Pre-Review Checklist
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).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-assistbot 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
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