Implement device awareness in camera service

- Modify ICameraServiceListener to pass device id
(i.e., the id of the device owning the camera, for
virtual camera this would be the id of the virtual
device, and for real cameras this would be
Context#DEVICE_ID_DEFAULT) and the mapped camera id
(for virtual devices, the back and front virtual cameras
of that device would have 0 and 1 respectively as their
mapped camera id, and for real cameras this would be
their actual camera id) in the callbacks. Cameraserver
exposes vitual cameras only to callers having context
associated with a custom policy virtual device.

- Modify ICameraService to accept device id and device
policy for binder calls related to camera operations.
Based on these, cameraserver maps the input camera id into
a virtual camera id (if applicable).

- Modify virtual camera HAL service to pass the device id
of virtual cameras using the metadata key ANDROID_INFO_DEVICE_ID.

- This change adds device-awareness to both camera2 and legacy
camera API's.

- This change prevents camera injection, session params injection,
and package name based cameraId-remapping if a virtual camera is
involved.

- This change modifies the NDK implementation to ignore callbacks
for non-default device id's. So virtual cameras are not accessible
using the NDK with this change (if the feature flag for camera
device awareness is enabled). Device awareness for camera NDK will
be added in a future CL.

Test: atest CtsVirtualDevicesCameraTestCases
Bug: 291736219
Change-Id: Iffe2a2e337a9e5801b84495d3ce1e8a1584b4993
diff --git a/camera/ndk/impl/ACameraManager.cpp b/camera/ndk/impl/ACameraManager.cpp
index 8c3424f..0744992 100644
--- a/camera/ndk/impl/ACameraManager.cpp
+++ b/camera/ndk/impl/ACameraManager.cpp
@@ -32,6 +32,9 @@
 
 namespace android {
 namespace acam {
+
+// TODO(b/291736219): Add device-awareness to ACameraManager.
+
 // Static member definitions
 const char* CameraManagerGlobal::kCameraIdKey   = "CameraId";
 const char* CameraManagerGlobal::kPhysicalCameraIdKey   = "PhysicalCameraId";
@@ -125,6 +128,12 @@
         std::vector<hardware::CameraStatus> cameraStatuses{};
         mCameraService->addListener(mCameraServiceListener, &cameraStatuses);
         for (auto& c : cameraStatuses) {
+            // Skip callback for cameras not belonging to the default device, as NDK doesn't support
+            // device awareness yet.
+            if (c.deviceId != kDefaultDeviceId) {
+                continue;
+            }
+
             onStatusChangedLocked(c.status, c.cameraId);
 
             for (auto& unavailablePhysicalId : c.unavailablePhysicalIds) {
@@ -461,7 +470,13 @@
 }
 
 binder::Status CameraManagerGlobal::CameraServiceListener::onStatusChanged(
-        int32_t status, const std::string& cameraId) {
+        int32_t status, const std::string& cameraId, int deviceId) {
+    // Skip callback for cameras not belonging to the default device, as NDK doesn't support
+    // device awareness yet.
+    if (deviceId != kDefaultDeviceId) {
+        return binder::Status::ok();
+    }
+
     sp<CameraManagerGlobal> cm = mCameraManager.promote();
     if (cm != nullptr) {
         cm->onStatusChanged(status, cameraId);
@@ -472,7 +487,14 @@
 }
 
 binder::Status CameraManagerGlobal::CameraServiceListener::onPhysicalCameraStatusChanged(
-        int32_t status, const std::string& cameraId, const std::string& physicalCameraId) {
+        int32_t status, const std::string& cameraId, const std::string& physicalCameraId,
+        int deviceId) {
+    // Skip callback for cameras not belonging to the default device, as NDK doesn't support
+    // device awareness yet.
+    if (deviceId != kDefaultDeviceId) {
+        return binder::Status::ok();
+    }
+
     sp<CameraManagerGlobal> cm = mCameraManager.promote();
     if (cm != nullptr) {
         cm->onStatusChanged(status, cameraId, physicalCameraId);
@@ -697,7 +719,8 @@
     CameraMetadata rawMetadata;
     int targetSdkVersion = android_get_application_target_sdk_version();
     binder::Status serviceRet = cs->getCameraCharacteristics(cameraIdStr,
-            targetSdkVersion, /*overrideToPortrait*/false, &rawMetadata);
+            targetSdkVersion, /*overrideToPortrait*/false, kDefaultDeviceId, /*devicePolicy*/0,
+            &rawMetadata);
     if (!serviceRet.isOk()) {
         switch(serviceRet.serviceSpecificErrorCode()) {
             case hardware::ICameraService::ERROR_DISCONNECTED:
@@ -749,7 +772,8 @@
     binder::Status serviceRet = cs->connectDevice(
             callbacks, cameraId, "", {},
             hardware::ICameraService::USE_CALLING_UID, /*oomScoreOffset*/0,
-            targetSdkVersion, /*overrideToPortrait*/false, /*out*/&deviceRemote);
+            targetSdkVersion, /*overrideToPortrait*/false, kDefaultDeviceId, /*devicePolicy*/0,
+            /*out*/&deviceRemote);
 
     if (!serviceRet.isOk()) {
         ALOGE("%s: connect camera device failed: %s", __FUNCTION__, serviceRet.toString8().c_str());