Skip to content

Commit 245a8a0

Browse files
[camera] Fix Android autofocus state reading (flutter#5025)
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#135554 Part of flutter#84957
1 parent 138b4dc commit 245a8a0

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

packages/camera/camera_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.8+12
2+
3+
* Fixes handling of autofocus state when taking a picture.
4+
15
## 0.10.8+11
26

37
* Downgrades AGP version for compatibility with legacy projects.

packages/camera/camera_android/android/src/main/java/io/flutter/plugins/camera/CameraCaptureCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class CameraCaptureCallback extends CaptureCallback {
3131
CaptureResult.Key<Integer> aeStateKey = CaptureResult.CONTROL_AE_STATE;
3232

3333
@VisibleForTesting @NonNull
34-
CaptureResult.Key<Integer> afStateKey = CaptureResult.CONTROL_AE_STATE;
34+
CaptureResult.Key<Integer> afStateKey = CaptureResult.CONTROL_AF_STATE;
3535

3636
private CameraCaptureCallback(
3737
@NonNull CameraCaptureStateListener cameraStateListener,

packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/CameraCaptureCallbackTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,22 @@ public void onCaptureCompleted_updatesCameraCaptureProperties() {
6969
verify(mockCaptureProps, times(1)).setLastSensorExposureTime(2L);
7070
verify(mockCaptureProps, times(1)).setLastSensorSensitivity(3);
7171
}
72+
73+
@Test
74+
public void onCaptureCompleted_checksBothAutoFocusAndAutoExposure() {
75+
CameraCaptureSession mockSession = mock(CameraCaptureSession.class);
76+
CaptureRequest mockRequest = mock(CaptureRequest.class);
77+
TotalCaptureResult mockResult = mock(TotalCaptureResult.class);
78+
79+
cameraCaptureCallback.onCaptureCompleted(mockSession, mockRequest, mockResult);
80+
81+
// This is inherently somewhat fragile since it is testing internal implementation details,
82+
// but it is important to test that the code is actually using both of the expected states
83+
// since it's easy to typo one of these constants as the other. Ideally this would be tested
84+
// via the state machine output (CameraCaptureCallbackStatesTest.java), but testing the state
85+
// machine requires overriding the keys, so can't test that the right real keys are used in
86+
// production.
87+
verify(mockResult, times(1)).get(CaptureResult.CONTROL_AE_STATE);
88+
verify(mockResult, times(1)).get(CaptureResult.CONTROL_AF_STATE);
89+
}
7290
}

packages/camera/camera_android/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Android implementation of the camera plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
55

6-
version: 0.10.8+11
6+
version: 0.10.8+12
77

88
environment:
99
sdk: ">=2.19.0 <4.0.0"

0 commit comments

Comments
 (0)