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

Commit 364462f9 authored by Sauhard Pande's avatar Sauhard Pande Committed by Bruno Martins
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: I15910154c6df205e6d4e00bfad30a00c9e3d5bee
parent 31355d74
Loading
Loading
Loading
Loading
+39 −1
Original line number Original line Diff line number Diff line
@@ -45,6 +45,7 @@ import android.os.Message;
import android.os.Process;
import android.os.Process;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.renderscript.Allocation;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.Element;
import android.renderscript.RSIllegalArgumentException;
import android.renderscript.RSIllegalArgumentException;
@@ -62,6 +63,7 @@ import com.android.internal.app.IAppOpsService;
import java.io.IOException;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.List;


@@ -283,6 +285,23 @@ public class Camera {
     */
     */
    private static final int CAMERA_FACE_DETECTION_SW = 1;
    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();
        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.
     * Returns the number of physical cameras available on this device.
     * The return value of this method might change dynamically if the device
     * The return value of this method might change dynamically if the device
@@ -298,7 +317,20 @@ public class Camera {
     * @return total number of accessible camera devices, or 0 if there are no
     * @return total number of accessible camera devices, or 0 if there are no
     *   cameras or an error was encountered enumerating them.
     *   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.
     * Returns the information about a particular camera.
@@ -309,6 +341,9 @@ public class Camera {
     *    low-level failure).
     *    low-level failure).
     */
     */
    public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
    public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
        if (cameraId >= getNumberOfCameras()) {
            throw new RuntimeException("Unknown camera ID");
        }
        _getCameraInfo(cameraId, cameraInfo);
        _getCameraInfo(cameraId, cameraInfo);
        IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
        IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
        IAudioService audioService = IAudioService.Stub.asInterface(b);
        IAudioService audioService = IAudioService.Stub.asInterface(b);
@@ -581,6 +616,9 @@ public class Camera {


    /** used by Camera#open, Camera#open(int) */
    /** used by Camera#open, Camera#open(int) */
    Camera(int cameraId) {
    Camera(int cameraId) {
        if (cameraId >= getNumberOfCameras()) {
            throw new RuntimeException("Unknown camera ID");
        }
        int err = cameraInitNormal(cameraId);
        int err = cameraInitNormal(cameraId);
        if (checkInitErrors(err)) {
        if (checkInitErrors(err)) {
            if (err == -EACCES) {
            if (err == -EACCES) {
+9 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.content.Context;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.CameraInfo;
import android.hardware.CameraInfo;
import android.hardware.CameraStatus;
import android.hardware.CameraStatus;
import android.hardware.ICameraService;
import android.hardware.ICameraService;
@@ -1236,8 +1237,10 @@ public final class CameraManager {


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


        private void onStatusChangedLocked(int status, String id) {
        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) {
            if (DEBUG) {
                Log.v(TAG,
                Log.v(TAG,
                        String.format("Camera id %s has status changed to 0x%x", id, status));
                        String.format("Camera id %s has status changed to 0x%x", id, status));
+1 −1
Original line number Original line Diff line number Diff line
@@ -1129,7 +1129,7 @@ static int32_t android_hardware_Camera_getAudioRestriction(
//-------------------------------------------------
//-------------------------------------------------


static const JNINativeMethod camMethods[] = {
static const JNINativeMethod camMethods[] = {
  { "getNumberOfCameras",
  { "_getNumberOfCameras",
    "()I",
    "()I",
    (void *)android_hardware_Camera_getNumberOfCameras },
    (void *)android_hardware_Camera_getNumberOfCameras },
  { "_getCameraInfo",
  { "_getCameraInfo",