Skip to content

[camera] Fix Android autofocus state reading #5025

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

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.8+12

* Fixes handling of autofocus state when taking a picture.

## 0.10.8+11

* Downgrades AGP version for compatibility with legacy projects.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CameraCaptureCallback extends CaptureCallback {
CaptureResult.Key<Integer> aeStateKey = CaptureResult.CONTROL_AE_STATE;

@VisibleForTesting @NonNull
CaptureResult.Key<Integer> afStateKey = CaptureResult.CONTROL_AE_STATE;
CaptureResult.Key<Integer> afStateKey = CaptureResult.CONTROL_AF_STATE;

private CameraCaptureCallback(
@NonNull CameraCaptureStateListener cameraStateListener,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,22 @@ public void onCaptureCompleted_updatesCameraCaptureProperties() {
verify(mockCaptureProps, times(1)).setLastSensorExposureTime(2L);
verify(mockCaptureProps, times(1)).setLastSensorSensitivity(3);
}

@Test
public void onCaptureCompleted_checksBothAutoFocusAndAutoExposure() {
CameraCaptureSession mockSession = mock(CameraCaptureSession.class);
CaptureRequest mockRequest = mock(CaptureRequest.class);
TotalCaptureResult mockResult = mock(TotalCaptureResult.class);

cameraCaptureCallback.onCaptureCompleted(mockSession, mockRequest, mockResult);

// This is inherently somewhat fragile since it is testing internal implementation details,
// but it is important to test that the code is actually using both of the expected states
// since it's easy to typo one of these constants as the other. Ideally this would be tested
// via the state machine output (CameraCaptureCallbackStatesTest.java), but testing the state
// machine requires overriding the keys, so can't test that the right real keys are used in
// production.
verify(mockResult, times(1)).get(CaptureResult.CONTROL_AE_STATE);
verify(mockResult, times(1)).get(CaptureResult.CONTROL_AF_STATE);
}
}
2 changes: 1 addition & 1 deletion packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Android implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22

version: 0.10.8+11
version: 0.10.8+12

environment:
sdk: ">=2.19.0 <4.0.0"
Expand Down