Commit a172baf3 authored by Olle Liljenzin's avatar Olle Liljenzin Committed by Commit Bot

Stop using camera after it was released

We see an increased number of crashes caused by uncaught exceptions
indicating the camera was used after release.

The reported crash is also reproducible on one of our test devices by
opening certain chat pages in the Opera browser.

Using the camera after release() was called is an error, but this
would still happen if Camera#getParameters() fails with an exception
because we would then call release() without nulling the reference
to the released camera instance. Later on we will use the released
instance to close the camera preview, causing a new exception that
will crash the browser as it is not caught.

This change fixes the use-after-release crash by nulling the camera
reference after a failure, to prevent any further usage after the
camera was released.

Bug: 1125083
Change-Id: Ibbf3099636f3e25692fae4799255d04f2cfd4e3d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2527138Reviewed-by: default avatarHenrik Andreasson <henrika@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarMarkus Handell <handellm@google.com>
Commit-Queue: Olle Liljenzin <ollel@opera.com>
Cr-Commit-Position: refs/heads/master@{#825807}
parent d2d57e72
...@@ -509,6 +509,7 @@ public class VideoCaptureCamera ...@@ -509,6 +509,7 @@ public class VideoCaptureCamera
public void getPhotoCapabilitiesAsync(long callbackId) { public void getPhotoCapabilitiesAsync(long callbackId) {
final android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera); final android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera);
if (parameters == null) { if (parameters == null) {
mCamera = null;
VideoCaptureJni.get().onGetPhotoCapabilitiesReply( VideoCaptureJni.get().onGetPhotoCapabilitiesReply(
mNativeVideoCaptureDeviceAndroid, VideoCaptureCamera.this, callbackId, null); mNativeVideoCaptureDeviceAndroid, VideoCaptureCamera.this, callbackId, null);
return; return;
...@@ -695,6 +696,7 @@ public class VideoCaptureCamera ...@@ -695,6 +696,7 @@ public class VideoCaptureCamera
int fillLightMode, boolean hasTorch, boolean torch, double colorTemperature) { int fillLightMode, boolean hasTorch, boolean torch, double colorTemperature) {
android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera); android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera);
if (parameters == null) { if (parameters == null) {
mCamera = null;
return; return;
} }
...@@ -846,12 +848,14 @@ public class VideoCaptureCamera ...@@ -846,12 +848,14 @@ public class VideoCaptureCamera
} }
mPreviewParameters = getCameraParameters(mCamera); mPreviewParameters = getCameraParameters(mCamera);
if (mPreviewParameters == null) { if (mPreviewParameters == null) {
mCamera = null;
notifyTakePhotoError(callbackId); notifyTakePhotoError(callbackId);
return; return;
} }
android.hardware.Camera.Parameters photoParameters = getCameraParameters(mCamera); android.hardware.Camera.Parameters photoParameters = getCameraParameters(mCamera);
if (photoParameters == null) { if (photoParameters == null) {
mCamera = null;
notifyTakePhotoError(callbackId); notifyTakePhotoError(callbackId);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment