Camera2 legacy: Improve robustness to camera service crashes
When the camera service dies, the getParameters call is often the first to fail, and on legacy mode, this frequently happens in a background thread. Catch the runtime exceptions and convert to device errors, instead of killing the process. Bug: 17587496 Change-Id: I6757961e7c0387defd368a13cb7c343950602400
This commit is contained in:
@@ -336,8 +336,16 @@ public class CameraDeviceUserShim implements ICameraDeviceUser {
|
||||
CameraInfo info = new CameraInfo();
|
||||
Camera.getCameraInfo(cameraId, info);
|
||||
|
||||
Camera.Parameters legacyParameters = null;
|
||||
try {
|
||||
legacyParameters = legacyCamera.getParameters();
|
||||
} catch (RuntimeException e) {
|
||||
throw new CameraRuntimeException(CameraAccessException.CAMERA_ERROR,
|
||||
"Unable to get initial parameters", e);
|
||||
}
|
||||
|
||||
CameraCharacteristics characteristics =
|
||||
LegacyMetadataMapper.createCharacteristics(legacyCamera.getParameters(), info);
|
||||
LegacyMetadataMapper.createCharacteristics(legacyParameters, info);
|
||||
LegacyCameraDevice device = new LegacyCameraDevice(
|
||||
cameraId, legacyCamera, characteristics, threadCallbacks);
|
||||
return new CameraDeviceUserShim(cameraId, device, characteristics, init, threadCallbacks);
|
||||
|
||||
@@ -356,7 +356,14 @@ public class RequestThreadManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
mParams = mCamera.getParameters();
|
||||
try {
|
||||
mParams = mCamera.getParameters();
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "Received device exception: ", e);
|
||||
mDeviceState.setError(
|
||||
CameraDeviceImpl.CameraDeviceCallbacks.ERROR_CAMERA_DEVICE);
|
||||
return;
|
||||
}
|
||||
|
||||
List<int[]> supportedFpsRanges = mParams.getSupportedPreviewFpsRange();
|
||||
int[] bestRange = getPhotoPreviewFpsRange(supportedFpsRanges);
|
||||
@@ -780,7 +787,14 @@ public class RequestThreadManager {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Params changed -- getting new Parameters from HAL.");
|
||||
}
|
||||
mParams = mCamera.getParameters();
|
||||
try {
|
||||
mParams = mCamera.getParameters();
|
||||
} catch (RuntimeException e) {
|
||||
Log.e(TAG, "Received device exception: ", e);
|
||||
mDeviceState.setError(
|
||||
CameraDeviceImpl.CameraDeviceCallbacks.ERROR_CAMERA_DEVICE);
|
||||
break;
|
||||
}
|
||||
|
||||
// Update parameters to the latest that we think the camera is using
|
||||
mLastRequest.setParameters(mParams);
|
||||
|
||||
Reference in New Issue
Block a user