Skip to content

camera_android: Camera.java pausePreview null check #5265

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 12 commits into from
Nov 28, 2023
4 changes: 3 additions & 1 deletion packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 0.10.8+14

* Fixes `pausePreview` null pointer error. `pausePreview` should not be called
when camera is closed or not configured.
* Updates minimum supported SDK version to Flutter 3.10/Dart 3.0.

## 0.10.8+13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1076,8 +1076,13 @@ public void unlockCaptureOrientation() {

/** Pause the preview from dart. */
public void pausePreview() throws CameraAccessException {
this.pausedPreview = true;
this.captureSession.stopRepeating();
if (!this.pausedPreview) {
this.pausedPreview = true;

if (this.captureSession != null) {
this.captureSession.stopRepeating();
}
}
}

/** Resume the preview from dart. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,19 @@ public void close_doesNotCloseCaptureSessionWhenCameraDeviceNonNull() {
verify(mockCaptureSession, never()).close();
}

@Test
public void pausePreview_doesNotCallStopRepeatingWhenCameraClosed() throws CameraAccessException {
ArrayList<CaptureRequest.Builder> mockRequestBuilders = new ArrayList<>();
mockRequestBuilders.add(mock(CaptureRequest.Builder.class));
CameraDeviceWrapper fakeCamera = new FakeCameraDeviceWrapper(mockRequestBuilders);
TestUtils.setPrivateField(camera, "cameraDevice", fakeCamera);

camera.close();
camera.pausePreview();

verify(mockCaptureSession, never()).stopRepeating();
}

private static class TestCameraFeatureFactory implements CameraFeatureFactory {
private final AutoFocusFeature mockAutoFocusFeature;
private final ExposureLockFeature mockExposureLockFeature;
Expand Down
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+13
version: 0.10.8+14

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