summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShuzhen Wang <shuzhenwang@google.com>2020-03-06 11:38:21 -0800
committerShuzhen Wang <shuzhenwang@google.com>2020-03-10 11:34:26 -0700
commite375ee8f8a4e767040cfbef1ead28623b3e986e0 (patch)
tree164eef8bb0a5c5797adac6cf82c8b7ef4ebb4a83
parentb2307f8db48104fb14807db0b5531690c2eeaa3d (diff)
Camera: Add new hidden API for camera open/close callback
The hidden API is used by SystemUI process to adjust the system UI based on when a certain camera is opened or closed. Test: Manually observe callbacks in SystemUI when running camera CTS Bug: 150540299 Change-Id: I04cae782d96f0e32be8ef588dcd328f84b32887a Merged-In: I04cae782d96f0e32be8ef588dcd328f84b32887a
-rw-r--r--core/java/android/hardware/camera2/CameraManager.java85
-rw-r--r--core/res/AndroidManifest.xml8
-rw-r--r--core/res/res/values/strings.xml5
-rw-r--r--data/etc/com.android.systemui.xml1
-rw-r--r--media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java9
-rw-r--r--packages/SystemUI/AndroidManifest.xml1
6 files changed, 109 insertions, 0 deletions
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index c8276b25c52d..13f2a5ebc785 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -701,6 +701,33 @@ public final class CameraManager {
public void onCameraAccessPrioritiesChanged() {
// default empty implementation
}
+
+ /**
+ * A camera device has been opened by an application.
+ *
+ * <p>The default implementation of this method does nothing.</p>
+ *
+ * @param cameraId The unique identifier of the new camera.
+ * @param packageId The package Id of the application opening the camera.
+ *
+ * @see #onCameraClosed
+ */
+ /** @hide */
+ public void onCameraOpened(@NonNull String cameraId, @NonNull String packageId) {
+ // default empty implementation
+ }
+
+ /**
+ * A previously-opened camera has been closed.
+ *
+ * <p>The default implementation of this method does nothing.</p>
+ *
+ * @param cameraId The unique identifier of the closed camera.
+ */
+ /** @hide */
+ public void onCameraClosed(@NonNull String cameraId) {
+ // default empty implementation
+ }
}
/**
@@ -1139,6 +1166,38 @@ public final class CameraManager {
}
}
+ private void postSingleCameraOpenedUpdate(final AvailabilityCallback callback,
+ final Executor executor, final String id, final String packageId) {
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ executor.execute(
+ new Runnable() {
+ @Override
+ public void run() {
+ callback.onCameraOpened(id, packageId);
+ }
+ });
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ }
+
+ private void postSingleCameraClosedUpdate(final AvailabilityCallback callback,
+ final Executor executor, final String id) {
+ final long ident = Binder.clearCallingIdentity();
+ try {
+ executor.execute(
+ new Runnable() {
+ @Override
+ public void run() {
+ callback.onCameraClosed(id);
+ }
+ });
+ } finally {
+ Binder.restoreCallingIdentity(ident);
+ }
+ }
+
private void postSingleUpdate(final AvailabilityCallback callback, final Executor executor,
final String id, final int status) {
if (isAvailable(status)) {
@@ -1401,6 +1460,32 @@ public final class CameraManager {
}
}
+ @Override
+ public void onCameraOpened(String cameraId, String clientPackageId) {
+ synchronized (mLock) {
+ final int callbackCount = mCallbackMap.size();
+ for (int i = 0; i < callbackCount; i++) {
+ Executor executor = mCallbackMap.valueAt(i);
+ final AvailabilityCallback callback = mCallbackMap.keyAt(i);
+
+ postSingleCameraOpenedUpdate(callback, executor, cameraId, clientPackageId);
+ }
+ }
+ }
+
+ @Override
+ public void onCameraClosed(String cameraId) {
+ synchronized (mLock) {
+ final int callbackCount = mCallbackMap.size();
+ for (int i = 0; i < callbackCount; i++) {
+ Executor executor = mCallbackMap.valueAt(i);
+ final AvailabilityCallback callback = mCallbackMap.keyAt(i);
+
+ postSingleCameraClosedUpdate(callback, executor, cameraId);
+ }
+ }
+ }
+
/**
* Try to connect to camera service after some delay if any client registered camera
* availability callback or torch status callback.
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 5778d02737b9..7b95d92ce1d6 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -1267,6 +1267,14 @@
android:description="@string/permdesc_camera"
android:protectionLevel="dangerous|instant" />
+ <!-- Allows receiving the camera service notifications when a camera is opened
+ (by a certain application package) or closed.
+ @hide -->
+ <permission android:name="android.permission.CAMERA_OPEN_CLOSE_LISTENER"
+ android:permissionGroup="android.permission-group.UNDEFINED"
+ android:label="@string/permlab_cameraOpenCloseListener"
+ android:description="@string/permdesc_cameraOpenCloseListener"
+ android:protectionLevel="signature" />
<!-- ====================================================================== -->
<!-- Permissions for accessing the device sensors -->
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 5d5729b412be..044e07420c2d 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -1151,6 +1151,11 @@
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permdesc_camera">This app can take pictures and record videos using the camera at any time.</string>
+ <!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR_LIMIT=NONE] -->
+ <string name="permlab_cameraOpenCloseListener">Allow an application or service to receive callbacks about camera devices being opened or closed.</string>
+ <!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. [CHAR_LIMIT=NONE] -->
+ <string name="permdesc_cameraOpenCloseListener">This signature app can receive callbacks when any camera device is being opened (by what application package) or closed.</string>
+
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
<string name="permlab_vibrate">control vibration</string>
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
diff --git a/data/etc/com.android.systemui.xml b/data/etc/com.android.systemui.xml
index a305d48c4633..2f5b5f3bf7b4 100644
--- a/data/etc/com.android.systemui.xml
+++ b/data/etc/com.android.systemui.xml
@@ -60,5 +60,6 @@
<permission name="android.permission.WRITE_SECURE_SETTINGS"/>
<permission name="android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS"/>
<permission name="android.permission.CONTROL_DISPLAY_COLOR_TRANSFORMS" />
+ <permission name="android.permission.CAMERA_OPEN_CLOSE_LISTENER" />
</privapp-permissions>
</permissions>
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
index 87a59df19e8e..0889192099df 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
@@ -313,6 +313,15 @@ public class CameraBinderTest extends AndroidTestCase {
public void onCameraAccessPrioritiesChanged() {
Log.v(TAG, "Camera access permission change");
}
+ @Override
+ public void onCameraOpened(String cameraId, String clientPackageName) {
+ Log.v(TAG, String.format("Camera %s is opened by client package %s",
+ cameraId, clientPackageName));
+ }
+ @Override
+ public void onCameraClosed(String cameraId) {
+ Log.v(TAG, String.format("Camera %s is closed", cameraId));
+ }
}
/**
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index 862abfda6a65..20b61f966d2d 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -151,6 +151,7 @@
<uses-permission android:name="android.permission.CONFIGURE_WIFI_DISPLAY" />
<uses-permission android:name="android.permission.CAMERA" />
+ <uses-permission android:name="android.permission.CAMERA_OPEN_CLOSE_LISTENER" />
<!-- Screen Capturing -->
<uses-permission android:name="android.permission.MANAGE_MEDIA_PROJECTION" />