Camera: Fill out vndk implementation for physical camera callbacks
Also fixed missing implementation of Camera availability callbacks for
ExtendedAvailabilityCallback.
Test: Camera CTS, and vndk test
Bug: 148146086
Change-Id: I557d6db3900b2346b7bc7e12cd946bc4c2dc4076
diff --git a/services/camera/libcameraservice/hidl/HidlCameraService.cpp b/services/camera/libcameraservice/hidl/HidlCameraService.cpp
index 97ba9c4..a46133e 100644
--- a/services/camera/libcameraservice/hidl/HidlCameraService.cpp
+++ b/services/camera/libcameraservice/hidl/HidlCameraService.cpp
@@ -154,15 +154,50 @@
Return<void> HidlCameraService::addListener(const sp<HCameraServiceListener>& hCsListener,
addListener_cb _hidl_cb) {
- if (mAidlICameraService == nullptr) {
- _hidl_cb(HStatus::UNKNOWN_ERROR, {});
+ std::vector<hardware::CameraStatus> cameraStatusAndIds{};
+ HStatus status = addListenerInternal<HCameraServiceListener>(
+ hCsListener, &cameraStatusAndIds);
+ if (status != HStatus::NO_ERROR) {
+ _hidl_cb(status, {});
return Void();
}
- if (hCsListener == nullptr) {
- ALOGE("%s listener must not be NULL", __FUNCTION__);
- _hidl_cb(HStatus::ILLEGAL_ARGUMENT, {});
+
+ hidl_vec<HCameraStatusAndId> hCameraStatusAndIds;
+ //Convert cameraStatusAndIds to HIDL and call callback
+ convertToHidl(cameraStatusAndIds, &hCameraStatusAndIds);
+ _hidl_cb(status, hCameraStatusAndIds);
+
+ return Void();
+}
+
+Return<void> HidlCameraService::addListener_2_1(const sp<HCameraServiceListener2_1>& hCsListener,
+ addListener_2_1_cb _hidl_cb) {
+ std::vector<hardware::CameraStatus> cameraStatusAndIds{};
+ HStatus status = addListenerInternal<HCameraServiceListener2_1>(
+ hCsListener, &cameraStatusAndIds);
+ if (status != HStatus::NO_ERROR) {
+ _hidl_cb(status, {});
return Void();
}
+
+ hidl_vec<frameworks::cameraservice::service::V2_1::CameraStatusAndId> hCameraStatusAndIds;
+ //Convert cameraStatusAndIds to HIDL and call callback
+ convertToHidl(cameraStatusAndIds, &hCameraStatusAndIds);
+ _hidl_cb(status, hCameraStatusAndIds);
+
+ return Void();
+}
+
+template<class T>
+HStatus HidlCameraService::addListenerInternal(const sp<T>& hCsListener,
+ std::vector<hardware::CameraStatus>* cameraStatusAndIds) {
+ if (mAidlICameraService == nullptr) {
+ return HStatus::UNKNOWN_ERROR;
+ }
+ if (hCsListener == nullptr || cameraStatusAndIds == nullptr) {
+ ALOGE("%s listener and cameraStatusAndIds must not be NULL", __FUNCTION__);
+ return HStatus::ILLEGAL_ARGUMENT;
+ }
sp<hardware::ICameraServiceListener> csListener = nullptr;
// Check the cache for previously registered callbacks
{
@@ -177,33 +212,27 @@
} else {
ALOGE("%s: Trying to add a listener %p already registered",
__FUNCTION__, hCsListener.get());
- _hidl_cb(HStatus::ILLEGAL_ARGUMENT, {});
- return Void();
+ return HStatus::ILLEGAL_ARGUMENT;
}
}
- std::vector<hardware::CameraStatus> cameraStatusAndIds{};
binder::Status serviceRet =
- mAidlICameraService->addListenerHelper(csListener, &cameraStatusAndIds, true);
+ mAidlICameraService->addListenerHelper(csListener, cameraStatusAndIds, true);
HStatus status = HStatus::NO_ERROR;
if (!serviceRet.isOk()) {
- ALOGE("%s: Unable to add camera device status listener", __FUNCTION__);
- status = B2HStatus(serviceRet);
- _hidl_cb(status, {});
- return Void();
+ ALOGE("%s: Unable to add camera device status listener", __FUNCTION__);
+ status = B2HStatus(serviceRet);
+ return status;
}
- cameraStatusAndIds.erase(std::remove_if(cameraStatusAndIds.begin(), cameraStatusAndIds.end(),
+ cameraStatusAndIds->erase(std::remove_if(cameraStatusAndIds->begin(), cameraStatusAndIds->end(),
[this](const hardware::CameraStatus& s) {
- bool supportsHAL3 = false;
- binder::Status sRet =
+ bool supportsHAL3 = false;
+ binder::Status sRet =
mAidlICameraService->supportsCameraApi(String16(s.cameraId),
hardware::ICameraService::API_VERSION_2, &supportsHAL3);
- return !sRet.isOk() || !supportsHAL3;
- }), cameraStatusAndIds.end());
- hidl_vec<HCameraStatusAndId> hCameraStatusAndIds;
- //Convert cameraStatusAndIds to HIDL and call callback
- convertToHidl(cameraStatusAndIds, &hCameraStatusAndIds);
- _hidl_cb(status, hCameraStatusAndIds);
- return Void();
+ return !sRet.isOk() || !supportsHAL3;
+ }), cameraStatusAndIds->end());
+
+ return HStatus::NO_ERROR;
}
Return<HStatus> HidlCameraService::removeListener(const sp<HCameraServiceListener>& hCsListener) {