Merge "Implement CameraIdRemapping in CameraManager" into udc-qpr-dev

This commit is contained in:
Akash Malik
2023-08-09 22:01:16 +00:00
committed by Android (Google) Code Review

View File

@@ -31,6 +31,7 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Point;
import android.hardware.CameraExtensionSessionStats;
import android.hardware.CameraIdRemapping;
import android.hardware.CameraStatus;
import android.hardware.ICameraService;
import android.hardware.ICameraServiceListener;
@@ -1729,6 +1730,17 @@ public final class CameraManager {
}
}
/**
* Remaps Camera Ids in the CameraService.
*
* @hide
*/
@RequiresPermission(android.Manifest.permission.CAMERA_INJECT_EXTERNAL_CAMERA)
public void remapCameraIds(@NonNull CameraIdRemapping cameraIdRemapping)
throws CameraAccessException, SecurityException, IllegalArgumentException {
CameraManagerGlobal.get().remapCameraIds(cameraIdRemapping);
}
/**
* Reports {@link CameraExtensionSessionStats} to the {@link ICameraService} to be logged for
* currently active session. Validation is done downstream.
@@ -1802,6 +1814,13 @@ public final class CameraManager {
private final Object mLock = new Object();
/**
* The active CameraIdRemapping. This will be used to refresh the cameraIdRemapping state
* in the CameraService every time we connect to it, including when the CameraService
* Binder dies and we reconnect to it.
*/
@Nullable private CameraIdRemapping mActiveCameraIdRemapping;
// Access only through getCameraService to deal with binder death
private ICameraService mCameraService;
private boolean mHasOpenCloseListenerPermission = false;
@@ -1944,6 +1963,41 @@ public final class CameraManager {
} catch (RemoteException e) {
// Camera service died in all probability
}
if (mActiveCameraIdRemapping != null) {
try {
cameraService.remapCameraIds(mActiveCameraIdRemapping);
} catch (ServiceSpecificException e) {
// Unexpected failure, ignore and continue.
Log.e(TAG, "Unable to remap camera Ids in the camera service");
} catch (RemoteException e) {
// Camera service died in all probability
}
}
}
/** Updates the cameraIdRemapping state in the CameraService. */
public void remapCameraIds(@NonNull CameraIdRemapping cameraIdRemapping)
throws CameraAccessException, SecurityException {
synchronized (mLock) {
ICameraService cameraService = getCameraService();
if (cameraService == null) {
throw new CameraAccessException(
CameraAccessException.CAMERA_DISCONNECTED,
"Camera service is currently unavailable.");
}
try {
cameraService.remapCameraIds(cameraIdRemapping);
mActiveCameraIdRemapping = cameraIdRemapping;
} catch (ServiceSpecificException e) {
throwAsPublicException(e);
} catch (RemoteException e) {
throw new CameraAccessException(
CameraAccessException.CAMERA_DISCONNECTED,
"Camera service is currently unavailable.");
}
}
}
private String[] extractCameraIdListLocked() {