当前位置:   article > 正文

Android P 通过系统属性来禁止打开系统Camera和第三方Camera_android 系统开发不允许三方应用打开后摄

android 系统开发不允许三方应用打开后摄

1.禁止第三方APP打开Camera
frameworks/base/core/java/android/hardware/Camera.java

 public static Camera open(int cameraId) {
        // add 
        if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
            return null;
        }
        // end
        return new Camera(cameraId);
    }

public static Camera open() { 
        //add 
        if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
            return null;
        }
        // end
        int numberOfCameras = getNumberOfCameras();
        CameraInfo cameraInfo = new CameraInfo();
        for (int i = 0; i < numberOfCameras; i++) {
            getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
                return new Camera(i);
            }
        }
        return null;
    }


 public static Camera openLegacy(int cameraId, int halVersion) {
        if (halVersion < CAMERA_HAL_API_VERSION_1_0) {
            throw new IllegalArgumentException("Invalid HAL version " + halVersion);
        }
        // add 
        if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
            return null;
        }
        // end
        return new Camera(cameraId, halVersion);
    }


public static Camera openUninitialized() {
        // add 
        if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
            return null;
        }
        //end
        return new Camera();
    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

2.禁止打开系统Camera
frameworks/base/core/java/android/hardware/camera2/CameraManager.java

import android.os.SystemProperties;//add 


 private CameraDevice openCameraDeviceUserAsync(String cameraId,
            CameraDevice.StateCallback callback, Executor executor, final int uid)
            throws CameraAccessException {
        CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
        CameraDevice device = null;
        //add 
        if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
            return null;
        }
        // end
        synchronized (mLock) {

            ICameraDeviceUser cameraUser = null;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

3.可以通过设置"persist.sys.disablecamera"的值来控制是否禁用Camera。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/461423
推荐阅读
相关标签
  

闽ICP备14008679号