[camera_android] Reset AE and AF triggers to idle after capture (#11330) ## Issue App freezes during focus/flash sequence in low light. On high-end camera devices, focusing takes longer in dark environments. Repeatedly requesting focus while using the flash can cause the CaptureRequest to hang. > The [issues](https://github.com/flutter/flutter/issues/97501) has been resolved. > I reproduced the same behavior on a different device (not an Xperia). This log has been captured on my Xperia device. ``` D/CameraCaptureCallback(12647): CameraCaptureCallback | state: STATE_CAPTURING | afState: 1 | aeState: 5 D/CameraCaptureCallback(12647): CameraCaptureCallback | state: STATE_CAPTURING | afState: 1 | aeState: 5 D/CameraCaptureCallback(12647): CameraCaptureCallback | state: STATE_CAPTURING | afState: 5 | aeState: 4 D/CameraCaptureCallback(12647): CameraCaptureCallback | state: STATE_CAPTURING | afState: 5 | aeState: 4 D/CameraCaptureCallback(12647): CameraCaptureCallback | state: STATE_CAPTURING | afState: 1 | aeState: 4 I/Camera (12647): refreshPreviewCaptureSession ``` ## Root Cause Camera2 trigger controls are driven by one-shot states (START), but they are not always reset to IDLE once the sequence is complete. On certain devices (like the Xperia 1), this failure to reset can block subsequent capture requests. ## Fix `runPrecaptureSequence():` Send an AE trigger START, then immediately follow with IDLE in the same execution path. `lockAutoFocus():` Send an AF trigger START, then reset to IDLE after the preview request is captured. ## Results AE/AF triggers are now consistently returned to the IDLE state. The freeze during capture after using the flash on Xperia 1 has been resolved. Camera trigger sequences are now stable across various device models. ------ ### By the way, I believe [CameraX](https://pub.dev/packages/camerax) is the way to go for Android camera development. It's been the default since version 0.11.0. ## 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.
This repo is a companion repo to the main flutter repo. It contains the source code for Flutter's first-party packages (i.e., packages developed by the core Flutter team). Check the packages directory to see all packages.
These packages are also available on pub.
Please file any issues, bugs, or feature requests in the main flutter repo. Issues pertaining to this repository are labeled “package”.
If you wish to contribute a new package to the Flutter ecosystem, please see the documentation for developing packages. You can store your package source code in any GitHub repository (the present repo is only intended for packages developed by the core Flutter team). Once your package is ready you can publish to the pub repository.
If you wish to contribute a change to any of the existing packages in this repo, please review our contribution guide, and send a pull request.
These are the packages hosted in this repository: