getCameraIdList看不到后摄的副摄像头,怎么办

最近做双摄测试开发,发现副摄像头id找不到.只能找到一个前摄,一个后摄.
从framework源码发现实际是隐藏了,

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;
    }
        public String[] getCameraIdList() {
            String[] cameraIds = null;
            synchronized(mLock) {
                // 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;
                    idCount++;
                }
                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;
                    cameraIds[idCount] = mDeviceStatus.keyAt(i);
                    idCount++;
                }
            }
            .....
            return cameraIds;
        }

通过设置属性vendor.camera.aux.packagelist, 可以使用副摄像头.

修改common_full_phone.mk

# white list to get aux camera
PRODUCT_PROPERTY_OVERRIDES += \
    vendor.camera.aux.packagelist=org.codeaurora.snapcam,com.smartisan.factorytest,com.android.camera2,com.qualcomm.qti.qmmi

参考:
https://www.jianshu.com/p/6fe64cf0340c

你可能感兴趣的:(getCameraIdList看不到后摄的副摄像头,怎么办)