From d3feb3d62c139f08879bbb7f7a0513d593dafcc0 Mon Sep 17 00:00:00 2001 From: Shuzhen Wang Date: Fri, 17 Aug 2018 13:52:40 -0700 Subject: [PATCH] Camera: Add support for physical camera characteristics query - Add version 3.5 for ICameraDevice for physical camera characteristics query. - Add version 3.5 for ICameraDeviceSession to work around HIDL versioning bug. Test: Camera CTS Bug: 79523700 Change-Id: I8df6cdd4ee6ac5755758510c0dc1ea1cec31aa73 --- camera/common/1.0/default/CameraModule.cpp | 35 ++++++ .../common/1.0/default/include/CameraModule.h | 2 + camera/device/3.2/default/CameraDevice.cpp | 8 +- camera/device/3.2/default/CameraDevice_3_2.h | 54 +++++++-- camera/device/3.5/Android.bp | 23 ++++ camera/device/3.5/ICameraDevice.hal | 62 ++++++++++ camera/device/3.5/ICameraDeviceSession.hal | 29 +++++ camera/device/3.5/default/Android.bp | 53 +++++++++ camera/device/3.5/default/CameraDevice.cpp | 86 ++++++++++++++ .../device_v3_5_impl/CameraDevice_3_5.h | 107 ++++++++++++++++++ camera/provider/2.4/Android.bp | 1 + camera/provider/2.4/default/Android.bp | 5 + .../provider/2.4/default/CameraProvider.cpp | 48 ++++---- 13 files changed, 484 insertions(+), 29 deletions(-) create mode 100644 camera/device/3.5/Android.bp create mode 100644 camera/device/3.5/ICameraDevice.hal create mode 100644 camera/device/3.5/ICameraDeviceSession.hal create mode 100644 camera/device/3.5/default/Android.bp create mode 100644 camera/device/3.5/default/CameraDevice.cpp create mode 100644 camera/device/3.5/default/include/device_v3_5_impl/CameraDevice_3_5.h diff --git a/camera/common/1.0/default/CameraModule.cpp b/camera/common/1.0/default/CameraModule.cpp index dc4e0f01ff..eb840a74f4 100644 --- a/camera/common/1.0/default/CameraModule.cpp +++ b/camera/common/1.0/default/CameraModule.cpp @@ -319,6 +319,41 @@ int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) { return OK; } +int CameraModule::getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo) { + ATRACE_CALL(); + Mutex::Autolock lock(mCameraInfoLock); + if (physicalCameraId < 0) { + ALOGE("%s: Invalid physical camera ID %d", __FUNCTION__, physicalCameraId); + return -EINVAL; + } + + // Only query physical camera info for 2.5 version for newer + int apiVersion = mModule->common.module_api_version; + if (apiVersion < CAMERA_MODULE_API_VERSION_2_5) { + ALOGE("%s: Module version must be at least 2.5 to handle getPhysicalCameraInfo", + __FUNCTION__); + return -ENODEV; + } + + ssize_t index = mPhysicalCameraInfoMap.indexOfKey(physicalCameraId); + if (index == NAME_NOT_FOUND) { + // Get physical camera characteristics, and cache it + camera_metadata_t *info = nullptr; + ATRACE_BEGIN("camera_module->get_physical_camera_info"); + int ret = mModule->get_physical_camera_info(physicalCameraId, &info); + ATRACE_END(); + if (ret != 0) { + return ret; + } + + index = mPhysicalCameraInfoMap.add(physicalCameraId, info); + } + + assert(index != NAME_NOT_FOUND); + *physicalInfo = mPhysicalCameraInfoMap[index]; + return OK; +} + int CameraModule::getDeviceVersion(int cameraId) { ssize_t index = mDeviceVersionMap.indexOfKey(cameraId); if (index == NAME_NOT_FOUND) { diff --git a/camera/common/1.0/default/include/CameraModule.h b/camera/common/1.0/default/include/CameraModule.h index deebd09480..ed853bf85f 100644 --- a/camera/common/1.0/default/include/CameraModule.h +++ b/camera/common/1.0/default/include/CameraModule.h @@ -65,6 +65,7 @@ public: void *getDso(); // Only used by CameraProvider void removeCamera(int cameraId); + int getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo); private: // Derive camera characteristics keys defined after HAL device version @@ -76,6 +77,7 @@ private: camera_module_t *mModule; KeyedVector mCameraInfoMap; KeyedVector mDeviceVersionMap; + KeyedVector mPhysicalCameraInfoMap; Mutex mCameraInfoLock; }; diff --git a/camera/device/3.2/default/CameraDevice.cpp b/camera/device/3.2/default/CameraDevice.cpp index dfbb9768a4..2e80ce8631 100644 --- a/camera/device/3.2/default/CameraDevice.cpp +++ b/camera/device/3.2/default/CameraDevice.cpp @@ -101,7 +101,7 @@ Status CameraDevice::getHidlStatus(int status) { } // Methods from ::android::hardware::camera::device::V3_2::ICameraDevice follow. -Return CameraDevice::getResourceCost(getResourceCost_cb _hidl_cb) { +Return CameraDevice::getResourceCost(ICameraDevice::getResourceCost_cb _hidl_cb) { Status status = initStatus(); CameraResourceCost resCost; if (status == Status::OK) { @@ -141,7 +141,8 @@ Return CameraDevice::getResourceCost(getResourceCost_cb _hidl_cb) { return Void(); } -Return CameraDevice::getCameraCharacteristics(getCameraCharacteristics_cb _hidl_cb) { +Return CameraDevice::getCameraCharacteristics( + ICameraDevice::getCameraCharacteristics_cb _hidl_cb) { Status status = initStatus(); CameraMetadata cameraCharacteristics; if (status == Status::OK) { @@ -172,7 +173,8 @@ Return CameraDevice::setTorchMode(TorchMode mode) { return status; } -Return CameraDevice::open(const sp& callback, open_cb _hidl_cb) { +Return CameraDevice::open(const sp& callback, + ICameraDevice::open_cb _hidl_cb) { Status status = initStatus(); sp session = nullptr; diff --git a/camera/device/3.2/default/CameraDevice_3_2.h b/camera/device/3.2/default/CameraDevice_3_2.h index 9534707bd0..f4745337f8 100644 --- a/camera/device/3.2/default/CameraDevice_3_2.h +++ b/camera/device/3.2/default/CameraDevice_3_2.h @@ -51,7 +51,7 @@ using ::android::Mutex; /* * The camera device HAL implementation is opened lazily (via the open call) */ -struct CameraDevice : public ICameraDevice { +struct CameraDevice : public virtual RefBase { // Called by provider HAL. Provider HAL must ensure the uniqueness of // CameraDevice object per cameraId, or there could be multiple CameraDevice // trying to access the same physical camera. @@ -60,7 +60,14 @@ struct CameraDevice : public ICameraDevice { CameraDevice(sp module, const std::string& cameraId, const SortedVector>& cameraDeviceNames); - ~CameraDevice(); + virtual ~CameraDevice(); + + // Retrieve the HIDL interface, split into its own class to avoid inheritance issues when + // dealing with minor version revs and simultaneous implementation and interface inheritance + virtual sp getInterface() { + return new TrampolineDeviceInterface_3_2(this); + } + // Caller must use this method to check if CameraDevice ctor failed bool isInitFailed() { return mInitFail; } // Used by provider HAL to signal external camera disconnected @@ -68,16 +75,16 @@ struct CameraDevice : public ICameraDevice { /* Methods from ::android::hardware::camera::device::V3_2::ICameraDevice follow. */ // The following method can be called without opening the actual camera device - Return getResourceCost(getResourceCost_cb _hidl_cb) override; - Return getCameraCharacteristics(getCameraCharacteristics_cb _hidl_cb) override; - Return setTorchMode(TorchMode mode) override; + Return getResourceCost(ICameraDevice::getResourceCost_cb _hidl_cb); + Return getCameraCharacteristics(ICameraDevice::getCameraCharacteristics_cb _hidl_cb); + Return setTorchMode(TorchMode mode); // Open the device HAL and also return a default capture session - Return open(const sp& callback, open_cb _hidl_cb) override; + Return open(const sp& callback, ICameraDevice::open_cb _hidl_cb); // Forward the dump call to the opened session, or do nothing - Return dumpState(const ::android::hardware::hidl_handle& fd) override; + Return dumpState(const ::android::hardware::hidl_handle& fd); /* End of Methods from ::android::hardware::camera::device::V3_2::ICameraDevice */ protected: @@ -106,6 +113,39 @@ protected: static Status getHidlStatus(int); Status initStatus() const; + +private: + struct TrampolineDeviceInterface_3_2 : public ICameraDevice { + TrampolineDeviceInterface_3_2(sp parent) : + mParent(parent) {} + + virtual Return getResourceCost(V3_2::ICameraDevice::getResourceCost_cb _hidl_cb) + override { + return mParent->getResourceCost(_hidl_cb); + } + + virtual Return getCameraCharacteristics( + V3_2::ICameraDevice::getCameraCharacteristics_cb _hidl_cb) override { + return mParent->getCameraCharacteristics(_hidl_cb); + } + + virtual Return setTorchMode(TorchMode mode) override { + return mParent->setTorchMode(mode); + } + + virtual Return open(const sp& callback, + V3_2::ICameraDevice::open_cb _hidl_cb) override { + return mParent->open(callback, _hidl_cb); + } + + virtual Return dumpState(const hidl_handle& fd) override { + return mParent->dumpState(fd); + } + + private: + sp mParent; + }; + }; } // namespace implementation diff --git a/camera/device/3.5/Android.bp b/camera/device/3.5/Android.bp new file mode 100644 index 0000000000..a4e9ee2243 --- /dev/null +++ b/camera/device/3.5/Android.bp @@ -0,0 +1,23 @@ +// This file is autogenerated by hidl-gen -Landroidbp. + +hidl_interface { + name: "android.hardware.camera.device@3.5", + root: "android.hardware", + vndk: { + enabled: true, + }, + srcs: [ + "ICameraDevice.hal", + "ICameraDeviceSession.hal", + ], + interfaces: [ + "android.hardware.camera.common@1.0", + "android.hardware.camera.device@3.2", + "android.hardware.camera.device@3.3", + "android.hardware.camera.device@3.4", + "android.hardware.graphics.common@1.0", + "android.hidl.base@1.0", + ], + gen_java: false, +} + diff --git a/camera/device/3.5/ICameraDevice.hal b/camera/device/3.5/ICameraDevice.hal new file mode 100644 index 0000000000..e7e8dd343f --- /dev/null +++ b/camera/device/3.5/ICameraDevice.hal @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.camera.device@3.5; + +import android.hardware.camera.common@1.0::Status; +import @3.2::CameraMetadata; +import @3.2::ICameraDevice; + +/** + * Camera device interface + * + * Supports the android.hardware.Camera API, and the android.hardware.camera2 + * API at LIMITED or better hardware level. + * + */ +interface ICameraDevice extends @3.2::ICameraDevice { + + /** + * getPhysicalCameraCharacteristics: + * + * Return the static camera information for a physical camera ID backing + * this logical camera device. This information may not change between consecutive calls. + * + * Note that HAL must support this function for physical camera IDs that are + * not exposed via ICameraProvider::getCameraIdList(). + * + * @return status Status code for the operation, one of: + * OK: + * On a successful query of the camera device characteristics + * INTERNAL_ERROR: + * The camera device cannot be opened due to an internal + * error. + * CAMERA_DISCONNECTED: + * An external camera device has been disconnected, and is no longer + * available. This camera device interface is now stale, and a new + * instance must be acquired if the device is reconnected. All + * subsequent calls on this interface must return + * CAMERA_DISCONNECTED. + * + * @return cameraCharacteristics + * The static metadata for this logical camera device's physical device, or an empty + * metadata structure if status is not OK. + * + */ + getPhysicalCameraCharacteristics(string physicalCameraId) + generates (Status status, CameraMetadata cameraCharacteristics); + +}; diff --git a/camera/device/3.5/ICameraDeviceSession.hal b/camera/device/3.5/ICameraDeviceSession.hal new file mode 100644 index 0000000000..84066851e9 --- /dev/null +++ b/camera/device/3.5/ICameraDeviceSession.hal @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware.camera.device@3.5; + +import android.hardware.camera.common@1.0::Status; +import @3.4::ICameraDeviceSession; + +/** + * Camera device active session interface. + * + * Obtained via ICameraDevice::open(), this interface contains the methods to + * configure and request captures from an active camera device. + */ +interface ICameraDeviceSession extends @3.4::ICameraDeviceSession { +}; diff --git a/camera/device/3.5/default/Android.bp b/camera/device/3.5/default/Android.bp new file mode 100644 index 0000000000..341f573b7f --- /dev/null +++ b/camera/device/3.5/default/Android.bp @@ -0,0 +1,53 @@ +// +// Copyright (C) 2018 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +cc_library_headers { + name: "camera.device@3.5-impl_headers", + vendor: true, + export_include_dirs: ["include/device_v3_5_impl"] +} + +cc_library_shared { + name: "camera.device@3.5-impl", + defaults: ["hidl_defaults"], + proprietary: true, + vendor: true, + srcs: [ + "CameraDevice.cpp", + ], + shared_libs: [ + "libhidlbase", + "libhidltransport", + "libutils", + "libcutils", + "camera.device@3.2-impl", + "camera.device@3.3-impl", + "camera.device@3.4-impl", + "android.hardware.camera.device@3.2", + "android.hardware.camera.device@3.3", + "android.hardware.camera.device@3.4", + "android.hardware.camera.device@3.5", + "android.hardware.camera.provider@2.4", + "android.hardware.graphics.mapper@2.0", + "liblog", + "libhardware", + "libcamera_metadata", + ], + static_libs: [ + "android.hardware.camera.common@1.0-helper", + ], + local_include_dirs: ["include/device_v3_5_impl"], +} diff --git a/camera/device/3.5/default/CameraDevice.cpp b/camera/device/3.5/default/CameraDevice.cpp new file mode 100644 index 0000000000..fcd1c96565 --- /dev/null +++ b/camera/device/3.5/default/CameraDevice.cpp @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "CamDev@3.5-impl" +#include + +#include "CameraModule.h" +#include "CameraDevice_3_5.h" + +namespace android { +namespace hardware { +namespace camera { +namespace device { +namespace V3_5 { +namespace implementation { + +using namespace ::android::hardware::camera::device; +using ::android::hardware::camera::common::V1_0::Status; +using ::android::hardware::camera::device::V3_2::CameraMetadata; + +CameraDevice::CameraDevice(sp module, const std::string& cameraId, + const SortedVector>& cameraDeviceNames) : + V3_4::implementation::CameraDevice(module, cameraId, cameraDeviceNames) { +} + +CameraDevice::~CameraDevice() { +} + +Return CameraDevice::getPhysicalCameraCharacteristics(const hidl_string& physicalCameraId, + V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) { + Status status = initStatus(); + CameraMetadata cameraCharacteristics; + if (status == Status::OK) { + // Require module 2.5+ version. + if (mModule->getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_5) { + ALOGE("%s: get_physical_camera_info must be called on camera module 2.5 or newer", + __FUNCTION__); + status = Status::INTERNAL_ERROR; + } else { + char *end; + errno = 0; + long id = strtol(physicalCameraId.c_str(), &end, 0); + if (id > INT_MAX || (errno == ERANGE && id == LONG_MAX) || + id < INT_MIN || (errno == ERANGE && id == LONG_MIN) || + *end != '\0') { + ALOGE("%s: Invalid physicalCameraId %s", __FUNCTION__, physicalCameraId.c_str()); + status = Status::ILLEGAL_ARGUMENT; + } else { + camera_metadata_t *physicalInfo = nullptr; + int ret = mModule->getPhysicalCameraInfo((int)id, &physicalInfo); + if (ret == OK) { + V3_2::implementation::convertToHidl(physicalInfo, &cameraCharacteristics); + } else { + ALOGE("%s: Failed to get physical camera %s info: %s (%d)!", __FUNCTION__, + physicalCameraId.c_str(), strerror(-ret), ret); + status = Status::INTERNAL_ERROR; + } + } + } + } + _hidl_cb(status, cameraCharacteristics); + return Void(); +} + +// End of methods from ::android::hardware::camera::device::V3_2::ICameraDevice. + +} // namespace implementation +} // namespace V3_5 +} // namespace device +} // namespace camera +} // namespace hardware +} // namespace android + diff --git a/camera/device/3.5/default/include/device_v3_5_impl/CameraDevice_3_5.h b/camera/device/3.5/default/include/device_v3_5_impl/CameraDevice_3_5.h new file mode 100644 index 0000000000..f250bc9669 --- /dev/null +++ b/camera/device/3.5/default/include/device_v3_5_impl/CameraDevice_3_5.h @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2018 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ANDROID_HARDWARE_CAMERA_DEVICE_V3_5_CAMERADEVICE_H +#define ANDROID_HARDWARE_CAMERA_DEVICE_V3_5_CAMERADEVICE_H + +#include "CameraModule.h" +#include <../../../../3.4/default/include/device_v3_4_impl/CameraDevice_3_4.h> + +#include + +namespace android { +namespace hardware { +namespace camera { +namespace device { +namespace V3_5 { +namespace implementation { + +using namespace ::android::hardware::camera::device; + +using ::android::hardware::camera::common::V1_0::helper::CameraModule; +using ::android::hardware::Return; +using ::android::hardware::Void; +using ::android::hardware::hidl_string; +using ::android::hardware::camera::common::V1_0::TorchMode; +using ::android::hardware::camera::common::V1_0::helper::CameraModule; +using ::android::hardware::camera::common::V1_0::Status; +using ::android::sp; + +struct CameraDevice : public V3_4::implementation::CameraDevice { + // Called by provider HAL. + // Provider HAL must ensure the uniqueness of CameraDevice object per cameraId, or there could + // be multiple CameraDevice trying to access the same physical camera. Also, provider will have + // to keep track of all CameraDevice objects in order to notify CameraDevice when the underlying + // camera is detached. + // Delegates nearly all work to CameraDevice_3_4 + CameraDevice(sp module, + const std::string& cameraId, + const SortedVector>& cameraDeviceNames); + virtual ~CameraDevice(); + + virtual sp getInterface() override { + return new TrampolineDeviceInterface_3_5(this); + } + +protected: + Return getPhysicalCameraCharacteristics(const hidl_string& physicalCameraId, + V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb); + +private: + struct TrampolineDeviceInterface_3_5 : public ICameraDevice { + TrampolineDeviceInterface_3_5(sp parent) : + mParent(parent) {} + + virtual Return getResourceCost(V3_2::ICameraDevice::getResourceCost_cb _hidl_cb) + override { + return mParent->getResourceCost(_hidl_cb); + } + + virtual Return getCameraCharacteristics( + V3_2::ICameraDevice::getCameraCharacteristics_cb _hidl_cb) override { + return mParent->getCameraCharacteristics(_hidl_cb); + } + + virtual Return setTorchMode(TorchMode mode) override { + return mParent->setTorchMode(mode); + } + + virtual Return open(const sp& callback, + V3_2::ICameraDevice::open_cb _hidl_cb) override { + return mParent->open(callback, _hidl_cb); + } + + virtual Return dumpState(const hidl_handle& fd) override { + return mParent->dumpState(fd); + } + + virtual Return getPhysicalCameraCharacteristics(const hidl_string& physicalCameraId, + V3_5::ICameraDevice::getPhysicalCameraCharacteristics_cb _hidl_cb) override { + return mParent->getPhysicalCameraCharacteristics(physicalCameraId, _hidl_cb); + } + private: + sp mParent; + }; +}; + +} // namespace implementation +} // namespace V3_5 +} // namespace device +} // namespace camera +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_CAMERA_DEVICE_V3_5_CAMERADEVICE_H diff --git a/camera/provider/2.4/Android.bp b/camera/provider/2.4/Android.bp index 63d7fd5dca..27329f3b5d 100644 --- a/camera/provider/2.4/Android.bp +++ b/camera/provider/2.4/Android.bp @@ -14,6 +14,7 @@ hidl_interface { "android.hardware.camera.common@1.0", "android.hardware.camera.device@1.0", "android.hardware.camera.device@3.2", + "android.hardware.camera.device@3.5", "android.hidl.base@1.0", ], gen_java: false, diff --git a/camera/provider/2.4/default/Android.bp b/camera/provider/2.4/default/Android.bp index ae24d78143..de02d78a13 100644 --- a/camera/provider/2.4/default/Android.bp +++ b/camera/provider/2.4/default/Android.bp @@ -14,10 +14,12 @@ cc_library_shared { "android.hardware.camera.device@3.2", "android.hardware.camera.device@3.3", "android.hardware.camera.device@3.4", + "android.hardware.camera.device@3.5", "camera.device@1.0-impl", "camera.device@3.2-impl", "camera.device@3.3-impl", "camera.device@3.4-impl", + "camera.device@3.5-impl", "camera.device@3.4-external-impl", "android.hardware.camera.provider@2.4", "android.hardware.camera.common@1.0", @@ -31,6 +33,7 @@ cc_library_shared { ], header_libs: [ "camera.device@3.4-impl_headers", + "camera.device@3.5-impl_headers", "camera.device@3.4-external-impl_headers" ], static_libs: [ @@ -56,6 +59,7 @@ cc_binary { "android.hardware.camera.device@3.2", "android.hardware.camera.device@3.3", "android.hardware.camera.device@3.4", + "android.hardware.camera.device@3.5", "android.hardware.camera.provider@2.4", "android.hardware.camera.common@1.0", ], @@ -80,6 +84,7 @@ cc_binary { "android.hardware.camera.device@3.2", "android.hardware.camera.device@3.3", "android.hardware.camera.device@3.4", + "android.hardware.camera.device@3.5", "android.hardware.camera.provider@2.4", "android.hardware.camera.common@1.0", ], diff --git a/camera/provider/2.4/default/CameraProvider.cpp b/camera/provider/2.4/default/CameraProvider.cpp index 63139390cb..b69fe1a009 100644 --- a/camera/provider/2.4/default/CameraProvider.cpp +++ b/camera/provider/2.4/default/CameraProvider.cpp @@ -23,6 +23,7 @@ #include "CameraDevice_1_0.h" #include "CameraDevice_3_3.h" #include "CameraDevice_3_4.h" +#include "CameraDevice_3_5.h" #include #include #include @@ -43,6 +44,7 @@ const std::regex kDeviceNameRE("device@([0-9]+\\.[0-9]+)/legacy/(.+)"); const char *kHAL3_2 = "3.2"; const char *kHAL3_3 = "3.3"; const char *kHAL3_4 = "3.4"; +const char *kHAL3_5 = "3.5"; const char *kHAL1_0 = "1.0"; const int kMaxCameraDeviceNameLen = 128; const int kMaxCameraIdLen = 16; @@ -250,7 +252,11 @@ std::string CameraProvider::getHidlDeviceName( int versionMajor = isV1 ? 1 : 3; int versionMinor = isV1 ? 0 : mPreferredHal3MinorVersion; if (deviceVersion == CAMERA_DEVICE_API_VERSION_3_5) { - versionMinor = 4; + if (mModule->getModuleApiVersion() == CAMERA_MODULE_API_VERSION_2_5) { + versionMinor = 5; + } else { + versionMinor = 4; + } } char deviceName[kMaxCameraDeviceNameLen]; snprintf(deviceName, sizeof(deviceName), "device@%d.%d/legacy/%s", @@ -546,21 +552,31 @@ Return CameraProvider::getCameraDeviceInterface_V3_x( return Void(); } - sp device; - if (deviceVersion == kHAL3_4) { + sp deviceImpl; + if (deviceVersion >= kHAL3_4) { ALOGV("Constructing v3.4 camera device"); - sp deviceImpl = - new android::hardware::camera::device::V3_4::implementation::CameraDevice( + if (deviceVersion == kHAL3_4) { + deviceImpl = new android::hardware::camera::device::V3_4::implementation::CameraDevice( mModule, cameraId, mCameraDeviceNames); + } else if (deviceVersion == kHAL3_5) { + deviceImpl = new android::hardware::camera::device::V3_5::implementation::CameraDevice( + mModule, cameraId, mCameraDeviceNames); + } if (deviceImpl == nullptr || deviceImpl->isInitFailed()) { ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str()); - device = nullptr; _hidl_cb(Status::INTERNAL_ERROR, nullptr); return Void(); } - - device = deviceImpl; - _hidl_cb (Status::OK, device); + IF_ALOGV() { + deviceImpl->getInterface()->interfaceChain([]( + ::android::hardware::hidl_vec<::android::hardware::hidl_string> interfaceChain) { + ALOGV("Device interface chain:"); + for (auto iface : interfaceChain) { + ALOGV(" %s", iface.c_str()); + } + }); + } + _hidl_cb (Status::OK, deviceImpl->getInterface()); return Void(); } @@ -570,39 +586,33 @@ Return CameraProvider::getCameraDeviceInterface_V3_x( switch (mPreferredHal3MinorVersion) { case 2: { // Map legacy camera device v3 HAL to Treble camera device HAL v3.2 ALOGV("Constructing v3.2 camera device"); - sp deviceImpl = - new android::hardware::camera::device::V3_2::implementation::CameraDevice( + deviceImpl = new android::hardware::camera::device::V3_2::implementation::CameraDevice( mModule, cameraId, mCameraDeviceNames); if (deviceImpl == nullptr || deviceImpl->isInitFailed()) { ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str()); - device = nullptr; _hidl_cb(Status::INTERNAL_ERROR, nullptr); return Void(); } - device = deviceImpl; break; } case 3: { // Map legacy camera device v3 HAL to Treble camera device HAL v3.3 ALOGV("Constructing v3.3 camera device"); - sp deviceImpl = - new android::hardware::camera::device::V3_3::implementation::CameraDevice( + deviceImpl = new android::hardware::camera::device::V3_3::implementation::CameraDevice( mModule, cameraId, mCameraDeviceNames); if (deviceImpl == nullptr || deviceImpl->isInitFailed()) { ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str()); - device = nullptr; _hidl_cb(Status::INTERNAL_ERROR, nullptr); return Void(); } - device = deviceImpl; break; } default: ALOGE("%s: Unknown HAL minor version %d!", __FUNCTION__, mPreferredHal3MinorVersion); - device = nullptr; _hidl_cb(Status::INTERNAL_ERROR, nullptr); return Void(); } - _hidl_cb (Status::OK, device); + + _hidl_cb (Status::OK, deviceImpl->getInterface()); return Void(); }