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

Commit e42da6e1 authored by Avichal Rakesh's avatar Avichal Rakesh
Browse files

Camera2: Optimize CameraDeviceSetup query during openCamera

CameraManager#openCamera currently ended up calling public CameraManager
methods to query for CameraDeviceSetup support. While this was
functionally correct, it led to a few extra binder calls which could
significantly increase the latency of openCamera.

This CL moves those calls to private methods that don't do as much error
checking to improve openCamera's performance.

Bug: 326270391
Test: atest PerformanceTest#testCameraLaunch
Change-Id: If78af62bbb78e6a0acd92eb445a884c17079e8ae
parent 381323ab
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -772,6 +772,16 @@ public final class CameraManager {
                    "CameraDeviceSetup is not supported for Camera ID: " + cameraId);
        }

        return getCameraDeviceSetupUnsafe(cameraId);

    }

    /**
     * Creates and returns a {@link CameraDeviceSetup} instance without any error checking. To
     * be used (carefully) by callers who are sure that CameraDeviceSetup instance can be legally
     * created and don't want to pay the latency cost of calling {@link #getCameraDeviceSetup}.
     */
    private CameraDevice.CameraDeviceSetup getCameraDeviceSetupUnsafe(@NonNull String cameraId) {
        return new CameraDeviceSetupImpl(cameraId, /*cameraManager=*/ this, mContext);
    }

@@ -857,8 +867,9 @@ public final class CameraManager {

            ICameraDeviceUser cameraUser = null;
            CameraDevice.CameraDeviceSetup cameraDeviceSetup = null;
            if (Flags.cameraDeviceSetup() && isCameraDeviceSetupSupported(cameraId)) {
                cameraDeviceSetup = getCameraDeviceSetup(cameraId);
            if (Flags.cameraDeviceSetup()
                    && CameraDeviceSetupImpl.isCameraDeviceSetupSupported(characteristics)) {
                cameraDeviceSetup = getCameraDeviceSetupUnsafe(cameraId);
            }

            android.hardware.camera2.impl.CameraDeviceImpl deviceImpl =