Commit 7f63b1f8 authored by Christian Fremerey's avatar Christian Fremerey Committed by Commit Bot

[Video Capture, Android] Fix more nullptr exceptions

Method getCameraParameters() in file VideoCaptureCamera.java may return
null on failure. But several call sites assume that this never happens.
Crash reports show that it does happen.

This CL adds null checks and performs the appropriate failure action.

Bug: 879678
Change-Id: I978f45c04696c9a5b272932a945da033bafc6a77
Reviewed-on: https://chromium-review.googlesource.com/1214072Reviewed-by: default avatarEmircan Uysaler <emircan@chromium.org>
Commit-Queue: Christian Fremerey <chfremer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590007}
parent e5428390
......@@ -75,7 +75,8 @@ public abstract class VideoCapture {
@CalledByNative
public abstract boolean stopCaptureAndBlockUntilStopped();
// Replies by calling nativeOnGetPhotoCapabilitiesReply().
// Replies by calling nativeOnGetPhotoCapabilitiesReply(). Will pass |null|
// for parameter |result| to indicate failure.
@CalledByNative
public abstract void getPhotoCapabilitiesAsync(long callbackId);
......
......@@ -484,6 +484,10 @@ public class VideoCaptureCamera
@Override
public void getPhotoCapabilitiesAsync(long callbackId) {
final android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera);
if (parameters == null) {
nativeOnGetPhotoCapabilitiesReply(mNativeVideoCaptureDeviceAndroid, callbackId, null);
return;
}
PhotoCapabilities.Builder builder = new PhotoCapabilities.Builder();
Log.i(TAG, " CAM params: %s", parameters.flatten());
......@@ -646,6 +650,9 @@ public class VideoCaptureCamera
double iso, boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMode,
boolean hasTorch, boolean torch, double colorTemperature) {
android.hardware.Camera.Parameters parameters = getCameraParameters(mCamera);
if (parameters == null) {
return;
}
if (parameters.isZoomSupported() && zoom > 0) {
// |zoomRatios| is an ordered list; need the closest zoom index for parameters.setZoom()
......@@ -794,8 +801,16 @@ public class VideoCaptureCamera
mPhotoTakenCallbackId = callbackId;
}
mPreviewParameters = getCameraParameters(mCamera);
if (mPreviewParameters == null) {
notifyTakePhotoError(callbackId);
return;
}
android.hardware.Camera.Parameters photoParameters = getCameraParameters(mCamera);
if (photoParameters == null) {
notifyTakePhotoError(callbackId);
return;
}
photoParameters.setRotation(getCameraRotation());
if (mPhotoWidth > 0 || mPhotoHeight > 0) {
......
......@@ -385,6 +385,10 @@ void VideoCaptureDeviceAndroid::OnGetPhotoCapabilitiesReply(
NOTREACHED() << "|callback_id| not found.";
return;
}
if (result == nullptr) {
get_photo_state_callbacks_.erase(reference_it);
return;
}
base::android::ScopedJavaLocalRef<jobject> scoped_photo_capabilities(env,
result);
......
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