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

Commit 73abf4ea authored by Sauhard Pande's avatar Sauhard Pande Committed by Bruno Martins
Browse files

Camera: Expose Aux camera to apps present in the whitelist

Issue:
3rd party apk cannot handle additional aux camera and may cause failure,
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.

CRs-Fixed: 1086937

Change-Id: I15910154c6df205e6d4e00bfad30a00c9e3d5bee
parent 1dce3a2a
Loading
Loading
Loading
Loading
+36 −1
Original line number Diff line number Diff line
@@ -37,6 +37,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;
@@ -288,7 +289,35 @@ 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() {
        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("vendor.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.
@@ -299,6 +328,9 @@ public class Camera {
     *    low-level failure).
     */
    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);
@@ -570,6 +602,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) {
+42 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.app.ActivityThread;
import android.content.Context;
import android.hardware.CameraInfo;
import android.hardware.CameraStatus;
@@ -39,6 +40,8 @@ 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;
import android.util.Log;

@@ -910,8 +913,22 @@ public final class CameraManager {
                // Try to make sure we have an up-to-date list of camera devices.
                connectCameraServiceLocked();

                boolean exposeAuxCamera = false;
                String packageName = ActivityThread.currentOpPackageName();
                String packageList = SystemProperties.get("vendor.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 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;
@@ -920,6 +937,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;
@@ -1101,6 +1119,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("vendor.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
@@ -1090,7 +1090,7 @@ static void android_hardware_Camera_enableFocusMoveCallback(JNIEnv *env, jobject
//-------------------------------------------------

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