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

Commit cfd08f70 authored by Sauhard Pande's avatar Sauhard Pande
Browse files

Camera: Expose dual camera for whitelist app

Issue:
   In Bayer+Mono dual camera case, the 3rd party apk may not be able to handle additional aux camera and may cause crash,
   also as mono camera doesnt support all capabilities of HAL3 it may cause CTS failure.
Fix:
	1. Expose aux camera to apps present in the whitelist ("camera.aux.packagelist")
	2. ignore the availabe/unavailable status update for aux camera - needed to fix testCameraManagerListenerCallbacks.
	3. returning exception for open request for bad cameraid (if cameraid requested by non-whilisted app is more than number of cameras exposed) - needed to fix testMultipleCameras

CRs-Fixed: 1086937

Change-Id: I15910154c6df205e6d4e00bfad30a00c9e3d5bee
parent eebb3a7b
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemProperties;
import android.renderscript.Allocation;
import android.renderscript.Element;
import android.renderscript.RenderScript;
@@ -246,13 +247,44 @@ public class Camera {
    /**
     * Returns the number of physical cameras available on this device.
     */
    public native static int getNumberOfCameras();
    public static int getNumberOfCameras() {
        boolean exposeAuxCamera = false;
        String packageName = ActivityThread.currentOpPackageName();
        /* Force to expose only two cameras
         * if the package name does not falls in this bucket
         */
        String packageList = SystemProperties.get("camera.aux.packagelist");
        if (packageList.length() > 0) {
            TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
            splitter.setString(packageList);
            for (String str : splitter) {
                if (packageName.equals(str)) {
                    exposeAuxCamera = true;
                    break;
                }
            }
        }
        int numberOfCameras = _getNumberOfCameras();
        if (exposeAuxCamera == false && (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.
     * If {@link #getNumberOfCameras()} returns N, the valid id is 0 to N-1.
     */
    public static void getCameraInfo(int cameraId, CameraInfo cameraInfo) {
        if(cameraId >= getNumberOfCameras()){
            throw new RuntimeException("Unknown camera ID");
        }
        _getCameraInfo(cameraId, cameraInfo);
        IBinder b = ServiceManager.getService(Context.AUDIO_SERVICE);
        IAudioService audioService = IAudioService.Stub.asInterface(b);
@@ -534,6 +566,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 = cameraInitNormal(cameraId);
        if (checkInitErrors(err)) {
            if (err == -EACCES) {
+46 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.hardware.camera2;
import android.annotation.RequiresPermission;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.content.Context;
import android.hardware.ICameraService;
import android.hardware.ICameraServiceListener;
@@ -34,6 +35,8 @@ import android.os.Looper;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceSpecificException;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import android.util.ArrayMap;

@@ -662,6 +665,25 @@ public final class CameraManager {

            try {
                numCameras = cameraService.getNumberOfCameras(CAMERA_TYPE_ALL);
                /* Force to expose only two cameras
                 * if the package name does not falls in this bucket
                 */
                boolean exposeAuxCamera = false;
                String packageName = ActivityThread.currentOpPackageName();
                String packageList = SystemProperties.get("camera.aux.packagelist");
                if (packageList.length() > 0) {
                    TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
                    splitter.setString(packageList);
                    for (String str : splitter) {
                        if (packageName.equals(str)) {
                            exposeAuxCamera = true;
                            break;
                        }
                    }
                }
                if (exposeAuxCamera == false && (numCameras > 2)) {
                    numCameras = 2;
                }
            } catch(ServiceSpecificException e) {
                throwAsPublicException(e);
            } catch (RemoteException e) {
@@ -989,6 +1011,30 @@ public final class CameraManager {
        }

        private void onStatusChangedLocked(int status, String id) {
            /* Force to ignore the last mono/aux camera status update
             * if the package name does not falls in this bucket
             */
            boolean exposeMonoCamera = false;
            String packageName = ActivityThread.currentOpPackageName();
            String packageList = SystemProperties.get("camera.aux.packagelist");
            if (packageList.length() > 0) {
                TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
                splitter.setString(packageList);
                for (String str : splitter) {
                    if (packageName.equals(str)) {
                        exposeMonoCamera = true;
                        break;
                    }
                }
            }

            if (exposeMonoCamera == false) {
                if (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
@@ -1099,7 +1099,7 @@ static void android_hardware_Camera_enableFocusMoveCallback(JNIEnv *env, jobject
//-------------------------------------------------

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