[camera] Fix Android autofocus state reading (#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 https://github.com/flutter/flutter/issues/135554
Part of https://github.com/flutter/flutter/issues/84957
This commit is contained in:
stuartmorgan
2023-09-28 11:41:17 -07:00
committed by GitHub
parent 138b4dc024
commit 245a8a086a
4 changed files with 24 additions and 2 deletions

View File

@ -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.

View File

@ -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,

View File

@ -69,4 +69,22 @@ public class CameraCaptureCallbackTest {
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);
}
}

View File

@ -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"