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

Commit 79d4a4c1 authored by Eino-Ville Talvala's avatar Eino-Ville Talvala Committed by Android (Google) Code Review
Browse files

Merge "Camera: Remove all camera HALv1 code"

parents d8e4cdc6 7208d0af
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -42424,10 +42424,6 @@ Landroid/hardware/camera2/impl/CameraMetadataNative$Key;
Landroid/hardware/camera2/impl/CameraMetadataNative;
Landroid/hardware/camera2/impl/GetCommand;
Landroid/hardware/camera2/impl/SetCommand;
Landroid/hardware/camera2/legacy/LegacyCameraDevice;
Landroid/hardware/camera2/legacy/LegacyExceptionUtils$BufferQueueAbandonedException;
Landroid/hardware/camera2/legacy/LegacyMetadataMapper;
Landroid/hardware/camera2/legacy/PerfMeasurement;
Landroid/hardware/camera2/marshal/MarshalHelpers;
Landroid/hardware/camera2/marshal/MarshalQueryable;
Landroid/hardware/camera2/marshal/MarshalRegistry$MarshalToken;
+0 −4
Original line number Diff line number Diff line
@@ -2297,10 +2297,6 @@ android.hardware.camera2.impl.CameraMetadataNative$Key
android.hardware.camera2.impl.CameraMetadataNative
android.hardware.camera2.impl.GetCommand
android.hardware.camera2.impl.SetCommand
android.hardware.camera2.legacy.LegacyCameraDevice
android.hardware.camera2.legacy.LegacyExceptionUtils$BufferQueueAbandonedException
android.hardware.camera2.legacy.LegacyMetadataMapper
android.hardware.camera2.legacy.PerfMeasurement
android.hardware.camera2.marshal.MarshalHelpers
android.hardware.camera2.marshal.MarshalQueryable
android.hardware.camera2.marshal.MarshalRegistry$MarshalToken
+11 −73
Original line number Diff line number Diff line
@@ -249,14 +249,10 @@ public class Camera {
    public static final int CAMERA_HAL_API_VERSION_1_0 = 0x100;

    /**
     * A constant meaning the normal camera connect/open will be used.
     */
    private static final int CAMERA_HAL_API_VERSION_NORMAL_CONNECT = -2;

    /**
     * Used to indicate HAL version un-specified.
     * Camera HAL device API version 3.0
     * @hide
     */
    private static final int CAMERA_HAL_API_VERSION_UNSPECIFIED = -1;
    public static final int CAMERA_HAL_API_VERSION_3_0 = 0x300;

    /**
     * Hardware face detection. It does not use much CPU.
@@ -427,7 +423,7 @@ public class Camera {
     * Creates a new Camera object to access a particular hardware camera with
     * given hal API version. If the same camera is opened by other applications
     * or the hal API version is not supported by this device, this will throw a
     * RuntimeException.
     * RuntimeException. As of Android 12, HAL version 1 is no longer supported.
     * <p>
     * You must call {@link #release()} when you are done using the camera,
     * otherwise it will remain locked and be unavailable to other applications.
@@ -463,49 +459,14 @@ public class Camera {
     */
    @UnsupportedAppUsage
    public static Camera openLegacy(int cameraId, int halVersion) {
        if (halVersion < CAMERA_HAL_API_VERSION_1_0) {
            throw new IllegalArgumentException("Invalid HAL version " + halVersion);
        if (halVersion < CAMERA_HAL_API_VERSION_3_0) {
            throw new IllegalArgumentException("Unsupported HAL version " + halVersion);
        }

        return new Camera(cameraId, halVersion);
    }

    /**
     * Create a legacy camera object.
     *
     * @param cameraId The hardware camera to access, between 0 and
     * {@link #getNumberOfCameras()}-1.
     * @param halVersion The HAL API version this camera device to be opened as.
     */
    private Camera(int cameraId, int halVersion) {
        int err = cameraInitVersion(cameraId, halVersion);
        if (checkInitErrors(err)) {
            if (err == -EACCES) {
                throw new RuntimeException("Fail to connect to camera service");
            } else if (err == -ENODEV) {
                throw new RuntimeException("Camera initialization failed");
            } else if (err == -ENOSYS) {
                throw new RuntimeException("Camera initialization failed because some methods"
                        + " are not implemented");
            } else if (err == -EOPNOTSUPP) {
                throw new RuntimeException("Camera initialization failed because the hal"
                        + " version is not supported by this device");
            } else if (err == -EINVAL) {
                throw new RuntimeException("Camera initialization failed because the input"
                        + " arugments are invalid");
            } else if (err == -EBUSY) {
                throw new RuntimeException("Camera initialization failed because the camera"
                        + " device was already opened");
            } else if (err == -EUSERS) {
                throw new RuntimeException("Camera initialization failed because the max"
                        + " number of camera devices were already opened");
            }
            // Should never hit this.
            throw new RuntimeException("Unknown camera error");
        }
        return new Camera(cameraId);
    }

    private int cameraInitVersion(int cameraId, int halVersion) {
    private int cameraInit(int cameraId) {
        mShutterCallback = null;
        mRawImageCallback = null;
        mJpegCallback = null;
@@ -523,35 +484,13 @@ public class Camera {
            mEventHandler = null;
        }

        return native_setup(new WeakReference<Camera>(this), cameraId, halVersion,
        return native_setup(new WeakReference<Camera>(this), cameraId,
                ActivityThread.currentOpPackageName());
    }

    private int cameraInitNormal(int cameraId) {
        return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_NORMAL_CONNECT);
    }

    /**
     * Connect to the camera service using #connectLegacy
     *
     * <p>
     * This acts the same as normal except that it will return
     * the detailed error code if open fails instead of
     * converting everything into {@code NO_INIT}.</p>
     *
     * <p>Intended to use by the camera2 shim only, do <i>not</i> use this for other code.</p>
     *
     * @return a detailed errno error code, or {@code NO_ERROR} on success
     *
     * @hide
     */
    public int cameraInitUnspecified(int cameraId) {
        return cameraInitVersion(cameraId, CAMERA_HAL_API_VERSION_UNSPECIFIED);
    }

    /** used by Camera#open, Camera#open(int) */
    Camera(int cameraId) {
        int err = cameraInitNormal(cameraId);
        int err = cameraInit(cameraId);
        if (checkInitErrors(err)) {
            if (err == -EACCES) {
                throw new RuntimeException("Fail to connect to camera service");
@@ -616,8 +555,7 @@ public class Camera {
    }

    @UnsupportedAppUsage
    private native final int native_setup(Object camera_this, int cameraId, int halVersion,
                                           String packageName);
    private native int native_setup(Object cameraThis, int cameraId, String packageName);

    private native final void native_release();

+18 −95
Original line number Diff line number Diff line
@@ -23,14 +23,11 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.content.Context;
import android.hardware.CameraInfo;
import android.hardware.CameraStatus;
import android.hardware.ICameraService;
import android.hardware.ICameraServiceListener;
import android.hardware.camera2.impl.CameraDeviceImpl;
import android.hardware.camera2.impl.CameraMetadataNative;
import android.hardware.camera2.legacy.CameraDeviceUserShim;
import android.hardware.camera2.legacy.LegacyMetadataMapper;
import android.hardware.camera2.params.SessionConfiguration;
import android.hardware.camera2.utils.CameraIdAndSessionConfiguration;
import android.hardware.camera2.utils.ConcurrentCameraIdCombination;
@@ -405,10 +402,6 @@ public final class CameraManager {
            throw new IllegalArgumentException("No cameras available on device");
        }
        synchronized (mLock) {
            /*
             * Get the camera characteristics from the camera service directly if it supports it,
             * otherwise get them from the legacy shim instead.
             */
            ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
            if (cameraService == null) {
                throw new CameraAccessException(CameraAccessException.CAMERA_DISCONNECTED,
@@ -417,26 +410,10 @@ public final class CameraManager {
            try {
                Size displaySize = getDisplaySize();

                // First check isHiddenPhysicalCamera to avoid supportsCamera2ApiLocked throwing
                // exception in case cameraId is a hidden physical camera.
                if (!isHiddenPhysicalCamera(cameraId) && !supportsCamera2ApiLocked(cameraId)) {
                    // Legacy backwards compatibility path; build static info from the camera
                    // parameters
                    int id = Integer.parseInt(cameraId);

                    String parameters = cameraService.getLegacyParameters(id);

                    CameraInfo info = cameraService.getCameraInfo(id);

                    characteristics = LegacyMetadataMapper.createCharacteristics(parameters, info,
                            id, displaySize);
                } else {
                    // Normal path: Get the camera characteristics directly from the camera service
                CameraMetadataNative info = cameraService.getCameraCharacteristics(cameraId);
                try {
                    info.setCameraId(Integer.parseInt(cameraId));
                } catch (NumberFormatException e) {
                        // For external camera, reaching here is expected.
                    Log.v(TAG, "Failed to parse camera Id " + cameraId + " to integer");
                }
                boolean hasConcurrentStreams =
@@ -444,7 +421,7 @@ public final class CameraManager {
                info.setHasMandatoryConcurrentStreams(hasConcurrentStreams);
                info.setDisplaySize(displaySize);
                characteristics = new CameraCharacteristics(info);
                }

            } catch (ServiceSpecificException e) {
                throwAsPublicException(e);
            } catch (RemoteException e) {
@@ -500,8 +477,6 @@ public final class CameraManager {
            ICameraDeviceCallbacks callbacks = deviceImpl.getCallbacks();

            try {
                if (supportsCamera2ApiLocked(cameraId)) {
                    // Use cameraservice's cameradeviceclient implementation for HAL3.2+ devices
                ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
                if (cameraService == null) {
                    throw new ServiceSpecificException(
@@ -510,20 +485,6 @@ public final class CameraManager {
                }
                cameraUser = cameraService.connectDevice(callbacks, cameraId,
                    mContext.getOpPackageName(),  mContext.getAttributionTag(), uid);
                } else {
                    // Use legacy camera implementation for HAL1 devices
                    int id;
                    try {
                        id = Integer.parseInt(cameraId);
                    } catch (NumberFormatException e) {
                        throw new IllegalArgumentException("Expected cameraId to be numeric, but it was: "
                                + cameraId);
                    }

                    Log.i(TAG, "Using legacy camera HAL.");
                    cameraUser = CameraDeviceUserShim.connectBinderShim(callbacks, id,
                            getDisplaySize());
                }
            } catch (ServiceSpecificException e) {
                if (e.errorCode == ICameraService.ERROR_DEPRECATED_HAL) {
                    throw new AssertionError("Should've gone down the shim path");
@@ -1020,44 +981,6 @@ public final class CameraManager {
        }
    }

    /**
     * Queries the camera service if it supports the camera2 api directly, or needs a shim.
     *
     * @param cameraId a non-{@code null} camera identifier
     * @return {@code false} if the legacy shim needs to be used, {@code true} otherwise.
     */
    private boolean supportsCamera2ApiLocked(String cameraId) {
        return supportsCameraApiLocked(cameraId, API_VERSION_2);
    }

    /**
     * Queries the camera service if it supports a camera api directly, or needs a shim.
     *
     * @param cameraId a non-{@code null} camera identifier
     * @param apiVersion the version, i.e. {@code API_VERSION_1} or {@code API_VERSION_2}
     * @return {@code true} if connecting will work for that device version.
     */
    private boolean supportsCameraApiLocked(String cameraId, int apiVersion) {
        /*
         * Possible return values:
         * - NO_ERROR => CameraX API is supported
         * - CAMERA_DEPRECATED_HAL => CameraX API is *not* supported (thrown as an exception)
         * - Remote exception => If the camera service died
         *
         * Anything else is an unexpected error we don't want to recover from.
         */
        try {
            ICameraService cameraService = CameraManagerGlobal.get().getCameraService();
            // If no camera service, no support
            if (cameraService == null) return false;

            return cameraService.supportsCameraApi(cameraId, apiVersion);
        } catch (RemoteException e) {
            // Camera service is now down, no support for any API level
        }
        return false;
    }

    /**
     * Queries the camera service if a cameraId is a hidden physical camera that belongs to a
     * logical camera device.
+0 −90
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.camera2.legacy;

import android.hardware.camera2.CaptureRequest;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Immutable container for a burst of capture results.
 */
public class BurstHolder {
    private static final String TAG = "BurstHolder";
    private final ArrayList<RequestHolder.Builder> mRequestBuilders;
    private final boolean mRepeating;
    private final int mRequestId;

    /**
     * Immutable container for a burst of capture results.
     *
     * @param requestId id of the burst request.
     * @param repeating true if this burst is repeating.
     * @param requests the array of {@link CaptureRequest}s for this burst.
     * @param jpegSurfaceIds a {@link Collection} of IDs for the surfaces that have jpeg outputs.
     */
    public BurstHolder(int requestId, boolean repeating, CaptureRequest[] requests,
                       Collection<Long> jpegSurfaceIds) {
        mRequestBuilders = new ArrayList<>();
        int i = 0;
        for (CaptureRequest r : requests) {
            mRequestBuilders.add(new RequestHolder.Builder(requestId, /*subsequenceId*/i,
                    /*request*/r, repeating, jpegSurfaceIds));
            ++i;
        }
        mRepeating = repeating;
        mRequestId = requestId;
    }

    /**
     * Get the id of this request.
     */
    public int getRequestId() {
        return mRequestId;
    }

    /**
     * Return true if this repeating.
     */
    public boolean isRepeating() {
        return mRepeating;
    }

    /**
     * Return the number of requests in this burst sequence.
     */
    public int getNumberOfRequests() {
        return mRequestBuilders.size();
    }

    /**
     * Create a list of {@link RequestHolder} objects encapsulating the requests in this burst.
     *
     * @param frameNumber the starting framenumber for this burst.
     * @return the list of {@link RequestHolder} objects.
     */
    public List<RequestHolder> produceRequestHolders(long frameNumber) {
        ArrayList<RequestHolder> holders = new ArrayList<RequestHolder>();
        int i = 0;
        for (RequestHolder.Builder b : mRequestBuilders) {
            holders.add(b.build(frameNumber + i));
            ++i;
        }
        return holders;
    }
}
Loading