Skip to content

Conversation

@jesswrd
Copy link
Contributor

@jesswrd jesswrd commented Jul 24, 2025

Fixed camera switching issue where phones with multiple back cameras could not correctly switch to some other chosen camera. Fixed by specifying a camera via its CameraInfo instead of its direction.

Fixes flutter/flutter#164963

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

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 effectively fixes the camera switching bug by introducing a more robust selection mechanism using CameraInfo. The changes are well-distributed across the Dart and native Android code. I've provided a few suggestions to improve code clarity, maintainability, and test correctness. Once these are addressed, this PR should be in great shape.

Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

Overall looks good! Left some comments.

case null:
}

if (cameraInfo != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think to make sure this tests does what we want, we need to check if cameraInfo is the CameraInfo that maps to cameraDescriptions[0], so we need a tighter check here. Please correct me if I'm wrong though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done. Also, I did sort of a "transitive verification." I can't access the CameraInfo that maps to cameraDescriptions[0] directly in the conditional stub check due to timing issues, so I directly check that cameraInfo is mockBackCameraInfoOne. I verify that mockBackCameraInfoOne is associated with cameraDescriptions[0] below.

      // Verify the camera name used to create camera is associated with mockBackCameraInfoOne.
      expect(
        cameraNameToInfos[cameraDescriptions[0].name],
        mockBackCameraInfoOne,
      );

@jesswrd jesswrd requested a review from camsim99 July 29, 2025 19:32
Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

LGTM :)

@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 30, 2025
@auto-submit auto-submit bot merged commit 7a9e9ce into flutter:main Jul 30, 2025
80 checks passed
vashworth pushed a commit to vashworth/packages that referenced this pull request Jul 30, 2025
Fixed camera switching issue where phones with multiple back cameras could not correctly switch to some other chosen camera. Fixed by specifying a camera via its CameraInfo instead of its direction.

Fixes flutter/flutter#164963

## Pre-Review Checklist

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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.

[^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.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jul 31, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Jul 31, 2025
ksokolovskyi pushed a commit to ksokolovskyi/flutter that referenced this pull request Aug 19, 2025
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
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_android_camerax] Camera switching not working correctly

2 participants