1 /*
2 * Copyright (C) 2022 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 #include "AidlProviderInfo.h"
17 #include "common/HalConversionsTemplated.h"
18 #include "common/CameraProviderInfoTemplated.h"
19
20 #include <aidl/AidlUtils.h>
21
22 #include <com_android_internal_camera_flags.h>
23 #include <cutils/properties.h>
24
25 #include <aidlcommonsupport/NativeHandle.h>
26 #include <android_companion_virtualdevice_flags.h>
27 #include <android/binder_manager.h>
28 #include <android/hardware/ICameraService.h>
29 #include <camera_metadata_hidden.h>
30
31 #include "device3/DistortionMapper.h"
32 #include "device3/ZoomRatioMapper.h"
33 #include <utils/AttributionAndPermissionUtils.h>
34 #include <utils/SessionConfigurationUtils.h>
35 #include <utils/Trace.h>
36
37 namespace {
38 const bool kEnableLazyHal(property_get_bool("ro.camera.enableLazyHal", false));
39 } // anonymous namespace
40
41 namespace android {
42
43 namespace SessionConfigurationUtils = ::android::camera3::SessionConfigurationUtils;
44 namespace flags = com::android::internal::camera::flags;
45 namespace vd_flags = android::companion::virtualdevice::flags;
46
47 using namespace aidl::android::hardware;
48 using namespace hardware::camera;
49 using android::hardware::cameraservice::utils::conversion::aidl::copySessionCharacteristics;
50 using hardware::camera2::utils::CameraIdAndSessionConfiguration;
51 using hardware::ICameraService;
52 using SessionConfigurationUtils::overrideDefaultRequestKeys;
53
54 using HalDeviceStatusType = aidl::android::hardware::camera::common::CameraDeviceStatus;
55 using ICameraProvider = aidl::android::hardware::camera::provider::ICameraProvider;
56 using StatusListener = CameraProviderManager::StatusListener;
57
mapExceptionCodeToStatusT(binder_exception_t binderException)58 static status_t mapExceptionCodeToStatusT(binder_exception_t binderException) {
59 switch (binderException) {
60 case EX_NONE:
61 return OK;
62 case EX_ILLEGAL_ARGUMENT:
63 case EX_NULL_POINTER:
64 case EX_BAD_PARCELABLE:
65 case EX_ILLEGAL_STATE:
66 return BAD_VALUE;
67 case EX_UNSUPPORTED_OPERATION:
68 return INVALID_OPERATION;
69 case EX_TRANSACTION_FAILED:
70 return DEAD_OBJECT;
71 default:
72 return UNKNOWN_ERROR;
73 }
74 }
75
mapToStatusT(const ndk::ScopedAStatus & s)76 status_t AidlProviderInfo::mapToStatusT(const ndk::ScopedAStatus& s) {
77 using Status = aidl::android::hardware::camera::common::Status;
78 auto exceptionCode = s.getExceptionCode();
79 if (exceptionCode != EX_SERVICE_SPECIFIC) {
80 return mapExceptionCodeToStatusT(exceptionCode);
81 }
82 Status st = static_cast<Status>(s.getServiceSpecificError());
83 switch (st) {
84 case Status::OK:
85 return OK;
86 case Status::ILLEGAL_ARGUMENT:
87 return BAD_VALUE;
88 case Status::CAMERA_IN_USE:
89 return -EBUSY;
90 case Status::MAX_CAMERAS_IN_USE:
91 return -EUSERS;
92 case Status::OPERATION_NOT_SUPPORTED:
93 return INVALID_OPERATION;
94 case Status::CAMERA_DISCONNECTED:
95 return DEAD_OBJECT;
96 case Status::INTERNAL_ERROR:
97 return INVALID_OPERATION;
98 }
99 ALOGW("Unexpected HAL status code %d", static_cast<int>(st));
100 return INVALID_OPERATION;
101 }
102
AidlProviderInfo(const std::string & providerName,const std::string & providerInstance,CameraProviderManager * manager)103 AidlProviderInfo::AidlProviderInfo(
104 const std::string &providerName,
105 const std::string &providerInstance,
106 CameraProviderManager *manager) :
107 CameraProviderManager::ProviderInfo(providerName, providerInstance, manager) {}
108
initializeAidlProvider(std::shared_ptr<ICameraProvider> & interface,int64_t currentDeviceState)109 status_t AidlProviderInfo::initializeAidlProvider(
110 std::shared_ptr<ICameraProvider>& interface, int64_t currentDeviceState) {
111
112 using aidl::android::hardware::camera::provider::ICameraProvider;
113 std::string parsedProviderName =
114 mProviderName.substr(std::string(ICameraProvider::descriptor).size() + 1);
115
116 status_t res = parseProviderName(parsedProviderName, &mType, &mId);
117 if (res != OK) {
118 ALOGE("%s: Invalid provider name, ignoring", __FUNCTION__);
119 return BAD_VALUE;
120 }
121 ALOGI("Connecting to new camera provider: %s, isRemote? %d",
122 mProviderName.c_str(), interface->isRemote());
123
124 // cameraDeviceStatusChange callbacks may be called (and causing new devices added)
125 // before setCallback returns
126 mCallbacks =
127 ndk::SharedRefBase::make<AidlProviderCallbacks>(this);
128 ndk::ScopedAStatus status =
129 interface->setCallback(mCallbacks);
130 if (!status.isOk()) {
131 ALOGE("%s: Transaction error setting up callbacks with camera provider '%s': %s",
132 __FUNCTION__, mProviderName.c_str(), status.getMessage());
133 return mapToStatusT(status);
134 }
135
136 mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(binderDied));
137
138 if (!vd_flags::virtual_camera_service_discovery() || interface->isRemote()) {
139 binder_status_t link =
140 AIBinder_linkToDeath(interface->asBinder().get(), mDeathRecipient.get(), this);
141 if (link != STATUS_OK) {
142 ALOGW("%s: Unable to link to provider '%s' death notifications (%d)", __FUNCTION__,
143 mProviderName.c_str(), link);
144 return DEAD_OBJECT;
145 }
146 }
147
148 if (!kEnableLazyHal) {
149 // Save HAL reference indefinitely
150 mSavedInterface = interface;
151 } else {
152 mActiveInterface = interface;
153 }
154
155 ALOGV("%s: Setting device state for %s: 0x%" PRIx64,
156 __FUNCTION__, mProviderName.c_str(), mDeviceState);
157 notifyDeviceStateChange(currentDeviceState);
158
159 res = setUpVendorTags();
160 if (res != OK) {
161 ALOGE("%s: Unable to set up vendor tags from provider '%s'",
162 __FUNCTION__, mProviderName.c_str());
163 return res;
164 }
165
166 // Get initial list of camera devices, if any
167 std::vector<std::string> devices;
168 std::vector<std::string> retDevices;
169 status = interface->getCameraIdList(&retDevices);
170 if (!status.isOk()) {
171 ALOGE("%s: Transaction error in getting camera ID list from provider '%s': %s",
172 __FUNCTION__, mProviderName.c_str(), status.getMessage());
173 return mapToStatusT(status);
174 }
175
176 for (auto& name : retDevices) {
177 uint16_t major, minor;
178 std::string type, id;
179 status_t res = parseDeviceName(name, &major, &minor, &type, &id);
180 if (res != OK) {
181 ALOGE("%s: Error parsing deviceName: %s: %d", __FUNCTION__, name.c_str(), res);
182 return res;
183 } else {
184 devices.push_back(name);
185 mProviderPublicCameraIds.push_back(id);
186 }
187 }
188
189 // Get list of concurrent streaming camera device combinations
190 res = getConcurrentCameraIdsInternalLocked(interface);
191 if (res != OK) {
192 return res;
193 }
194
195 mSetTorchModeSupported = true;
196
197 mIsRemote = interface->isRemote();
198
199 initializeProviderInfoCommon(devices);
200 return OK;
201 }
202
binderDied(void * cookie)203 void AidlProviderInfo::binderDied(void *cookie) {
204 AidlProviderInfo *provider = reinterpret_cast<AidlProviderInfo *>(cookie);
205 ALOGI("Camera provider '%s' has died; removing it", provider->mProviderInstance.c_str());
206 provider->mManager->removeProvider(std::string(provider->mProviderInstance));
207 }
208
setUpVendorTags()209 status_t AidlProviderInfo::setUpVendorTags() {
210 if (mVendorTagDescriptor != nullptr)
211 return OK;
212
213 std::vector<camera::common::VendorTagSection> vts;
214 ::ndk::ScopedAStatus status;
215 const std::shared_ptr<ICameraProvider> interface = startProviderInterface();
216 if (interface == nullptr) {
217 return DEAD_OBJECT;
218 }
219 status = interface->getVendorTags(&vts);
220 if (!status.isOk()) {
221 ALOGE("%s: Transaction error getting vendor tags from provider '%s': %s",
222 __FUNCTION__, mProviderName.c_str(), status.getMessage());
223 return mapToStatusT(status);
224 }
225
226 // Read all vendor tag definitions into a descriptor
227 status_t res;
228 if ((res =
229 IdlVendorTagDescriptor::
230 createDescriptorFromIdl<std::vector<camera::common::VendorTagSection>,
231 camera::common::VendorTagSection>(vts, /*out*/mVendorTagDescriptor))
232 != OK) {
233 ALOGE("%s: Could not generate descriptor from vendor tag operations,"
234 "received error %s (%d). Camera clients will not be able to use"
235 "vendor tags", __FUNCTION__, strerror(res), res);
236 return res;
237 }
238
239 return OK;
240 }
241
notifyDeviceStateChange(int64_t newDeviceState)242 status_t AidlProviderInfo::notifyDeviceStateChange(int64_t newDeviceState) {
243
244 mDeviceState = newDeviceState;
245 // Check if the provider is currently active - not going to start it up for this notification
246 auto interface = mSavedInterface != nullptr ? mSavedInterface : mActiveInterface.lock();
247 if (interface != nullptr) {
248 // Send current device state
249 interface->notifyDeviceStateChange(mDeviceState);
250 }
251 return OK;
252 }
253
successfullyStartedProviderInterface()254 bool AidlProviderInfo::successfullyStartedProviderInterface() {
255 return startProviderInterface() != nullptr;
256 }
257
258 std::shared_ptr<camera::device::ICameraDevice>
startDeviceInterface(const std::string & name)259 AidlProviderInfo::startDeviceInterface(const std::string &name) {
260 ::ndk::ScopedAStatus status;
261 std::shared_ptr<camera::device::ICameraDevice> cameraInterface;
262 const std::shared_ptr<ICameraProvider> interface = startProviderInterface();
263 if (interface == nullptr) {
264 return nullptr;
265 }
266 status = interface->getCameraDeviceInterface(name, &cameraInterface);
267 if (!status.isOk()) {
268 ALOGE("%s: Transaction error trying to obtain interface for camera device %s: %s",
269 __FUNCTION__, name.c_str(), status.getMessage());
270 return nullptr;
271 }
272 return cameraInterface;
273 }
274
startProviderInterface()275 const std::shared_ptr<ICameraProvider> AidlProviderInfo::startProviderInterface() {
276 ATRACE_CALL();
277 ALOGV("Request to start camera provider: %s", mProviderName.c_str());
278 if (mSavedInterface != nullptr) {
279 return mSavedInterface;
280 }
281
282 if (!kEnableLazyHal) {
283 ALOGE("Bad provider state! Should not be here on a non-lazy HAL!");
284 return nullptr;
285 }
286
287 auto interface = mActiveInterface.lock();
288 if (interface != nullptr) {
289 ALOGV("Camera provider (%s) already in use. Re-using instance.", mProviderName.c_str());
290 return interface;
291 }
292
293 // Try to get service without starting
294 interface = ICameraProvider::fromBinder(
295 ndk::SpAIBinder(AServiceManager_checkService(mProviderName.c_str())));
296 if (interface != nullptr) {
297 // Service is already running. Cache and return.
298 mActiveInterface = interface;
299 return interface;
300 }
301
302 ALOGV("Camera provider actually needs restart, calling getService(%s)", mProviderName.c_str());
303 interface = mManager->mAidlServiceProxy->getService(mProviderName);
304
305 if (interface == nullptr) {
306 ALOGE("%s: %s service not started", __FUNCTION__, mProviderName.c_str());
307 return nullptr;
308 }
309
310 // Set all devices as ENUMERATING, provider should update status
311 // to PRESENT after initializing.
312 // This avoids failing getCameraDeviceInterface_V3_x before devices
313 // are ready.
314 for (auto& device : mDevices) {
315 device->mIsDeviceAvailable = false;
316 }
317
318 interface->setCallback(mCallbacks);
319 auto link = AIBinder_linkToDeath(interface->asBinder().get(), mDeathRecipient.get(),
320 this);
321 if (link != STATUS_OK) {
322 ALOGW("%s: Unable to link to provider '%s' death notifications",
323 __FUNCTION__, mProviderName.c_str());
324 mManager->removeProvider(std::string(mProviderInstance));
325 return nullptr;
326 }
327
328 // Send current device state
329 interface->notifyDeviceStateChange(mDeviceState);
330 // Cache interface to return early for future calls.
331 mActiveInterface = interface;
332
333 return interface;
334 }
335
cameraDeviceStatusChange(const std::string & cameraDeviceName,HalDeviceStatusType newStatus)336 ::ndk::ScopedAStatus AidlProviderInfo::AidlProviderCallbacks::cameraDeviceStatusChange(
337 const std::string& cameraDeviceName,
338 HalDeviceStatusType newStatus) {
339 sp<AidlProviderInfo> parent = mParent.promote();
340 if (parent == nullptr) {
341 ALOGE("%s: Parent provider not alive", __FUNCTION__);
342 return ::ndk::ScopedAStatus::ok();
343 }
344 return parent->cameraDeviceStatusChange(cameraDeviceName, newStatus);
345 }
346
torchModeStatusChange(const std::string & cameraDeviceName,aidl::android::hardware::camera::common::TorchModeStatus newStatus)347 ::ndk::ScopedAStatus AidlProviderInfo::AidlProviderCallbacks::torchModeStatusChange(
348 const std::string& cameraDeviceName,
349 aidl::android::hardware::camera::common::TorchModeStatus newStatus) {
350 sp<AidlProviderInfo> parent = mParent.promote();
351 if (parent == nullptr) {
352 ALOGE("%s: Parent provider not alive", __FUNCTION__);
353 return ::ndk::ScopedAStatus::ok();
354 }
355 return parent->torchModeStatusChange(cameraDeviceName, newStatus);
356
357 };
358
physicalCameraDeviceStatusChange(const std::string & cameraDeviceName,const std::string & physicalCameraDeviceName,HalDeviceStatusType newStatus)359 ::ndk::ScopedAStatus AidlProviderInfo::AidlProviderCallbacks::physicalCameraDeviceStatusChange(
360 const std::string& cameraDeviceName,
361 const std::string& physicalCameraDeviceName,
362 HalDeviceStatusType newStatus) {
363 sp<AidlProviderInfo> parent = mParent.promote();
364 if (parent == nullptr) {
365 ALOGE("%s: Parent provider not alive", __FUNCTION__);
366 return ::ndk::ScopedAStatus::ok();
367 }
368 return parent->physicalCameraDeviceStatusChange(cameraDeviceName, physicalCameraDeviceName,
369 newStatus);
370 };
371
cameraDeviceStatusChange(const std::string & cameraDeviceName,HalDeviceStatusType newStatus)372 ::ndk::ScopedAStatus AidlProviderInfo::cameraDeviceStatusChange(const std::string& cameraDeviceName,
373 HalDeviceStatusType newStatus) {
374 cameraDeviceStatusChangeInternal(cameraDeviceName, HalToFrameworkCameraDeviceStatus(newStatus));
375 return ::ndk::ScopedAStatus::ok();
376 }
377
torchModeStatusChange(const std::string & cameraDeviceName,aidl::android::hardware::camera::common::TorchModeStatus newStatus)378 ::ndk::ScopedAStatus AidlProviderInfo::torchModeStatusChange(const std::string& cameraDeviceName,
379 aidl::android::hardware::camera::common::TorchModeStatus newStatus) {
380 torchModeStatusChangeInternal(cameraDeviceName, HalToFrameworkTorchModeStatus(newStatus));
381 return ::ndk::ScopedAStatus::ok();
382 };
383
physicalCameraDeviceStatusChange(const std::string & cameraDeviceName,const std::string & physicalCameraDeviceName,HalDeviceStatusType newStatus)384 ::ndk::ScopedAStatus AidlProviderInfo::physicalCameraDeviceStatusChange(
385 const std::string& cameraDeviceName,
386 const std::string& physicalCameraDeviceName,
387 HalDeviceStatusType newStatus) {
388 physicalCameraDeviceStatusChangeInternal(cameraDeviceName, physicalCameraDeviceName,
389 HalToFrameworkCameraDeviceStatus(newStatus));
390 return ::ndk::ScopedAStatus::ok();
391 };
392
393 std::unique_ptr<CameraProviderManager::ProviderInfo::DeviceInfo>
initializeDeviceInfo(const std::string & name,const metadata_vendor_id_t tagId,const std::string & id,uint16_t)394 AidlProviderInfo::initializeDeviceInfo(
395 const std::string &name, const metadata_vendor_id_t tagId,
396 const std::string &id, uint16_t /*minorVersion*/) {
397 ::ndk::ScopedAStatus status;
398
399 auto cameraInterface = startDeviceInterface(name);
400 if (cameraInterface == nullptr) return nullptr;
401
402 camera::common::CameraResourceCost resourceCost;
403 status = cameraInterface->getResourceCost(&resourceCost);
404 if (!status.isOk()) {
405 ALOGE("%s: Unable to obtain resource costs for camera device %s: %s", __FUNCTION__,
406 name.c_str(), status.getMessage());
407 return nullptr;
408 }
409
410 for (auto& conflictName : resourceCost.conflictingDevices) {
411 uint16_t major, minor;
412 std::string type, id;
413 status_t res = parseDeviceName(conflictName, &major, &minor, &type, &id);
414 if (res != OK) {
415 ALOGE("%s: Failed to parse conflicting device %s", __FUNCTION__, conflictName.c_str());
416 return nullptr;
417 }
418 conflictName = id;
419 }
420
421 int32_t interfaceVersion = 0;
422 status = cameraInterface->getInterfaceVersion(&interfaceVersion);
423 if (!status.isOk()) {
424 ALOGE("%s: Unable to obtain interface version for camera device %s: %s", __FUNCTION__,
425 id.c_str(), status.getMessage());
426 return nullptr;
427 }
428
429 return std::unique_ptr<DeviceInfo3>(
430 new AidlDeviceInfo3(name, tagId, id, static_cast<uint16_t>(interfaceVersion),
431 HalToFrameworkResourceCost(resourceCost), this,
432 mProviderPublicCameraIds, cameraInterface));
433 }
434
reCacheConcurrentStreamingCameraIdsLocked()435 status_t AidlProviderInfo::reCacheConcurrentStreamingCameraIdsLocked() {
436
437 // Check if the provider is currently active - not going to start it up for this notification
438 auto interface = mSavedInterface != nullptr ? mSavedInterface : mActiveInterface.lock();
439 if (interface == nullptr) {
440 ALOGE("%s: camera provider interface for %s is not valid", __FUNCTION__,
441 mProviderName.c_str());
442 return INVALID_OPERATION;
443 }
444
445 return getConcurrentCameraIdsInternalLocked(interface);
446 }
447
getConcurrentCameraIdsInternalLocked(std::shared_ptr<ICameraProvider> & interface)448 status_t AidlProviderInfo::getConcurrentCameraIdsInternalLocked(
449 std::shared_ptr<ICameraProvider> &interface) {
450 if (interface == nullptr) {
451 ALOGE("%s: null interface provided", __FUNCTION__);
452 return BAD_VALUE;
453 }
454
455 std::vector<aidl::android::hardware::camera::provider::ConcurrentCameraIdCombination> combs;
456 ::ndk::ScopedAStatus status = interface->getConcurrentCameraIds(&combs);
457
458 if (!status.isOk()) {
459 ALOGE("%s: Transaction error in getting concurrent camera ID list from provider '%s'",
460 __FUNCTION__, mProviderName.c_str());
461 return mapToStatusT(status);
462 }
463 mConcurrentCameraIdCombinations.clear();
464 for (const auto& combination : combs) {
465 std::unordered_set<std::string> deviceIds;
466 for (const auto &cameraDeviceId : combination.combination) {
467 deviceIds.insert(cameraDeviceId);
468 }
469 mConcurrentCameraIdCombinations.push_back(std::move(deviceIds));
470 }
471
472 return OK;
473 }
474
AidlDeviceInfo3(const std::string & name,const metadata_vendor_id_t tagId,const std::string & id,uint16_t minorVersion,const CameraResourceCost & resourceCost,sp<CameraProviderManager::ProviderInfo> parentProvider,const std::vector<std::string> & publicCameraIds,std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice> interface)475 AidlProviderInfo::AidlDeviceInfo3::AidlDeviceInfo3(
476 const std::string& name,
477 const metadata_vendor_id_t tagId,
478 const std::string &id, uint16_t minorVersion,
479 const CameraResourceCost& resourceCost,
480 sp<CameraProviderManager::ProviderInfo> parentProvider,
481 const std::vector<std::string>& publicCameraIds,
482 std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice> interface) :
483 DeviceInfo3(name, tagId, id, minorVersion, resourceCost, parentProvider, publicCameraIds) {
484
485 // Get camera characteristics and initialize flash unit availability
486 aidl::android::hardware::camera::device::CameraMetadata chars;
487 ::ndk::ScopedAStatus status = interface->getCameraCharacteristics(&chars);
488 std::vector<uint8_t> &metadata = chars.metadata;
489 camera_metadata_t *buffer = reinterpret_cast<camera_metadata_t*>(metadata.data());
490 size_t expectedSize = metadata.size();
491 int resV = validate_camera_metadata_structure(buffer, &expectedSize);
492 if (resV == OK || resV == CAMERA_METADATA_VALIDATION_SHIFTED) {
493 set_camera_metadata_vendor_id(buffer, mProviderTagid);
494 mCameraCharacteristics = buffer;
495 } else {
496 ALOGE("%s: Malformed camera metadata received from HAL", __FUNCTION__);
497 return;
498 }
499
500 if (!status.isOk()) {
501 ALOGE("%s: Transaction error getting camera characteristics for device %s"
502 " to check for a flash unit: %s", __FUNCTION__, id.c_str(),
503 status.getMessage());
504 return;
505 }
506
507 if (mCameraCharacteristics.exists(ANDROID_INFO_DEVICE_STATE_ORIENTATIONS)) {
508 const auto &stateMap = mCameraCharacteristics.find(ANDROID_INFO_DEVICE_STATE_ORIENTATIONS);
509 if ((stateMap.count > 0) && ((stateMap.count % 2) == 0)) {
510 for (size_t i = 0; i < stateMap.count; i += 2) {
511 mDeviceStateOrientationMap.emplace(stateMap.data.i64[i], stateMap.data.i64[i+1]);
512 }
513 } else {
514 ALOGW("%s: Invalid ANDROID_INFO_DEVICE_STATE_ORIENTATIONS map size: %zu", __FUNCTION__,
515 stateMap.count);
516 }
517 }
518
519 mCompositeJpegRDisabled = mCameraCharacteristics.exists(
520 ANDROID_JPEGR_AVAILABLE_JPEG_R_STREAM_CONFIGURATIONS);
521 mCompositeHeicUltraHDRDisabled = mCameraCharacteristics.exists(
522 ANDROID_HEIC_AVAILABLE_HEIC_ULTRA_HDR_STREAM_CONFIGURATIONS);
523
524 mSystemCameraKind = getSystemCameraKind();
525
526 status_t res = fixupMonochromeTags();
527 if (OK != res) {
528 ALOGE("%s: Unable to fix up monochrome tags based for older HAL version: %s (%d)",
529 __FUNCTION__, strerror(-res), res);
530 return;
531 }
532 res = fixupManualFlashStrengthControlTags(mCameraCharacteristics);
533 if (OK != res) {
534 ALOGE("%s: Unable to fix up manual flash strength control tags: %s (%d)",
535 __FUNCTION__, strerror(-res), res);
536 return;
537 }
538
539 auto stat = addDynamicDepthTags();
540 if (OK != stat) {
541 ALOGE("%s: Failed appending dynamic depth tags: %s (%d)", __FUNCTION__, strerror(-stat),
542 stat);
543 }
544 res = deriveHeicTags();
545 if (OK != res) {
546 ALOGE("%s: Unable to derive HEIC tags based on camera and media capabilities: %s (%d)",
547 __FUNCTION__, strerror(-res), res);
548 }
549 res = deriveJpegRTags();
550 if (OK != res) {
551 ALOGE("%s: Unable to derive Jpeg/R tags based on camera and media capabilities: %s (%d)",
552 __FUNCTION__, strerror(-res), res);
553 }
554 res = deriveHeicUltraHDRTags();
555 if (OK != res) {
556 ALOGE("%s: Unable to derive Heic UltraHDR tags based on camera and "
557 "media capabilities: %s (%d)",
558 __FUNCTION__, strerror(-res), res);
559 }
560 using camera3::SessionConfigurationUtils::supportsUltraHighResolutionCapture;
561 if (supportsUltraHighResolutionCapture(mCameraCharacteristics)) {
562 status_t status = addDynamicDepthTags(/*maxResolution*/true);
563 if (OK != status) {
564 ALOGE("%s: Failed appending dynamic depth tags for maximum resolution mode: %s (%d)",
565 __FUNCTION__, strerror(-status), status);
566 }
567
568 status = deriveHeicTags(/*maxResolution*/true);
569 if (OK != status) {
570 ALOGE("%s: Unable to derive HEIC tags based on camera and media capabilities for"
571 "maximum resolution mode: %s (%d)", __FUNCTION__, strerror(-status), status);
572 }
573
574 status = deriveJpegRTags(/*maxResolution*/true);
575 if (OK != status) {
576 ALOGE("%s: Unable to derive Jpeg/R tags based on camera and media capabilities for"
577 "maximum resolution mode: %s (%d)", __FUNCTION__, strerror(-status), status);
578 }
579 status = deriveHeicUltraHDRTags(/*maxResolution*/true);
580 if (OK != status) {
581 ALOGE("%s: Unable to derive Heic UltraHDR tags based on camera and "
582 "media capabilities: %s (%d)",
583 __FUNCTION__, strerror(-status), status);
584 }
585 }
586
587 res = addRotateCropTags();
588 if (OK != res) {
589 ALOGE("%s: Unable to add default SCALER_ROTATE_AND_CROP tags: %s (%d)", __FUNCTION__,
590 strerror(-res), res);
591 }
592 res = addAutoframingTags();
593 if (OK != res) {
594 ALOGE("%s: Unable to add default AUTOFRAMING tags: %s (%d)", __FUNCTION__,
595 strerror(-res), res);
596 }
597 res = addPreCorrectionActiveArraySize();
598 if (OK != res) {
599 ALOGE("%s: Unable to add PRE_CORRECTION_ACTIVE_ARRAY_SIZE: %s (%d)", __FUNCTION__,
600 strerror(-res), res);
601 }
602 res = camera3::ZoomRatioMapper::overrideZoomRatioTags(
603 &mCameraCharacteristics, &mSupportNativeZoomRatio);
604 if (OK != res) {
605 ALOGE("%s: Unable to override zoomRatio related tags: %s (%d)",
606 __FUNCTION__, strerror(-res), res);
607 }
608 res = addReadoutTimestampTag();
609 if (OK != res) {
610 ALOGE("%s: Unable to add sensorReadoutTimestamp tag: %s (%d)",
611 __FUNCTION__, strerror(-res), res);
612 }
613
614 if (flags::color_temperature()) {
615 res = addColorCorrectionAvailableModesTag(mCameraCharacteristics);
616 if (OK != res) {
617 ALOGE("%s: Unable to add COLOR_CORRECTION_AVAILABLE_MODES tag: %s (%d)",
618 __FUNCTION__, strerror(-res), res);
619 }
620 }
621
622 if (flags::ae_priority()) {
623 res = addAePriorityModeTags();
624 if (OK != res) {
625 ALOGE("%s: Unable to add CONTROL_AE_AVAILABLE_PRIORITY_MODES tag: %s (%d)",
626 __FUNCTION__, strerror(-res), res);
627 }
628 }
629
630 camera_metadata_entry flashAvailable =
631 mCameraCharacteristics.find(ANDROID_FLASH_INFO_AVAILABLE);
632 if (flashAvailable.count == 1 &&
633 flashAvailable.data.u8[0] == ANDROID_FLASH_INFO_AVAILABLE_TRUE) {
634 mHasFlashUnit = true;
635 // Fix up flash strength tags for devices without these keys.
636 res = fixupTorchStrengthTags();
637 if (OK != res) {
638 ALOGE("%s: Unable to add default ANDROID_FLASH_INFO_STRENGTH_DEFAULT_LEVEL and"
639 "ANDROID_FLASH_INFO_STRENGTH_MAXIMUM_LEVEL tags: %s (%d)", __FUNCTION__,
640 strerror(-res), res);
641 }
642
643 // b/247038031: In case of system_server crash, camera_server is
644 // restarted as well. If flashlight is turned on before the crash, it
645 // may be stuck to be on. As a workaround, set torch mode to be OFF.
646 interface->setTorchMode(false);
647 } else {
648 mHasFlashUnit = false;
649 }
650
651 res = addSessionConfigQueryVersionTag();
652 if (OK != res) {
653 ALOGE("%s: Unable to add sessionConfigurationQueryVersion tag: %s (%d)",
654 __FUNCTION__, strerror(-res), res);
655 }
656
657 camera_metadata_entry entry =
658 mCameraCharacteristics.find(ANDROID_FLASH_INFO_STRENGTH_DEFAULT_LEVEL);
659 if (entry.count == 1) {
660 mTorchDefaultStrengthLevel = entry.data.i32[0];
661 } else {
662 mTorchDefaultStrengthLevel = 0;
663 }
664 entry = mCameraCharacteristics.find(ANDROID_FLASH_INFO_STRENGTH_MAXIMUM_LEVEL);
665 if (entry.count == 1) {
666 mTorchMaximumStrengthLevel = entry.data.i32[0];
667 } else {
668 mTorchMaximumStrengthLevel = 0;
669 }
670
671 mTorchStrengthLevel = 0;
672
673 queryPhysicalCameraIds();
674
675 // Get physical camera characteristics if applicable
676 if (mIsLogicalCamera) {
677 for (auto& id : mPhysicalIds) {
678 if (std::find(mPublicCameraIds.begin(), mPublicCameraIds.end(), id) !=
679 mPublicCameraIds.end()) {
680 continue;
681 }
682
683 aidl::android::hardware::camera::device::CameraMetadata pChars;
684 status = interface->getPhysicalCameraCharacteristics(id, &pChars);
685 if (!status.isOk()) {
686 ALOGE("%s: Transaction error getting physical camera %s characteristics for "
687 "logical id %s: %s", __FUNCTION__, id.c_str(), mId.c_str(),
688 status.getMessage());
689 return;
690 }
691 std::vector<uint8_t> &pMetadata = pChars.metadata;
692 camera_metadata_t *pBuffer =
693 reinterpret_cast<camera_metadata_t*>(pMetadata.data());
694 size_t expectedSize = pMetadata.size();
695 int res = validate_camera_metadata_structure(pBuffer, &expectedSize);
696 if (res == OK || res == CAMERA_METADATA_VALIDATION_SHIFTED) {
697 set_camera_metadata_vendor_id(pBuffer, mProviderTagid);
698 mPhysicalCameraCharacteristics[id] = pBuffer;
699 } else {
700 ALOGE("%s: Malformed camera metadata received from HAL", __FUNCTION__);
701 return;
702 }
703
704 res = camera3::ZoomRatioMapper::overrideZoomRatioTags(
705 &mPhysicalCameraCharacteristics[id], &mSupportNativeZoomRatio);
706 if (OK != res) {
707 ALOGE("%s: Unable to override zoomRatio related tags: %s (%d)",
708 __FUNCTION__, strerror(-res), res);
709 }
710
711 res = fixupManualFlashStrengthControlTags(mPhysicalCameraCharacteristics[id]);
712 if (OK != res) {
713 ALOGE("%s: Unable to fix up manual flash strength control tags: %s (%d)",
714 __FUNCTION__, strerror(-res), res);
715 return;
716 }
717
718 if (flags::color_temperature()) {
719 res = addColorCorrectionAvailableModesTag(mPhysicalCameraCharacteristics[id]);
720 if (OK != res) {
721 ALOGE("%s: Unable to add COLOR_CORRECTION_AVAILABLE_MODES tag: %s (%d)",
722 __FUNCTION__, strerror(-res), res);
723 }
724 }
725 }
726 }
727
728 int deviceVersion = HARDWARE_DEVICE_API_VERSION(mVersion.get_major(), mVersion.get_minor());
729 if (deviceVersion >= CAMERA_DEVICE_API_VERSION_1_3) {
730 // This additional set of request keys must match the ones specified
731 // in ICameraDevice.isSessionConfigurationWithSettingsSupported.
732 mAdditionalKeysForFeatureQuery.insert(mAdditionalKeysForFeatureQuery.end(),
733 {ANDROID_CONTROL_VIDEO_STABILIZATION_MODE, ANDROID_CONTROL_AE_TARGET_FPS_RANGE});
734 }
735
736 if (flags::camera_multi_client() && isAutomotiveDevice()) {
737 addSharedSessionConfigurationTags();
738 }
739
740 if (!kEnableLazyHal) {
741 // Save HAL reference indefinitely
742 mSavedInterface = interface;
743 }
744 }
745
setTorchMode(bool enabled)746 status_t AidlProviderInfo::AidlDeviceInfo3::setTorchMode(bool enabled) {
747 const std::shared_ptr<camera::device::ICameraDevice> interface = startDeviceInterface();
748 ::ndk::ScopedAStatus s = interface->setTorchMode(enabled);
749 if (!s.isOk()) {
750 ALOGE("%s Unable to set torch mode: %s", __FUNCTION__, s.getMessage());
751 return mapToStatusT(s);
752 }
753 return OK;
754 }
755
turnOnTorchWithStrengthLevel(int32_t torchStrength)756 status_t AidlProviderInfo::AidlDeviceInfo3::turnOnTorchWithStrengthLevel(
757 int32_t torchStrength) {
758 const std::shared_ptr<camera::device::ICameraDevice> interface = startDeviceInterface();
759 if (interface == nullptr) {
760 return DEAD_OBJECT;
761 }
762
763 ::ndk::ScopedAStatus s = interface->turnOnTorchWithStrengthLevel(torchStrength);
764 if (!s.isOk()) {
765 ALOGE("%s Unable to set torch mode strength %d : %s", __FUNCTION__, torchStrength,
766 s.getMessage());
767 return mapToStatusT(s);
768 }
769 mTorchStrengthLevel = torchStrength;
770 return OK;
771 }
772
getTorchStrengthLevel(int32_t * torchStrength)773 status_t AidlProviderInfo::AidlDeviceInfo3::getTorchStrengthLevel(int32_t *torchStrength) {
774 if (torchStrength == nullptr) {
775 return BAD_VALUE;
776 }
777 const std::shared_ptr<camera::device::ICameraDevice> interface = startDeviceInterface();
778 if (interface == nullptr) {
779 return DEAD_OBJECT;
780 }
781
782 ::ndk::ScopedAStatus status = interface->getTorchStrengthLevel(torchStrength);
783 if (!status.isOk()) {
784 ALOGE("%s: Couldn't get torch strength level: %s", __FUNCTION__, status.getMessage());
785 return mapToStatusT(status);
786 }
787 return OK;
788 }
789
790 std::shared_ptr<aidl::android::hardware::camera::device::ICameraDevice>
startDeviceInterface()791 AidlProviderInfo::AidlDeviceInfo3::startDeviceInterface() {
792 Mutex::Autolock l(mDeviceAvailableLock);
793 std::shared_ptr<camera::device::ICameraDevice> device;
794 ATRACE_CALL();
795 if (mSavedInterface == nullptr) {
796 sp<AidlProviderInfo> parentProvider =
797 static_cast<AidlProviderInfo *>(mParentProvider.promote().get());
798 if (parentProvider != nullptr) {
799 // Wait for lazy HALs to confirm device availability
800 if (parentProvider->isExternalLazyHAL() && !mIsDeviceAvailable) {
801 ALOGV("%s: Wait for external device to become available %s",
802 __FUNCTION__,
803 mId.c_str());
804
805 auto res = mDeviceAvailableSignal.waitRelative(mDeviceAvailableLock,
806 kDeviceAvailableTimeout);
807 if (res != OK) {
808 ALOGE("%s: Failed waiting for device to become available",
809 __FUNCTION__);
810 return nullptr;
811 }
812 }
813
814 device = parentProvider->startDeviceInterface(mName);
815 }
816 } else {
817 device = mSavedInterface;
818 }
819 return device;
820 }
821
dumpState(int fd)822 status_t AidlProviderInfo::AidlDeviceInfo3::dumpState(int fd) {
823 const std::shared_ptr<camera::device::ICameraDevice> interface = startDeviceInterface();
824 if (interface == nullptr) {
825 return DEAD_OBJECT;
826 }
827 const char *args = nullptr;
828 auto ret = interface->dump(fd, &args, /*numArgs*/0);
829 if (ret != OK) {
830 return ret;
831 }
832 return OK;
833 }
834
isSessionConfigurationSupported(const SessionConfiguration & configuration,bool overrideForPerfClass,camera3::metadataGetter getMetadata,bool checkSessionParams,bool * status)835 status_t AidlProviderInfo::AidlDeviceInfo3::isSessionConfigurationSupported(
836 const SessionConfiguration &configuration, bool overrideForPerfClass,
837 camera3::metadataGetter getMetadata, bool checkSessionParams, bool *status) {
838
839 auto operatingMode = configuration.getOperatingMode();
840
841 auto res = SessionConfigurationUtils::checkOperatingMode(operatingMode,
842 mCameraCharacteristics, mId);
843 if (!res.isOk()) {
844 return UNKNOWN_ERROR;
845 }
846
847 camera::device::StreamConfiguration streamConfiguration;
848 bool earlyExit = false;
849 auto bRes = SessionConfigurationUtils::convertToHALStreamCombination(configuration,
850 mId, mCameraCharacteristics, mCompositeJpegRDisabled, getMetadata,
851 mPhysicalIds, streamConfiguration, overrideForPerfClass, mProviderTagid,
852 checkSessionParams, mAdditionalKeysForFeatureQuery, &earlyExit);
853
854 if (!bRes.isOk()) {
855 return UNKNOWN_ERROR;
856 }
857
858 if (earlyExit) {
859 *status = false;
860 return OK;
861 }
862
863 const std::shared_ptr<camera::device::ICameraDevice> interface =
864 startDeviceInterface();
865
866 if (interface == nullptr) {
867 return DEAD_OBJECT;
868 }
869
870 ::ndk::ScopedAStatus ret;
871 if (checkSessionParams) {
872 // Only interface version 1_3 or greater supports
873 // isStreamCombinationWIthSettingsSupported.
874 int deviceVersion = HARDWARE_DEVICE_API_VERSION(mVersion.get_major(), mVersion.get_minor());
875 if (deviceVersion < CAMERA_DEVICE_API_VERSION_1_3) {
876 ALOGI("%s: Camera device version (major %d, minor %d) doesn't support querying of "
877 "session configuration!", __FUNCTION__, mVersion.get_major(),
878 mVersion.get_minor());
879 return INVALID_OPERATION;
880 }
881 ret = interface->isStreamCombinationWithSettingsSupported(streamConfiguration, status);
882 } else {
883 ret = interface->isStreamCombinationSupported(streamConfiguration, status);
884 }
885 if (!ret.isOk()) {
886 *status = false;
887 ALOGE("%s: Unexpected binder error: %s", __FUNCTION__, ret.getMessage());
888 return mapToStatusT(ret);
889 }
890 return OK;
891
892 }
893
createDefaultRequest(camera3::camera_request_template_t templateId,CameraMetadata * metadata)894 status_t AidlProviderInfo::AidlDeviceInfo3::createDefaultRequest(
895 camera3::camera_request_template_t templateId, CameraMetadata* metadata) {
896 const std::shared_ptr<camera::device::ICameraDevice> interface =
897 startDeviceInterface();
898
899 if (interface == nullptr) {
900 return DEAD_OBJECT;
901 }
902
903 int deviceVersion = HARDWARE_DEVICE_API_VERSION(mVersion.get_major(), mVersion.get_minor());
904 if (deviceVersion < CAMERA_DEVICE_API_VERSION_1_3) {
905 ALOGI("%s: Camera device minor version 0x%x doesn't support creating "
906 " default request!", __FUNCTION__, mVersion.get_minor());
907 return INVALID_OPERATION;
908 }
909
910 aidl::android::hardware::camera::device::CameraMetadata request;
911
912 using aidl::android::hardware::camera::device::RequestTemplate;
913 RequestTemplate id;
914 status_t res = SessionConfigurationUtils::mapRequestTemplateToAidl(
915 templateId, &id);
916 if (res != OK) {
917 return res;
918 }
919
920 auto err = interface->constructDefaultRequestSettings(id, &request);
921 if (!err.isOk()) {
922 ALOGE("%s: Transaction error: %s", __FUNCTION__, err.getMessage());
923 return AidlProviderInfo::mapToStatusT(err);
924 }
925 const camera_metadata *r =
926 reinterpret_cast<const camera_metadata_t*>(request.metadata.data());
927 camera_metadata *rawRequest = nullptr;
928 size_t expectedSize = request.metadata.size();
929 int ret = validate_camera_metadata_structure(r, &expectedSize);
930 if (ret == OK || ret == CAMERA_METADATA_VALIDATION_SHIFTED) {
931 rawRequest = clone_camera_metadata(r);
932 if (rawRequest == nullptr) {
933 ALOGE("%s: Unable to clone camera metadata received from HAL",
934 __FUNCTION__);
935 res = UNKNOWN_ERROR;
936 }
937 } else {
938 ALOGE("%s: Malformed camera metadata received from HAL", __FUNCTION__);
939 res = UNKNOWN_ERROR;
940 }
941
942 set_camera_metadata_vendor_id(rawRequest, mProviderTagid);
943 metadata->acquire(rawRequest);
944
945 res = overrideDefaultRequestKeys(metadata);
946 if (res != OK) {
947 ALOGE("Unabled to override default request keys: %s (%d)",
948 strerror(-res), res);
949 return res;
950 }
951
952 return res;
953 }
954
getSessionCharacteristics(const SessionConfiguration & configuration,bool overrideForPerfClass,camera3::metadataGetter getMetadata,CameraMetadata * outChars)955 status_t AidlProviderInfo::AidlDeviceInfo3::getSessionCharacteristics(
956 const SessionConfiguration &configuration, bool overrideForPerfClass,
957 camera3::metadataGetter getMetadata, CameraMetadata* outChars) {
958 camera::device::StreamConfiguration streamConfiguration;
959 bool earlyExit = false;
960 auto res = SessionConfigurationUtils::convertToHALStreamCombination(configuration,
961 mId, mCameraCharacteristics, mCompositeJpegRDisabled, getMetadata,
962 mPhysicalIds, streamConfiguration, overrideForPerfClass, mProviderTagid,
963 /*checkSessionParams*/true, mAdditionalKeysForFeatureQuery, &earlyExit);
964
965 if (!res.isOk()) {
966 return UNKNOWN_ERROR;
967 }
968
969 if (earlyExit) {
970 return BAD_VALUE;
971 }
972
973 const std::shared_ptr<camera::device::ICameraDevice> interface =
974 startDeviceInterface();
975
976 if (interface == nullptr) {
977 return DEAD_OBJECT;
978 }
979
980 aidl::android::hardware::camera::device::CameraMetadata chars;
981 ::ndk::ScopedAStatus ret =
982 interface->getSessionCharacteristics(streamConfiguration, &chars);
983 if (!ret.isOk()) {
984 ALOGE("%s: Unexpected binder error while getting session characteristics (%d): %s",
985 __FUNCTION__, ret.getExceptionCode(), ret.getMessage());
986 return mapToStatusT(ret);
987 }
988
989 std::vector<uint8_t> &metadata = chars.metadata;
990 auto *buffer = reinterpret_cast<camera_metadata_t*>(metadata.data());
991 size_t expectedSize = metadata.size();
992 int resV = validate_camera_metadata_structure(buffer, &expectedSize);
993 if (resV == OK || resV == CAMERA_METADATA_VALIDATION_SHIFTED) {
994 set_camera_metadata_vendor_id(buffer, mProviderTagid);
995 } else {
996 ALOGE("%s: Malformed camera metadata received from HAL", __FUNCTION__);
997 return BAD_VALUE;
998 }
999
1000 CameraMetadata rawSessionChars;
1001 rawSessionChars = buffer; // clone buffer
1002 rawSessionChars.sort(); // sort for faster lookups
1003
1004 *outChars = mCameraCharacteristics;
1005 outChars->sort(); // sort for faster reads and (hopefully!) writes
1006
1007 return copySessionCharacteristics(/*from=*/rawSessionChars, /*to=*/outChars,
1008 mSessionConfigQueryVersion);
1009 }
1010
convertToAidlHALStreamCombinationAndCameraIdsLocked(const std::vector<CameraIdAndSessionConfiguration> & cameraIdsAndSessionConfigs,const std::set<std::string> & perfClassPrimaryCameraIds,int targetSdkVersion,std::vector<camera::provider::CameraIdAndStreamCombination> * halCameraIdsAndStreamCombinations,bool * earlyExit)1011 status_t AidlProviderInfo::convertToAidlHALStreamCombinationAndCameraIdsLocked(
1012 const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
1013 const std::set<std::string>& perfClassPrimaryCameraIds,
1014 int targetSdkVersion,
1015 std::vector<camera::provider::CameraIdAndStreamCombination>
1016 *halCameraIdsAndStreamCombinations,
1017 bool *earlyExit) {
1018 binder::Status bStatus = binder::Status::ok();
1019 std::vector<camera::provider::CameraIdAndStreamCombination> halCameraIdsAndStreamsV;
1020 bool shouldExit = false;
1021 status_t res = OK;
1022 for (auto &cameraIdAndSessionConfig : cameraIdsAndSessionConfigs) {
1023 const std::string& cameraId = cameraIdAndSessionConfig.mCameraId;
1024 camera::device::StreamConfiguration streamConfiguration;
1025 CameraMetadata deviceInfo;
1026 bool overrideForPerfClass =
1027 SessionConfigurationUtils::targetPerfClassPrimaryCamera(
1028 perfClassPrimaryCameraIds, cameraId, targetSdkVersion);
1029 res = mManager->getCameraCharacteristicsLocked(cameraId, overrideForPerfClass, &deviceInfo,
1030 hardware::ICameraService::ROTATION_OVERRIDE_NONE);
1031 if (res != OK) {
1032 return res;
1033 }
1034 camera3::metadataGetter getMetadata =
1035 [this](const std::string &id, bool overrideForPerfClass) {
1036 CameraMetadata physicalDeviceInfo;
1037 mManager->getCameraCharacteristicsLocked(
1038 id, overrideForPerfClass, &physicalDeviceInfo,
1039 hardware::ICameraService::ROTATION_OVERRIDE_NONE);
1040 return physicalDeviceInfo;
1041 };
1042 std::vector<std::string> physicalCameraIds;
1043 mManager->isLogicalCameraLocked(cameraId, &physicalCameraIds);
1044 bStatus =
1045 SessionConfigurationUtils::convertToHALStreamCombination(
1046 cameraIdAndSessionConfig.mSessionConfiguration,
1047 cameraId, deviceInfo,
1048 mManager->isCompositeJpegRDisabledLocked(cameraId), getMetadata,
1049 physicalCameraIds, streamConfiguration,
1050 overrideForPerfClass, mProviderTagid,
1051 /*checkSessionParams*/false, /*additionalKeys*/{},
1052 &shouldExit);
1053 if (!bStatus.isOk()) {
1054 ALOGE("%s: convertToHALStreamCombination failed", __FUNCTION__);
1055 return INVALID_OPERATION;
1056 }
1057 if (shouldExit) {
1058 *earlyExit = true;
1059 return OK;
1060 }
1061 camera::provider::CameraIdAndStreamCombination halCameraIdAndStream;
1062 halCameraIdAndStream.cameraId = cameraId;
1063 halCameraIdAndStream.streamConfiguration = streamConfiguration;
1064 halCameraIdsAndStreamsV.push_back(halCameraIdAndStream);
1065 }
1066 *halCameraIdsAndStreamCombinations = halCameraIdsAndStreamsV;
1067 return OK;
1068 }
1069
isConcurrentSessionConfigurationSupported(const std::vector<CameraIdAndSessionConfiguration> & cameraIdsAndSessionConfigs,const std::set<std::string> & perfClassPrimaryCameraIds,int targetSdkVersion,bool * isSupported)1070 status_t AidlProviderInfo::isConcurrentSessionConfigurationSupported(
1071 const std::vector<CameraIdAndSessionConfiguration> &cameraIdsAndSessionConfigs,
1072 const std::set<std::string>& perfClassPrimaryCameraIds,
1073 int targetSdkVersion, bool *isSupported) {
1074
1075 std::vector<camera::provider::CameraIdAndStreamCombination> halCameraIdsAndStreamCombinations;
1076 bool knowUnsupported = false;
1077 status_t res = convertToAidlHALStreamCombinationAndCameraIdsLocked(
1078 cameraIdsAndSessionConfigs, perfClassPrimaryCameraIds,
1079 targetSdkVersion, &halCameraIdsAndStreamCombinations, &knowUnsupported);
1080 if (res != OK) {
1081 ALOGE("%s unable to convert session configurations provided to HAL stream"
1082 "combinations", __FUNCTION__);
1083 return res;
1084 }
1085 if (knowUnsupported) {
1086 // We got to know the streams aren't valid before doing the HAL
1087 // call itself.
1088 *isSupported = false;
1089 return OK;
1090 }
1091
1092 // Check if the provider is currently active - not going to start it up for this notification
1093 auto interface = mSavedInterface != nullptr ? mSavedInterface : mActiveInterface.lock();
1094 if (interface == nullptr) {
1095 // TODO: This might be some other problem
1096 return INVALID_OPERATION;
1097 }
1098 ::ndk::ScopedAStatus status = interface->isConcurrentStreamCombinationSupported(
1099 halCameraIdsAndStreamCombinations, isSupported);
1100 if (!status.isOk()) {
1101 *isSupported = false;
1102 ALOGE("%s: hal interface session configuration query failed", __FUNCTION__);
1103 return mapToStatusT(status);
1104 }
1105
1106 return OK;
1107 }
1108
1109 } //namespace android
1110