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
This commit is contained in:
Shuzhen Wang
2020-03-06 11:38:21 -08:00
parent b2307f8db4
commit e375ee8f8a
6 changed files with 109 additions and 0 deletions

View File

@@ -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.