Skip to content

Commit

Permalink
[camera] Fix Android autofocus state reading (#5025)
Browse files Browse the repository at this point in the history
Fixes a typo introduced during a testability refactor that caused the capture state machine to read the wrong value for autofocus state, breaking the state machine.

Fixes flutter/flutter#135554
Part of flutter/flutter#84957
  • Loading branch information
stuartmorgan authored Sep 28, 2023
1 parent 138b4dc commit 245a8a0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
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

0 comments on commit 245a8a0

Please sign in to comment.