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

Commit d0b80385 authored by Sauhard Pande's avatar Sauhard Pande Committed by codeworkx
Browse files

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
parent 90b1f22e
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -33,6 +33,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.RSIllegalArgumentException;
@@ -261,7 +262,41 @@ 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() {
        /* Force to expose only two cameras
         * if the package name does not falls in this bucket
         */
        int numberOfCameras = native_getNumberOfCameras();
        if ((numberOfCameras > 2) && !shouldExposeAuxCamera()) {
            numberOfCameras = 2;
        }
        return numberOfCameras;
    }

    /**
     * Wether to expose Aux cameras
     */
    /** @hide */
    public static boolean shouldExposeAuxCamera() {
        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)) {
                    return true;
                }
            }
        }
        return false;
    }

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

    /**
     * Returns the information about a particular camera.
@@ -272,6 +307,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);
@@ -543,6 +581,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) {
+13 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.CameraInfo;
import android.hardware.CameraStatus;
import android.hardware.ICameraService;
@@ -841,6 +842,7 @@ public final class CameraManager {

                int idCount = 0;
                for (int i = 0; i < mDeviceStatus.size(); i++) {
                    if ((i == 2) && !Camera.shouldExposeAuxCamera()) break;
                    int status = mDeviceStatus.valueAt(i);
                    if (status == ICameraServiceListener.STATUS_NOT_PRESENT ||
                            status == ICameraServiceListener.STATUS_ENUMERATING) continue;
@@ -849,6 +851,7 @@ public final class CameraManager {
                cameraIds = new String[idCount];
                idCount = 0;
                for (int i = 0; i < mDeviceStatus.size(); i++) {
                    if ((i == 2) && !Camera.shouldExposeAuxCamera()) break;
                    int status = mDeviceStatus.valueAt(i);
                    if (status == ICameraServiceListener.STATUS_NOT_PRESENT ||
                            status == ICameraServiceListener.STATUS_ENUMERATING) continue;
@@ -985,6 +988,16 @@ 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
             */
            if (!Camera.shouldExposeAuxCamera()) {
                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
@@ -1101,7 +1101,7 @@ static void android_hardware_Camera_sendVendorCommand(JNIEnv *env, jobject thiz,
//-------------------------------------------------

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