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/services/camera/libcameraservice/hidl/AidlCameraServiceListener.cpp b/services/camera/libcameraservice/hidl/AidlCameraServiceListener.cpp
index 2b81224..d28c7ab 100644
--- a/services/camera/libcameraservice/hidl/AidlCameraServiceListener.cpp
+++ b/services/camera/libcameraservice/hidl/AidlCameraServiceListener.cpp
@@ -16,6 +16,7 @@
#include <hidl/AidlCameraServiceListener.h>
#include <hidl/Utils.h>
+#include <camera/CameraUtils.h>
#include <camera/StringUtils.h>
namespace android {
@@ -29,7 +30,10 @@
typedef frameworks::cameraservice::service::V2_1::ICameraServiceListener HCameraServiceListener2_1;
binder::Status H2BCameraServiceListener::onStatusChanged(
- int32_t status, const std::string& cameraId) {
+ int32_t status, const std::string& cameraId, int32_t deviceId) {
+ if (deviceId != kDefaultDeviceId) {
+ return binder::Status::ok();
+ }
HCameraDeviceStatus hCameraDeviceStatus = convertToHidlCameraDeviceStatus(status);
CameraStatusAndId cameraStatusAndId;
cameraStatusAndId.deviceStatus = hCameraDeviceStatus;
@@ -44,7 +48,10 @@
binder::Status H2BCameraServiceListener::onPhysicalCameraStatusChanged(
int32_t status, const std::string& cameraId,
- const std::string& physicalCameraId) {
+ const std::string& physicalCameraId, int32_t deviceId) {
+ if (deviceId != kDefaultDeviceId) {
+ return binder::Status::ok();
+ }
auto cast2_1 = HCameraServiceListener2_1::castFrom(mBase);
sp<HCameraServiceListener2_1> interface2_1 = nullptr;
if (cast2_1.isOk()) {
@@ -66,13 +73,13 @@
}
::android::binder::Status H2BCameraServiceListener::onTorchStatusChanged(
- int32_t, const std::string&) {
+ [[maybe_unused]] int32_t, [[maybe_unused]] const std::string&, [[maybe_unused]] int32_t) {
// We don't implement onTorchStatusChanged
return binder::Status::ok();
}
::android::binder::Status H2BCameraServiceListener::onTorchStrengthLevelChanged(
- const std::string&, int32_t) {
+ [[maybe_unused]] const std::string&, [[maybe_unused]] int32_t, [[maybe_unused]] int32_t) {
return binder::Status::ok();
}
diff --git a/services/camera/libcameraservice/hidl/AidlCameraServiceListener.h b/services/camera/libcameraservice/hidl/AidlCameraServiceListener.h
index 91a4c16..78fca4e 100644
--- a/services/camera/libcameraservice/hidl/AidlCameraServiceListener.h
+++ b/services/camera/libcameraservice/hidl/AidlCameraServiceListener.h
@@ -47,25 +47,28 @@
~H2BCameraServiceListener() { }
virtual ::android::binder::Status onStatusChanged(int32_t status,
- const std::string& cameraId) override;
+ const std::string& cameraId, int32_t deviceId) override;
virtual ::android::binder::Status onPhysicalCameraStatusChanged(int32_t status,
const std::string& cameraId,
- const std::string& physicalCameraId) override;
+ const std::string& physicalCameraId,
+ int32_t deviceId) override;
virtual ::android::binder::Status onTorchStatusChanged(
- int32_t status, const std::string& cameraId) override;
+ int32_t status, const std::string& cameraId, int32_t deviceId) override;
virtual ::android::binder::Status onTorchStrengthLevelChanged(
- const std::string& cameraId, int32_t newStrengthLevel) override;
+ const std::string& cameraId, int32_t newStrengthLevel, int32_t deviceId) override;
virtual binder::Status onCameraAccessPrioritiesChanged() {
// TODO: no implementation yet.
return binder::Status::ok();
}
- virtual binder::Status onCameraOpened(const std::string& /*cameraId*/,
- const std::string& /*clientPackageId*/) {
+ virtual binder::Status onCameraOpened([[maybe_unused]] const std::string& /*cameraId*/,
+ [[maybe_unused]] const std::string& /*clientPackageId*/,
+ [[maybe_unused]] int32_t /*deviceId*/) {
// empty implementation
return binder::Status::ok();
}
- virtual binder::Status onCameraClosed(const std::string& /*cameraId*/) {
+ virtual binder::Status onCameraClosed([[maybe_unused]] const std::string& /*cameraId*/,
+ [[maybe_unused]] int32_t /*deviceId*/) {
// empty implementation
return binder::Status::ok();
}
diff --git a/services/camera/libcameraservice/hidl/HidlCameraService.cpp b/services/camera/libcameraservice/hidl/HidlCameraService.cpp
index 1a5a6b9..8f25ad6 100644
--- a/services/camera/libcameraservice/hidl/HidlCameraService.cpp
+++ b/services/camera/libcameraservice/hidl/HidlCameraService.cpp
@@ -25,6 +25,7 @@
#include <hidl/HidlTransportSupport.h>
+#include <camera/CameraUtils.h>
#include <utils/Utils.h>
namespace android {
@@ -69,7 +70,7 @@
binder::Status serviceRet =
mAidlICameraService->getCameraCharacteristics(cameraId,
/*targetSdkVersion*/__ANDROID_API_FUTURE__, /*overrideToPortrait*/false,
- &cameraMetadata);
+ kDefaultDeviceId, 0, &cameraMetadata);
HCameraMetadata hidlMetadata;
if (!serviceRet.isOk()) {
switch(serviceRet.serviceSpecificErrorCode()) {
@@ -121,7 +122,7 @@
callbacks, cameraId, std::string(), {},
hardware::ICameraService::USE_CALLING_UID, 0/*oomScoreOffset*/,
/*targetSdkVersion*/__ANDROID_API_FUTURE__, /*overrideToPortrait*/false,
- /*out*/&deviceRemote);
+ kDefaultDeviceId, /*devicePolicy*/0, /*out*/&deviceRemote);
HStatus status = HStatus::NO_ERROR;
if (!serviceRet.isOk()) {
ALOGE("%s: Unable to connect to camera device", __FUNCTION__);