Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 17 | #include <android-base/properties.h> |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 18 | |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 19 | #include <hidl/AidlCameraDeviceCallbacks.h> |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 20 | #include <hidl/AidlCameraServiceListener.h> |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 21 | #include <hidl/HidlCameraService.h> |
| 22 | #include <hidl/HidlCameraDeviceUser.h> |
| 23 | #include <hidl/Utils.h> |
Avichal Rakesh | fcb78cb | 2022-10-27 15:45:54 -0700 | [diff] [blame] | 24 | #include <aidl/AidlUtils.h> |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 25 | |
| 26 | #include <hidl/HidlTransportSupport.h> |
| 27 | |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 28 | #include <camera/CameraUtils.h> |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame] | 29 | #include <utils/AttributionAndPermissionUtils.h> |
Avichal Rakesh | 74b5ae7 | 2023-12-27 16:56:45 -0800 | [diff] [blame] | 30 | #include <utils/Utils.h> |
| 31 | |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | namespace frameworks { |
| 34 | namespace cameraservice { |
| 35 | namespace service { |
| 36 | namespace V2_0 { |
| 37 | namespace implementation { |
| 38 | |
| 39 | using frameworks::cameraservice::service::V2_0::implementation::HidlCameraService; |
| 40 | using hardware::hidl_vec; |
Jayant Chowdhary | 81d81b0 | 2024-02-15 19:13:39 +0000 | [diff] [blame] | 41 | using hardware::BnCameraService::ROTATION_OVERRIDE_NONE; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 42 | using hardware::cameraservice::utils::conversion::convertToHidl; |
| 43 | using hardware::cameraservice::utils::conversion::B2HStatus; |
| 44 | using hardware::Void; |
Avichal Rakesh | fcb78cb | 2022-10-27 15:45:54 -0700 | [diff] [blame] | 45 | using hardware::cameraservice::utils::conversion::aidl::filterVndkKeys; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 46 | |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 47 | using device::V2_0::implementation::H2BCameraDeviceCallbacks; |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 48 | using device::V2_1::implementation::HidlCameraDeviceUser; |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 49 | using service::V2_0::implementation::H2BCameraServiceListener; |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 50 | using HCameraMetadataType = frameworks::cameraservice::common::V2_0::CameraMetadataType; |
| 51 | using HVendorTag = frameworks::cameraservice::common::V2_0::VendorTag; |
| 52 | using HVendorTagSection = frameworks::cameraservice::common::V2_0::VendorTagSection; |
| 53 | using HProviderIdAndVendorTagSections = |
| 54 | frameworks::cameraservice::common::V2_0::ProviderIdAndVendorTagSections; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 55 | |
| 56 | sp<HidlCameraService> gHidlCameraService; |
| 57 | |
| 58 | sp<HidlCameraService> HidlCameraService::getInstance(android::CameraService *cs) { |
| 59 | gHidlCameraService = new HidlCameraService(cs); |
| 60 | return gHidlCameraService; |
| 61 | } |
| 62 | |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 63 | HidlCameraService::HidlCameraService(android::CameraService *cs) : mAidlICameraService(cs) { |
Avichal Rakesh | 74b5ae7 | 2023-12-27 16:56:45 -0800 | [diff] [blame] | 64 | mVndkVersion = getVNDKVersionFromProp(__ANDROID_API_FUTURE__); |
| 65 | } |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 66 | |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 67 | Return<void> |
| 68 | HidlCameraService::getCameraCharacteristics(const hidl_string& cameraId, |
| 69 | getCameraCharacteristics_cb _hidl_cb) { |
| 70 | android::CameraMetadata cameraMetadata; |
| 71 | HStatus status = HStatus::NO_ERROR; |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame] | 72 | AttributionSourceState clientAttribution = |
| 73 | AttributionAndPermissionUtils::buildAttributionSource( |
| 74 | hardware::ICameraService::USE_CALLING_PID, |
| 75 | hardware::ICameraService::USE_CALLING_UID, |
| 76 | kDefaultDeviceId); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 77 | binder::Status serviceRet = |
Austin Borger | 71d8f67 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 78 | mAidlICameraService->getCameraCharacteristics(cameraId, |
Jayant Chowdhary | 81d81b0 | 2024-02-15 19:13:39 +0000 | [diff] [blame] | 79 | /*targetSdkVersion*/__ANDROID_API_FUTURE__, ROTATION_OVERRIDE_NONE, |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame] | 80 | clientAttribution, 0, &cameraMetadata); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 81 | HCameraMetadata hidlMetadata; |
| 82 | if (!serviceRet.isOk()) { |
| 83 | switch(serviceRet.serviceSpecificErrorCode()) { |
| 84 | // No ERROR_CAMERA_DISCONNECTED since we're in the same process. |
| 85 | case hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT: |
| 86 | ALOGE("%s: Camera ID %s does not exist!", __FUNCTION__, cameraId.c_str()); |
| 87 | status = HStatus::ILLEGAL_ARGUMENT; |
| 88 | break; |
| 89 | default: |
| 90 | ALOGE("Get camera characteristics from camera service failed: %s", |
Tomasz Wasilczyk | 12b04a5 | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 91 | serviceRet.toString8().c_str()); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 92 | status = B2HStatus(serviceRet); |
| 93 | } |
| 94 | _hidl_cb(status, hidlMetadata); |
| 95 | return Void(); |
| 96 | } |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 97 | if (filterVndkKeys(mVndkVersion, cameraMetadata) != OK) { |
| 98 | ALOGE("%s: Unable to filter vndk metadata keys for version %d", __FUNCTION__, mVndkVersion); |
| 99 | _hidl_cb(HStatus::UNKNOWN_ERROR, hidlMetadata); |
| 100 | return Void(); |
| 101 | } |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 102 | const camera_metadata_t *rawMetadata = cameraMetadata.getAndLock(); |
| 103 | convertToHidl(rawMetadata, &hidlMetadata); |
| 104 | _hidl_cb(status, hidlMetadata); |
| 105 | cameraMetadata.unlock(rawMetadata); |
| 106 | return Void(); |
| 107 | } |
| 108 | |
| 109 | Return<void> HidlCameraService::connectDevice(const sp<HCameraDeviceCallback>& hCallback, |
| 110 | const hidl_string& cameraId, |
| 111 | connectDevice_cb _hidl_cb) { |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 112 | // Here, we first get ICameraDeviceUser from mAidlICameraService, then save |
| 113 | // that interface in the newly created HidlCameraDeviceUser impl class. |
| 114 | if (mAidlICameraService == nullptr) { |
| 115 | _hidl_cb(HStatus::UNKNOWN_ERROR, nullptr); |
| 116 | return Void(); |
| 117 | } |
| 118 | sp<hardware::camera2::ICameraDeviceUser> deviceRemote = nullptr; |
| 119 | // Create a hardware::camera2::ICameraDeviceCallback object which internally |
| 120 | // calls callback functions passed through hCallback. |
| 121 | sp<H2BCameraDeviceCallbacks> hybridCallbacks = new H2BCameraDeviceCallbacks(hCallback); |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 122 | if (!hybridCallbacks->initializeLooper(mVndkVersion)) { |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 123 | ALOGE("Unable to handle callbacks on device, cannot connect"); |
| 124 | _hidl_cb(HStatus::UNKNOWN_ERROR, nullptr); |
| 125 | return Void(); |
| 126 | } |
| 127 | sp<hardware::camera2::ICameraDeviceCallbacks> callbacks = hybridCallbacks; |
Austin Borger | 65e6464 | 2024-06-11 15:58:23 -0700 | [diff] [blame] | 128 | AttributionSourceState clientAttribution = |
| 129 | AttributionAndPermissionUtils::buildAttributionSource( |
| 130 | hardware::ICameraService::USE_CALLING_PID, |
| 131 | hardware::ICameraService::USE_CALLING_UID, |
| 132 | kDefaultDeviceId); |
Austin Borger | d1ad6c6 | 2024-07-01 11:28:31 -0700 | [diff] [blame] | 133 | clientAttribution.packageName = ""; |
| 134 | clientAttribution.attributionTag = std::nullopt; |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 135 | binder::Status serviceRet = mAidlICameraService->connectDevice( |
Austin Borger | d1ad6c6 | 2024-07-01 11:28:31 -0700 | [diff] [blame] | 136 | callbacks, cameraId, 0/*oomScoreOffset*/, |
Jayant Chowdhary | 81d81b0 | 2024-02-15 19:13:39 +0000 | [diff] [blame] | 137 | /*targetSdkVersion*/__ANDROID_API_FUTURE__, ROTATION_OVERRIDE_NONE, |
Jyoti Bhayana | 1f9600b | 2024-10-29 20:25:32 -0700 | [diff] [blame] | 138 | clientAttribution, /*devicePolicy*/0, /*sharedMode*/false, /*out*/&deviceRemote); |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 139 | HStatus status = HStatus::NO_ERROR; |
| 140 | if (!serviceRet.isOk()) { |
| 141 | ALOGE("%s: Unable to connect to camera device", __FUNCTION__); |
| 142 | status = B2HStatus(serviceRet); |
| 143 | _hidl_cb(status, nullptr); |
| 144 | return Void(); |
| 145 | } |
| 146 | // Now we create a HidlCameraDeviceUser class, store the deviceRemote in it, |
| 147 | // and return that back. All calls on that interface will be forwarded to |
| 148 | // the AIDL interface. |
| 149 | sp<HidlCameraDeviceUser> hDeviceRemote = new HidlCameraDeviceUser(deviceRemote); |
| 150 | if (!hDeviceRemote->initStatus()) { |
| 151 | ALOGE("%s: Unable to initialize camera device HIDL wrapper", __FUNCTION__); |
| 152 | _hidl_cb(HStatus::UNKNOWN_ERROR, nullptr); |
| 153 | return Void(); |
| 154 | } |
| 155 | hybridCallbacks->setCaptureResultMetadataQueue(hDeviceRemote->getCaptureResultMetadataQueue()); |
| 156 | _hidl_cb(status, hDeviceRemote); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 157 | return Void(); |
| 158 | } |
| 159 | |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 160 | void HidlCameraService::addToListenerCacheLocked(sp<HCameraServiceListener> hListener, |
| 161 | sp<hardware::ICameraServiceListener> csListener) { |
| 162 | mListeners.emplace_back(std::make_pair(hListener, csListener)); |
| 163 | } |
| 164 | |
| 165 | sp<hardware::ICameraServiceListener> |
| 166 | HidlCameraService::searchListenerCacheLocked(sp<HCameraServiceListener> hListener, |
| 167 | bool shouldRemove) { |
| 168 | // Go through the mListeners list and compare the listener with the HIDL |
| 169 | // listener registered. |
| 170 | auto it = mListeners.begin(); |
| 171 | sp<ICameraServiceListener> csListener = nullptr; |
| 172 | for (;it != mListeners.end(); it++) { |
| 173 | if (hardware::interfacesEqual(it->first, hListener)) { |
| 174 | break; |
| 175 | } |
| 176 | } |
| 177 | if (it != mListeners.end()) { |
| 178 | csListener = it->second; |
| 179 | if (shouldRemove) { |
| 180 | mListeners.erase(it); |
| 181 | } |
| 182 | } |
| 183 | return csListener; |
| 184 | } |
| 185 | |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 186 | Return<void> HidlCameraService::addListener(const sp<HCameraServiceListener>& hCsListener, |
| 187 | addListener_cb _hidl_cb) { |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 188 | std::vector<hardware::CameraStatus> cameraStatusAndIds{}; |
| 189 | HStatus status = addListenerInternal<HCameraServiceListener>( |
| 190 | hCsListener, &cameraStatusAndIds); |
| 191 | if (status != HStatus::NO_ERROR) { |
| 192 | _hidl_cb(status, {}); |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 193 | return Void(); |
| 194 | } |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 195 | |
| 196 | hidl_vec<HCameraStatusAndId> hCameraStatusAndIds; |
| 197 | //Convert cameraStatusAndIds to HIDL and call callback |
| 198 | convertToHidl(cameraStatusAndIds, &hCameraStatusAndIds); |
| 199 | _hidl_cb(status, hCameraStatusAndIds); |
| 200 | |
| 201 | return Void(); |
| 202 | } |
| 203 | |
| 204 | Return<void> HidlCameraService::addListener_2_1(const sp<HCameraServiceListener2_1>& hCsListener, |
| 205 | addListener_2_1_cb _hidl_cb) { |
| 206 | std::vector<hardware::CameraStatus> cameraStatusAndIds{}; |
| 207 | HStatus status = addListenerInternal<HCameraServiceListener2_1>( |
| 208 | hCsListener, &cameraStatusAndIds); |
| 209 | if (status != HStatus::NO_ERROR) { |
| 210 | _hidl_cb(status, {}); |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 211 | return Void(); |
| 212 | } |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 213 | |
| 214 | hidl_vec<frameworks::cameraservice::service::V2_1::CameraStatusAndId> hCameraStatusAndIds; |
| 215 | //Convert cameraStatusAndIds to HIDL and call callback |
| 216 | convertToHidl(cameraStatusAndIds, &hCameraStatusAndIds); |
| 217 | _hidl_cb(status, hCameraStatusAndIds); |
| 218 | |
| 219 | return Void(); |
| 220 | } |
| 221 | |
| 222 | template<class T> |
| 223 | HStatus HidlCameraService::addListenerInternal(const sp<T>& hCsListener, |
| 224 | std::vector<hardware::CameraStatus>* cameraStatusAndIds) { |
| 225 | if (mAidlICameraService == nullptr) { |
| 226 | return HStatus::UNKNOWN_ERROR; |
| 227 | } |
| 228 | if (hCsListener == nullptr || cameraStatusAndIds == nullptr) { |
| 229 | ALOGE("%s listener and cameraStatusAndIds must not be NULL", __FUNCTION__); |
| 230 | return HStatus::ILLEGAL_ARGUMENT; |
| 231 | } |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 232 | sp<hardware::ICameraServiceListener> csListener = nullptr; |
| 233 | // Check the cache for previously registered callbacks |
| 234 | { |
| 235 | Mutex::Autolock l(mListenerListLock); |
| 236 | csListener = searchListenerCacheLocked(hCsListener); |
| 237 | if (csListener == nullptr) { |
| 238 | // Wrap an hCsListener with AidlCameraServiceListener and pass it to |
| 239 | // CameraService. |
| 240 | csListener = new H2BCameraServiceListener(hCsListener); |
| 241 | // Add to cache |
| 242 | addToListenerCacheLocked(hCsListener, csListener); |
| 243 | } else { |
| 244 | ALOGE("%s: Trying to add a listener %p already registered", |
| 245 | __FUNCTION__, hCsListener.get()); |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 246 | return HStatus::ILLEGAL_ARGUMENT; |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
Jayant Chowdhary | f949ddd | 2019-01-29 14:34:11 -0800 | [diff] [blame] | 249 | binder::Status serviceRet = |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 250 | mAidlICameraService->addListenerHelper(csListener, cameraStatusAndIds, true); |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 251 | HStatus status = HStatus::NO_ERROR; |
| 252 | if (!serviceRet.isOk()) { |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 253 | ALOGE("%s: Unable to add camera device status listener", __FUNCTION__); |
| 254 | status = B2HStatus(serviceRet); |
| 255 | return status; |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 256 | } |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 257 | cameraStatusAndIds->erase(std::remove_if(cameraStatusAndIds->begin(), cameraStatusAndIds->end(), |
Jayant Chowdhary | 90e6369 | 2019-10-25 14:13:01 -0700 | [diff] [blame] | 258 | [this](const hardware::CameraStatus& s) { |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 259 | bool supportsHAL3 = false; |
| 260 | binder::Status sRet = |
Austin Borger | 71d8f67 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 261 | mAidlICameraService->supportsCameraApi(s.cameraId, |
Jayant Chowdhary | 90e6369 | 2019-10-25 14:13:01 -0700 | [diff] [blame] | 262 | hardware::ICameraService::API_VERSION_2, &supportsHAL3); |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 263 | return !sRet.isOk() || !supportsHAL3; |
| 264 | }), cameraStatusAndIds->end()); |
| 265 | |
| 266 | return HStatus::NO_ERROR; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | Return<HStatus> HidlCameraService::removeListener(const sp<HCameraServiceListener>& hCsListener) { |
| 270 | if (hCsListener == nullptr) { |
| 271 | ALOGE("%s listener must not be NULL", __FUNCTION__); |
| 272 | return HStatus::ILLEGAL_ARGUMENT; |
| 273 | } |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 274 | sp<ICameraServiceListener> csListener = nullptr; |
| 275 | { |
| 276 | Mutex::Autolock l(mListenerListLock); |
| 277 | csListener = searchListenerCacheLocked(hCsListener, /*removeIfFound*/true); |
| 278 | } |
| 279 | if (csListener != nullptr) { |
| 280 | mAidlICameraService->removeListener(csListener); |
| 281 | } else { |
| 282 | ALOGE("%s Removing unregistered listener %p", __FUNCTION__, hCsListener.get()); |
| 283 | return HStatus::ILLEGAL_ARGUMENT; |
| 284 | } |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 285 | return HStatus::NO_ERROR; |
| 286 | } |
| 287 | |
| 288 | Return<void> HidlCameraService::getCameraVendorTagSections(getCameraVendorTagSections_cb _hidl_cb) { |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 289 | sp<VendorTagDescriptorCache> gCache = VendorTagDescriptorCache::getGlobalVendorTagCache(); |
| 290 | if (gCache == nullptr) { |
| 291 | _hidl_cb(HStatus::UNKNOWN_ERROR, {}); |
| 292 | return Void(); |
| 293 | } |
| 294 | const std::unordered_map<metadata_vendor_id_t, sp<android::VendorTagDescriptor>> |
| 295 | &vendorIdsAndTagDescs = gCache->getVendorIdsAndTagDescriptors(); |
| 296 | if (vendorIdsAndTagDescs.size() == 0) { |
| 297 | _hidl_cb(HStatus::UNKNOWN_ERROR, {}); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 298 | return Void(); |
| 299 | } |
| 300 | |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 301 | hidl_vec<HProviderIdAndVendorTagSections> hTagIdsAndVendorTagSections; |
| 302 | hTagIdsAndVendorTagSections.resize(vendorIdsAndTagDescs.size()); |
| 303 | size_t j = 0; |
| 304 | for (auto &vendorIdAndTagDescs : vendorIdsAndTagDescs) { |
| 305 | hidl_vec<HVendorTagSection> hVendorTagSections; |
| 306 | sp<VendorTagDescriptor> desc = vendorIdAndTagDescs.second; |
| 307 | const SortedVector<String8>* sectionNames = desc->getAllSectionNames(); |
| 308 | size_t numSections = sectionNames->size(); |
| 309 | std::vector<std::vector<HVendorTag>> tagsBySection(numSections); |
| 310 | int tagCount = desc->getTagCount(); |
Jayant Chowdhary | 925a27f | 2021-09-13 16:25:07 -0700 | [diff] [blame] | 311 | if (tagCount <= 0) { |
| 312 | continue; |
| 313 | } |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 314 | std::vector<uint32_t> tags(tagCount); |
| 315 | desc->getTagArray(tags.data()); |
| 316 | for (int i = 0; i < tagCount; i++) { |
| 317 | HVendorTag vt; |
| 318 | vt.tagId = tags[i]; |
| 319 | vt.tagName = desc->getTagName(tags[i]); |
| 320 | vt.tagType = (HCameraMetadataType) desc->getTagType(tags[i]); |
| 321 | ssize_t sectionIdx = desc->getSectionIndex(tags[i]); |
| 322 | tagsBySection[sectionIdx].push_back(vt); |
| 323 | } |
| 324 | hVendorTagSections.resize(numSections); |
| 325 | for (size_t s = 0; s < numSections; s++) { |
Tomasz Wasilczyk | 12b04a5 | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 326 | hVendorTagSections[s].sectionName = (*sectionNames)[s].c_str(); |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 327 | hVendorTagSections[s].tags = tagsBySection[s]; |
| 328 | } |
| 329 | HProviderIdAndVendorTagSections &hProviderIdAndVendorTagSections = |
| 330 | hTagIdsAndVendorTagSections[j]; |
| 331 | hProviderIdAndVendorTagSections.providerId = vendorIdAndTagDescs.first; |
| 332 | hProviderIdAndVendorTagSections.vendorTagSections = std::move(hVendorTagSections); |
| 333 | j++; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 334 | } |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 335 | _hidl_cb(HStatus::NO_ERROR, hTagIdsAndVendorTagSections); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 336 | return Void(); |
| 337 | } |
| 338 | |
| 339 | } // implementation |
| 340 | } // V2_0 |
| 341 | } // service |
| 342 | } // cameraservice |
| 343 | } // frameworks |
| 344 | } // android |
| 345 | |