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

Commit f9997754 authored by Sauhard Pande's avatar Sauhard Pande Committed by Nolen Johnson
Browse files

camera: Support exposing aux camera to apps

* Replace vendor.camera.aux.packageblacklist with vendor.camera.aux.packageexcludelist
  as recommended by coding guidelines https://developers.google.com/style/word-list#blacklist.

Original change:

Author: Sauhard Pande <sauhardp@codeaurora.org>
Date:   Thu Jul 21 18:23:21 2016 -0700

    Camera: Expose Aux camera to apps present in the whitelist

    Issue:
    3rd party apk cannot handle additional aux camera and may cause crash,
    Mono camera doesnt support all capabilities of HAL3 causing CTS issue.

    Fix:
    1. Expose aux camera to apps present in the whitelist
    2. ignore the availabe/unavailable status update for aux camera
    3. returning exception for open request for bad cameraid

    Change-Id: I15910154c6df205e6d4e00bfad30a00c9e3d5bee
    CRs-Fixed: 1086937

---------------------------------------------------------------------------

Forward-ported to R and squashed with the following changes:

Author: Rashed Abdel-Tawab <rashed@linux.com>
Date:   Sat Mar 24 13:20:52 2018 -0400

    camera: Check if aux camera whitelist is set before restricting cameras

    Some devices have a fully featured 3rd camera and adding 20+ camera apps
    to the whitelist is impossible due to the string length limit on
    systemprops. Add a check to see if the prop is even set, and if not,
    check if the blacklist property is set and mark those apps to hide the
    3rd camera from. If a package is not part of the blacklist, just restore
    the original behaviour and expose all the cameras to the app.

    Change-Id: I6c3b33c077e8710c73b5d0fa28e1b017d6c43a58

Author: Paul Keith <javelinanddart@gmail.com>
Date:   Fri Feb 8 08:42:33 2019 -0600

    Camera: Simplify code for Aux/Mono white and black lists

    Change-Id: I20c5454385d4d830a9a4d61926807a7eb1407c95

Change-Id: I7eb9f78c37f06a4e713fe6bcbf1793052aad3583

Change-Id: I15910154c6df205e6d4e00bfad30a00c9e3d5bee
parent 7d4d1096
Loading
Loading
Loading
Loading
+41 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.Message;
import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RSIllegalArgumentException;
@@ -59,6 +60,7 @@ import com.android.internal.app.IAppOpsService;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;

@@ -261,6 +263,25 @@ public class Camera {
     */
    private static final int CAMERA_FACE_DETECTION_SW = 1;

    /**
     * @hide
     */
    public static boolean shouldExposeAuxCamera() {
        /**
         * Force to expose only two cameras
         * if the package name does not falls in this bucket
         */
        String packageName = ActivityThread.currentOpPackageName();
        if (packageName == null)
            return true;
        List<String> packageList = Arrays.asList(
                SystemProperties.get("vendor.camera.aux.packagelist", packageName).split(","));
        List<String> packageExcludelist = Arrays.asList(
                SystemProperties.get("vendor.camera.aux.packageexcludelist", "").split(","));

        return packageList.contains(packageName) && !packageExcludelist.contains(packageName);
    }

    /**
     * Returns the number of physical cameras available on this device.
     * The return value of this method might change dynamically if the device
@@ -276,7 +297,20 @@ public class Camera {
     * @return total number of accessible camera devices, or 0 if there are no
     *   cameras or an error was encountered enumerating them.
     */
    public native static int getNumberOfCameras();
    public static int getNumberOfCameras() {
        int numberOfCameras = _getNumberOfCameras();
        if (!shouldExposeAuxCamera() && numberOfCameras > 2) {
            numberOfCameras = 2;
        }
        return numberOfCameras;
    }

    /**
     * Returns the number of physical cameras available on this device.
     *
     * @hide
     */
    public native static int _getNumberOfCameras();

    /**
     * Returns the information about a particular camera.
@@ -287,6 +321,9 @@ public class Camera {
     *    low-level failure).
     */
    public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
        if (cameraId >= getNumberOfCameras()) {
            throw new RuntimeException("Unknown camera ID");
        }
        boolean overrideToPortrait = CameraManager.shouldOverrideToPortrait(
                ActivityThread.currentApplication().getApplicationContext());

@@ -507,6 +544,9 @@ public class Camera {

    /** used by Camera#open, Camera#open(int) */
    Camera(int cameraId) {
        if (cameraId >= getNumberOfCameras()) {
            throw new RuntimeException("Unknown camera ID");
        }
        int err = cameraInit(cameraId);
        if (checkInitErrors(err)) {
            if (err == -EACCES) {
+9 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.compat.annotation.Overridable;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.hardware.Camera;
import android.hardware.CameraExtensionSessionStats;
import android.hardware.CameraIdRemapping;
import android.hardware.CameraStatus;
@@ -2002,8 +2003,10 @@ public final class CameraManager {

        private String[] extractCameraIdListLocked() {
            String[] cameraIds = null;
            boolean exposeAuxCamera = Camera.shouldExposeAuxCamera();
            int idCount = 0;
            for (int i = 0; i < mDeviceStatus.size(); i++) {
                if (!exposeAuxCamera && i == 2) break;
                int status = mDeviceStatus.valueAt(i);
                if (status == ICameraServiceListener.STATUS_NOT_PRESENT
                        || status == ICameraServiceListener.STATUS_ENUMERATING) continue;
@@ -2012,6 +2015,7 @@ public final class CameraManager {
            cameraIds = new String[idCount];
            idCount = 0;
            for (int i = 0; i < mDeviceStatus.size(); i++) {
                if (!exposeAuxCamera && i == 2) break;
                int status = mDeviceStatus.valueAt(i);
                if (status == ICameraServiceListener.STATUS_NOT_PRESENT
                        || status == ICameraServiceListener.STATUS_ENUMERATING) continue;
@@ -2544,6 +2548,11 @@ public final class CameraManager {
        }

        private void onStatusChangedLocked(int status, String id) {
            if (!Camera.shouldExposeAuxCamera() && Integer.parseInt(id) >= 2) {
                Log.w(TAG, "[soar.cts] ignore the status update of camera: " + id);
                return;
            }

            if (DEBUG) {
                Log.v(TAG,
                        String.format("Camera id %s has status changed to 0x%x", id, status));
+1 −1
Original line number Diff line number Diff line
@@ -1052,7 +1052,7 @@ static int32_t android_hardware_Camera_getAudioRestriction(
//-------------------------------------------------

static const JNINativeMethod camMethods[] = {
        {"getNumberOfCameras", "()I", (void *)android_hardware_Camera_getNumberOfCameras},
        {"_getNumberOfCameras", "()I", (void *)android_hardware_Camera_getNumberOfCameras},
        {"_getCameraInfo", "(IZLandroid/hardware/Camera$CameraInfo;)V",
         (void *)android_hardware_Camera_getCameraInfo},
        {"native_setup", "(Ljava/lang/Object;ILjava/lang/String;ZZ)I",