本文主要是介绍rk3588 安卓13 暴露相机开关接口,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
以前不知道有个系统属性可以做,后面的代码我几乎都用系统属性来写,比写个额外的广播接口方便多了。
实现一个相机的开关接口给上层调用,也就是打开后,上层无法再调用相机,关闭后可以正常打开,无需重启,直接贴代码
diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java
index f6697134bfa6..eee994271221 100644
--- a/core/java/android/hardware/Camera.java
+++ b/core/java/android/hardware/Camera.java
@@ -51,6 +51,7 @@ import android.util.Log;import android.view.Surface;import android.view.SurfaceHolder;+import android.os.SystemProperties;//add LQXimport com.android.internal.R;import com.android.internal.annotations.GuardedBy;import com.android.internal.app.IAppOpsCallback;
@@ -396,6 +397,13 @@ public class Camera {* @see android.app.admin.DevicePolicyManager#getCameraDisabled(android.content.ComponentName)*/public static Camera open(int cameraId) {
+
+ // LQX
+ if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
+ Log.d(TAG, "camera sensor is close" + "LQX");
+ return null;
+ }
+ // LQXreturn new Camera(cameraId);}@@ -409,6 +417,12 @@ public class Camera {* @see #open(int)*/public static Camera open() {
+ //add
+ if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
+ Log.d(TAG, "camera sensor is close" + "LQX");
+ return null;
+ }
+ // endint numberOfCameras = getNumberOfCameras();CameraInfo cameraInfo = new CameraInfo();for (int i = 0; i < numberOfCameras; i++) {
@@ -463,7 +477,12 @@ public class Camera {if (halVersion < CAMERA_HAL_API_VERSION_3_0) {throw new IllegalArgumentException("Unsupported HAL version " + halVersion);}
-
+ // add
+ if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
+ Log.d(TAG, "camera sensor is close" + "LQX");
+ return null;
+ }
+ // endreturn new Camera(cameraId);}@@ -532,6 +551,12 @@ public class Camera {* @hide*/public static Camera openUninitialized() {
+ // add
+ if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
+ Log.d(TAG, "camera sensor is close" + "LQX");
+ return null;
+ }
+ //endreturn new Camera();}diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index 56592ab43143..d885894dd106 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -720,6 +720,13 @@ public final class CameraManager {final int oomScoreOffset) throws CameraAccessException {CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);CameraDevice device = null;
+ //add
+ if(SystemProperties.get("persist.sys.disablecamera").equals("true")){
+ Log.d(TAG, "camera2 sensor is close" + "LQX");
+
+ return null;
+ }
+ // endMap<String, CameraCharacteristics> physicalIdsToChars =getPhysicalIdToCharsMap(characteristics);synchronized (mLock) {
这篇关于rk3588 安卓13 暴露相机开关接口的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!