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

Commit 05e93a58 authored by Mohammed Althaf T's avatar Mohammed Althaf T 😊
Browse files

camera: Use openLegacy() for older HAL1 devices

- We have seperate checks for APIs
parent 9f3a3f57
Loading
Loading
Loading
Loading
+20 −6
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import android.view.TextureView;
import net.sourceforge.opencamera.MyDebug;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
@@ -58,15 +59,28 @@ public class CameraController1 extends CameraController {
        if( MyDebug.LOG )
            Log.d(TAG, "create new CameraController1: " + cameraId);
        this.camera_error_cb = camera_error_cb;

        try {
            camera = Camera.open(cameraId);
            Method openMethod = Class.forName("android.hardware.Camera")
                    .getMethod("openLegacy", int.class, int.class);
            camera = (Camera) openMethod.invoke(null,
                    cameraId, 0x100);
        } catch (Exception e) {
            /* Retry with open if openLegacy doesn't exist/fails */
            camera = null;
        }
        catch(RuntimeException e) {

        if (camera == null) {
            try {
                camera = Camera.open(cameraId);
            } catch (RuntimeException e) {
                if (MyDebug.LOG)
                    Log.e(TAG, "failed to open camera");
                e.printStackTrace();
                throw new CameraControllerException();
            }
        }

        if( camera == null ) {
            // Although the documentation says Camera.open() should throw a RuntimeException, it seems that it some cases it can return null
            // I've seen this in some crashes reported in Google Play; also see: