Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eecc904f authored by Eino-Ville Talvala's avatar Eino-Ville Talvala
Browse files

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
parent 33ae07ab
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -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);
+16 −2
Original line number Diff line number Diff line
@@ -356,7 +356,14 @@ public class RequestThreadManager {
                }
            }
        }
        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.");
                            }
                            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);