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

Commit d6ebc55e authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Defer retrieval of camera ids and capabilities until in video call.

- The InCallCameraManager used to call initializeCameraList on startup.
- Delayed this until getActiveCameraId() is called,

Bug: 20993325
Change-Id: Ia8cf16c621650fd4adafa2c506a0021a0f63a6f8
parent 4296169f
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -57,14 +57,15 @@ public class InCallCameraManager {
    private boolean mUseFrontFacingCamera;

    /**
     * Aspect ratio of the front facing camera.
     * Indicates whether the list of cameras has been initialized yet.  Initialization is delayed
     * until a video call is present.
     */
    private float mFrontFacingCameraAspectRatio;
    private boolean mIsInitialized = false;

    /**
     * Aspect ratio of the rear facing camera.
     * The context.
     */
    private float mRearFacingCameraAspectRatio;
    private Context mContext;

    /**
     * Initializes the InCall CameraManager.
@@ -73,7 +74,7 @@ public class InCallCameraManager {
     */
    public InCallCameraManager(Context context) {
        mUseFrontFacingCamera = true;
        initializeCameraList(context);
        mContext = context;
    }

    /**
@@ -103,6 +104,8 @@ public class InCallCameraManager {
     * @return The active camera ID.
     */
    public String getActiveCameraId() {
        maybeInitializeCameraList(mContext);

        if (mUseFrontFacingCamera) {
            return mFrontFacingCameraId;
        } else {
@@ -111,15 +114,17 @@ public class InCallCameraManager {
    }

    /**
     * Get the camera ID and aspect ratio for the front and rear cameras.
     * Get the list of cameras available for use.
     *
     * @param context The context.
     */
    private void initializeCameraList(Context context) {
        if (context == null) {
    private void maybeInitializeCameraList(Context context) {
        if (mIsInitialized || context == null) {
            return;
        }

        Log.v(this, "initializeCameraList");

        CameraManager cameraManager = null;
        try {
            cameraManager = (CameraManager) context.getSystemService(
@@ -160,6 +165,9 @@ public class InCallCameraManager {
                }
            }
        }

        mIsInitialized = true;
        Log.v(this, "initializeCameraList : done");
    }

    public void addCameraSelectionListener(Listener listener) {
+12 −10
Original line number Diff line number Diff line
@@ -489,20 +489,22 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
                + " hasCallStateChanged=" +
                hasCallStateChanged + " isVideoMode=" + isVideoMode());

        if (!hasCallStateChanged) { return; }
        if (!hasCallStateChanged) {
            return;
        }

        if (isVideoCall) {
            final InCallCameraManager cameraManager = InCallPresenter.getInstance().
                    getInCallCameraManager();

            String prevCameraId = cameraManager.getActiveCameraId();

            updateCameraSelection(call);

            String newCameraId = cameraManager.getActiveCameraId();

            if (!Objects.equals(prevCameraId, newCameraId) && CallUtils.isActiveVideoCall(call)) {
                enableCamera(call.getVideoCall(), true);
            }
        }

        // Make sure we hide or show the video UI if needed.
        showVideoUi(call.getVideoState(), call.getState());