fix(android): Fix Android Camera1 race condition crash (#2781)

* add synchronized to take pictures callback in case camera was already stopped.

This will also prevent a possible null camera object.

* use our mCamera variable instead of the one received in the callback so we know if it has been disposed.

Co-authored-by: Cristiano Coelho <cristianocca@hotmail.com>
This commit is contained in:
cristianoccazinsp 2020-04-08 17:51:27 -03:00 committed by GitHub
parent bfe04aaec8
commit 85b951ced1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -760,16 +760,23 @@ class Camera1 extends CameraViewImpl implements MediaRecorder.OnInfoListener,
sound.play(MediaActionSound.SHUTTER_CLICK);
}
if (options.hasKey("pauseAfterCapture") && !options.getBoolean("pauseAfterCapture")) {
camera.startPreview();
mIsPreviewActive = true;
if (mIsScanning) {
camera.setPreviewCallback(Camera1.this);
// our camera might have been released
// when this callback fires, so make sure we have
// exclusive access when restoring its preview
synchronized(Camera1.this){
if(mCamera != null){
if (options.hasKey("pauseAfterCapture") && !options.getBoolean("pauseAfterCapture")) {
mCamera.startPreview();
mIsPreviewActive = true;
if (mIsScanning) {
mCamera.setPreviewCallback(Camera1.this);
}
} else {
mCamera.stopPreview();
mIsPreviewActive = false;
mCamera.setPreviewCallback(null);
}
}
} else {
camera.stopPreview();
mIsPreviewActive = false;
camera.setPreviewCallback(null);
}
isPictureCaptureInProgress.set(false);