1 /*
2  * Copyright (C) 2016 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 
17 #define LOG_TAG "CamComm1.0-CamModule"
18 #define ATRACE_TAG ATRACE_TAG_CAMERA
19 //#define LOG_NDEBUG 0
20 
21 #include <utils/Trace.h>
22 
23 #include "CameraModule.h"
24 
25 namespace android {
26 namespace hardware {
27 namespace camera {
28 namespace common {
29 namespace V1_0 {
30 namespace helper {
31 
deriveCameraCharacteristicsKeys(uint32_t deviceVersion,CameraMetadata & chars)32 void CameraModule::deriveCameraCharacteristicsKeys(
33         uint32_t deviceVersion, CameraMetadata &chars) {
34     ATRACE_CALL();
35 
36     Vector<int32_t> derivedCharKeys;
37     Vector<int32_t> derivedRequestKeys;
38     Vector<int32_t> derivedResultKeys;
39     // Keys added in HAL3.3
40     if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_3) {
41         Vector<uint8_t> controlModes;
42         uint8_t data = ANDROID_CONTROL_AE_LOCK_AVAILABLE_TRUE;
43         chars.update(ANDROID_CONTROL_AE_LOCK_AVAILABLE, &data, /*count*/1);
44         data = ANDROID_CONTROL_AWB_LOCK_AVAILABLE_TRUE;
45         chars.update(ANDROID_CONTROL_AWB_LOCK_AVAILABLE, &data, /*count*/1);
46         controlModes.push(ANDROID_CONTROL_MODE_AUTO);
47         camera_metadata_entry entry = chars.find(ANDROID_CONTROL_AVAILABLE_SCENE_MODES);
48         if (entry.count > 1 || entry.data.u8[0] != ANDROID_CONTROL_SCENE_MODE_DISABLED) {
49             controlModes.push(ANDROID_CONTROL_MODE_USE_SCENE_MODE);
50         }
51 
52         // Only advertise CONTROL_OFF mode if 3A manual controls are supported.
53         bool isManualAeSupported = false;
54         bool isManualAfSupported = false;
55         bool isManualAwbSupported = false;
56         entry = chars.find(ANDROID_CONTROL_AE_AVAILABLE_MODES);
57         if (entry.count > 0) {
58             for (size_t i = 0; i < entry.count; i++) {
59                 if (entry.data.u8[i] == ANDROID_CONTROL_AE_MODE_OFF) {
60                     isManualAeSupported = true;
61                     break;
62                 }
63             }
64         }
65         entry = chars.find(ANDROID_CONTROL_AF_AVAILABLE_MODES);
66         if (entry.count > 0) {
67             for (size_t i = 0; i < entry.count; i++) {
68                 if (entry.data.u8[i] == ANDROID_CONTROL_AF_MODE_OFF) {
69                     isManualAfSupported = true;
70                     break;
71                 }
72             }
73         }
74         entry = chars.find(ANDROID_CONTROL_AWB_AVAILABLE_MODES);
75         if (entry.count > 0) {
76             for (size_t i = 0; i < entry.count; i++) {
77                 if (entry.data.u8[i] == ANDROID_CONTROL_AWB_MODE_OFF) {
78                     isManualAwbSupported = true;
79                     break;
80                 }
81             }
82         }
83         if (isManualAeSupported && isManualAfSupported && isManualAwbSupported) {
84             controlModes.push(ANDROID_CONTROL_MODE_OFF);
85         }
86 
87         chars.update(ANDROID_CONTROL_AVAILABLE_MODES, controlModes);
88 
89         entry = chars.find(ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS);
90         // HAL3.2 devices passing existing CTS test should all support all LSC modes and LSC map
91         bool lensShadingModeSupported = false;
92         if (entry.count > 0) {
93             for (size_t i = 0; i < entry.count; i++) {
94                 if (entry.data.i32[i] == ANDROID_SHADING_MODE) {
95                     lensShadingModeSupported = true;
96                     break;
97                 }
98             }
99         }
100         Vector<uint8_t> lscModes;
101         Vector<uint8_t> lscMapModes;
102         lscModes.push(ANDROID_SHADING_MODE_FAST);
103         lscModes.push(ANDROID_SHADING_MODE_HIGH_QUALITY);
104         lscMapModes.push(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_OFF);
105         if (lensShadingModeSupported) {
106             lscModes.push(ANDROID_SHADING_MODE_OFF);
107             lscMapModes.push(ANDROID_STATISTICS_LENS_SHADING_MAP_MODE_ON);
108         }
109         chars.update(ANDROID_SHADING_AVAILABLE_MODES, lscModes);
110         chars.update(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES, lscMapModes);
111 
112         derivedCharKeys.push(ANDROID_CONTROL_AE_LOCK_AVAILABLE);
113         derivedCharKeys.push(ANDROID_CONTROL_AWB_LOCK_AVAILABLE);
114         derivedCharKeys.push(ANDROID_CONTROL_AVAILABLE_MODES);
115         derivedCharKeys.push(ANDROID_SHADING_AVAILABLE_MODES);
116         derivedCharKeys.push(ANDROID_STATISTICS_INFO_AVAILABLE_LENS_SHADING_MAP_MODES);
117 
118         // Need update android.control.availableHighSpeedVideoConfigurations since HAL3.3
119         // adds batch size to this array.
120         entry = chars.find(ANDROID_CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS);
121         if (entry.count > 0) {
122             Vector<int32_t> highSpeedConfig;
123             for (size_t i = 0; i < entry.count; i += 4) {
124                 highSpeedConfig.add(entry.data.i32[i]); // width
125                 highSpeedConfig.add(entry.data.i32[i + 1]); // height
126                 highSpeedConfig.add(entry.data.i32[i + 2]); // fps_min
127                 highSpeedConfig.add(entry.data.i32[i + 3]); // fps_max
128                 highSpeedConfig.add(1); // batchSize_max. default to 1 for HAL3.2
129             }
130             chars.update(ANDROID_CONTROL_AVAILABLE_HIGH_SPEED_VIDEO_CONFIGURATIONS,
131                     highSpeedConfig);
132         }
133     }
134 
135     // Keys added in HAL3.4
136     if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_4) {
137         // Check if HAL supports RAW_OPAQUE output
138         camera_metadata_entry entry = chars.find(ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS);
139         bool supportRawOpaque = false;
140         bool supportAnyRaw = false;
141         const int STREAM_CONFIGURATION_SIZE = 4;
142         const int STREAM_FORMAT_OFFSET = 0;
143         const int STREAM_WIDTH_OFFSET = 1;
144         const int STREAM_HEIGHT_OFFSET = 2;
145         const int STREAM_IS_INPUT_OFFSET = 3;
146         Vector<int32_t> rawOpaqueSizes;
147 
148         for (size_t i=0; i < entry.count; i += STREAM_CONFIGURATION_SIZE) {
149             int32_t format = entry.data.i32[i + STREAM_FORMAT_OFFSET];
150             int32_t width = entry.data.i32[i + STREAM_WIDTH_OFFSET];
151             int32_t height = entry.data.i32[i + STREAM_HEIGHT_OFFSET];
152             int32_t isInput = entry.data.i32[i + STREAM_IS_INPUT_OFFSET];
153             if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT &&
154                     format == HAL_PIXEL_FORMAT_RAW_OPAQUE) {
155                 supportRawOpaque = true;
156                 rawOpaqueSizes.push(width);
157                 rawOpaqueSizes.push(height);
158                 // 2 bytes per pixel. This rough estimation is only used when
159                 // HAL does not fill in the opaque raw size
160                 rawOpaqueSizes.push(width * height *2);
161             }
162             if (isInput == ANDROID_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_OUTPUT &&
163                     (format == HAL_PIXEL_FORMAT_RAW16 ||
164                      format == HAL_PIXEL_FORMAT_RAW10 ||
165                      format == HAL_PIXEL_FORMAT_RAW12 ||
166                      format == HAL_PIXEL_FORMAT_RAW_OPAQUE)) {
167                 supportAnyRaw = true;
168             }
169         }
170 
171         if (supportRawOpaque) {
172             entry = chars.find(ANDROID_SENSOR_OPAQUE_RAW_SIZE);
173             if (entry.count == 0) {
174                 // Fill in estimated value if HAL does not list it
175                 chars.update(ANDROID_SENSOR_OPAQUE_RAW_SIZE, rawOpaqueSizes);
176                 derivedCharKeys.push(ANDROID_SENSOR_OPAQUE_RAW_SIZE);
177             }
178         }
179 
180         // Check if HAL supports any RAW output, if so, fill in postRawSensitivityBoost range
181         if (supportAnyRaw) {
182             int32_t defaultRange[2] = {100, 100};
183             entry = chars.find(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE);
184             if (entry.count == 0) {
185                 // Fill in default value (100, 100)
186                 chars.update(
187                         ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE,
188                         defaultRange, 2);
189                 derivedCharKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST_RANGE);
190                 // Actual request/results will be derived by camera device.
191                 derivedRequestKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST);
192                 derivedResultKeys.push(ANDROID_CONTROL_POST_RAW_SENSITIVITY_BOOST);
193             }
194         }
195     }
196 
197     // Add those newly added keys to AVAILABLE_CHARACTERISTICS_KEYS
198     // This has to be done at this end of this function.
199     if (derivedCharKeys.size() > 0) {
200         appendAvailableKeys(
201                 chars, ANDROID_REQUEST_AVAILABLE_CHARACTERISTICS_KEYS, derivedCharKeys);
202     }
203     if (derivedRequestKeys.size() > 0) {
204         appendAvailableKeys(
205                 chars, ANDROID_REQUEST_AVAILABLE_REQUEST_KEYS, derivedRequestKeys);
206     }
207     if (derivedResultKeys.size() > 0) {
208         appendAvailableKeys(
209                 chars, ANDROID_REQUEST_AVAILABLE_RESULT_KEYS, derivedResultKeys);
210     }
211     return;
212 }
213 
appendAvailableKeys(CameraMetadata & chars,int32_t keyTag,const Vector<int32_t> & appendKeys)214 void CameraModule::appendAvailableKeys(CameraMetadata &chars,
215         int32_t keyTag, const Vector<int32_t>& appendKeys) {
216     camera_metadata_entry entry = chars.find(keyTag);
217     Vector<int32_t> availableKeys;
218     availableKeys.setCapacity(entry.count + appendKeys.size());
219     for (size_t i = 0; i < entry.count; i++) {
220         availableKeys.push(entry.data.i32[i]);
221     }
222     for (size_t i = 0; i < appendKeys.size(); i++) {
223         availableKeys.push(appendKeys[i]);
224     }
225     chars.update(keyTag, availableKeys);
226 }
227 
CameraModule(camera_module_t * module)228 CameraModule::CameraModule(camera_module_t *module) : mNumberOfCameras(0) {
229     if (module == NULL) {
230         ALOGE("%s: camera hardware module must not be null", __FUNCTION__);
231         assert(0);
232     }
233     mModule = module;
234 }
235 
~CameraModule()236 CameraModule::~CameraModule()
237 {
238     while (mCameraInfoMap.size() > 0) {
239         camera_info cameraInfo = mCameraInfoMap.editValueAt(0);
240         if (cameraInfo.static_camera_characteristics != NULL) {
241             free_camera_metadata(
242                     const_cast<camera_metadata_t*>(cameraInfo.static_camera_characteristics));
243         }
244         mCameraInfoMap.removeItemsAt(0);
245     }
246 
247     while (mPhysicalCameraInfoMap.size() > 0) {
248         camera_metadata_t* metadata = mPhysicalCameraInfoMap.editValueAt(0);
249         if (metadata != NULL) {
250             free_camera_metadata(metadata);
251         }
252         mPhysicalCameraInfoMap.removeItemsAt(0);
253     }
254 }
255 
init()256 int CameraModule::init() {
257     ATRACE_CALL();
258     int res = OK;
259     if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4 &&
260             mModule->init != NULL) {
261         ATRACE_BEGIN("camera_module->init");
262         res = mModule->init();
263         ATRACE_END();
264     }
265     mNumberOfCameras = getNumberOfCameras();
266     mCameraInfoMap.setCapacity(mNumberOfCameras);
267     return res;
268 }
269 
getCameraInfo(int cameraId,struct camera_info * info)270 int CameraModule::getCameraInfo(int cameraId, struct camera_info *info) {
271     ATRACE_CALL();
272     Mutex::Autolock lock(mCameraInfoLock);
273     if (cameraId < 0) {
274         ALOGE("%s: Invalid camera ID %d", __FUNCTION__, cameraId);
275         return -EINVAL;
276     }
277 
278     // Only override static_camera_characteristics for API2 devices
279     int apiVersion = mModule->common.module_api_version;
280     if (apiVersion < CAMERA_MODULE_API_VERSION_2_0) {
281         int ret;
282         ATRACE_BEGIN("camera_module->get_camera_info");
283         ret = mModule->get_camera_info(cameraId, info);
284         // Fill in this so CameraService won't be confused by
285         // possibly 0 device_version
286         info->device_version = CAMERA_DEVICE_API_VERSION_1_0;
287         ATRACE_END();
288         return ret;
289     }
290 
291     ssize_t index = mCameraInfoMap.indexOfKey(cameraId);
292     if (index == NAME_NOT_FOUND) {
293         // Get camera info from raw module and cache it
294         camera_info rawInfo, cameraInfo;
295         ATRACE_BEGIN("camera_module->get_camera_info");
296         int ret = mModule->get_camera_info(cameraId, &rawInfo);
297         ATRACE_END();
298         if (ret != 0) {
299             return ret;
300         }
301         int deviceVersion = rawInfo.device_version;
302         if (deviceVersion < CAMERA_DEVICE_API_VERSION_3_0) {
303             // static_camera_characteristics is invalid
304             *info = rawInfo;
305             return ret;
306         }
307         CameraMetadata m;
308         m.append(rawInfo.static_camera_characteristics);
309         deriveCameraCharacteristicsKeys(rawInfo.device_version, m);
310         cameraInfo = rawInfo;
311         cameraInfo.static_camera_characteristics = m.release();
312         index = mCameraInfoMap.add(cameraId, cameraInfo);
313     }
314 
315     assert(index != NAME_NOT_FOUND);
316     // return the cached camera info
317     *info = mCameraInfoMap[index];
318     return OK;
319 }
320 
getPhysicalCameraInfo(int physicalCameraId,camera_metadata_t ** physicalInfo)321 int CameraModule::getPhysicalCameraInfo(int physicalCameraId, camera_metadata_t **physicalInfo) {
322     ATRACE_CALL();
323     Mutex::Autolock lock(mCameraInfoLock);
324     if (physicalCameraId < mNumberOfCameras) {
325         ALOGE("%s: Invalid physical camera ID %d", __FUNCTION__, physicalCameraId);
326         return -EINVAL;
327     }
328 
329     // Only query physical camera info for 2.5 version for newer
330     int apiVersion = mModule->common.module_api_version;
331     if (apiVersion < CAMERA_MODULE_API_VERSION_2_5) {
332         ALOGE("%s: Module version must be at least 2.5 to handle getPhysicalCameraInfo",
333                 __FUNCTION__);
334         return -ENODEV;
335     }
336     if (mModule->get_physical_camera_info == nullptr) {
337         ALOGE("%s: get_physical_camera is NULL for module version 2.5", __FUNCTION__);
338         return -EINVAL;
339     }
340 
341     ssize_t index = mPhysicalCameraInfoMap.indexOfKey(physicalCameraId);
342     if (index == NAME_NOT_FOUND) {
343         // Get physical camera characteristics, and cache it
344         camera_metadata_t *info = nullptr;
345         ATRACE_BEGIN("camera_module->get_physical_camera_info");
346         int ret = mModule->get_physical_camera_info(physicalCameraId, &info);
347         ATRACE_END();
348         if (ret != 0) {
349             return ret;
350         }
351 
352         // The camera_metadata_t returned by get_physical_camera_info could be using
353         // more memory than necessary due to unused reserved space. Reduce the
354         // size by appending it to a new CameraMetadata object, which internally
355         // calls resizeIfNeeded.
356         CameraMetadata m;
357         m.append(info);
358         camera_metadata_t* derivedMetadata = m.release();
359         index = mPhysicalCameraInfoMap.add(physicalCameraId, derivedMetadata);
360     }
361 
362     assert(index != NAME_NOT_FOUND);
363     *physicalInfo = mPhysicalCameraInfoMap[index];
364     return OK;
365 }
366 
getDeviceVersion(int cameraId)367 int CameraModule::getDeviceVersion(int cameraId) {
368     ssize_t index = mDeviceVersionMap.indexOfKey(cameraId);
369     if (index == NAME_NOT_FOUND) {
370         int deviceVersion;
371         if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_0) {
372             struct camera_info info;
373             getCameraInfo(cameraId, &info);
374             deviceVersion = info.device_version;
375         } else {
376             deviceVersion = CAMERA_DEVICE_API_VERSION_1_0;
377         }
378         index = mDeviceVersionMap.add(cameraId, deviceVersion);
379     }
380     assert(index != NAME_NOT_FOUND);
381     return mDeviceVersionMap[index];
382 }
383 
open(const char * id,struct hw_device_t ** device)384 int CameraModule::open(const char* id, struct hw_device_t** device) {
385     int res;
386     ATRACE_BEGIN("camera_module->open");
387     res = filterOpenErrorCode(mModule->common.methods->open(&mModule->common, id, device));
388     ATRACE_END();
389     return res;
390 }
391 
isOpenLegacyDefined() const392 bool CameraModule::isOpenLegacyDefined() const {
393     if (getModuleApiVersion() < CAMERA_MODULE_API_VERSION_2_3) {
394         return false;
395     }
396     return mModule->open_legacy != NULL;
397 }
398 
openLegacy(const char * id,uint32_t halVersion,struct hw_device_t ** device)399 int CameraModule::openLegacy(
400         const char* id, uint32_t halVersion, struct hw_device_t** device) {
401     int res;
402     ATRACE_BEGIN("camera_module->open_legacy");
403     res = mModule->open_legacy(&mModule->common, id, halVersion, device);
404     ATRACE_END();
405     return res;
406 }
407 
getNumberOfCameras()408 int CameraModule::getNumberOfCameras() {
409     int numCameras;
410     ATRACE_BEGIN("camera_module->get_number_of_cameras");
411     numCameras = mModule->get_number_of_cameras();
412     ATRACE_END();
413     return numCameras;
414 }
415 
setCallbacks(const camera_module_callbacks_t * callbacks)416 int CameraModule::setCallbacks(const camera_module_callbacks_t *callbacks) {
417     int res = OK;
418     ATRACE_BEGIN("camera_module->set_callbacks");
419     if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_1) {
420         res = mModule->set_callbacks(callbacks);
421     }
422     ATRACE_END();
423     return res;
424 }
425 
isVendorTagDefined() const426 bool CameraModule::isVendorTagDefined() const {
427     return mModule->get_vendor_tag_ops != NULL;
428 }
429 
getVendorTagOps(vendor_tag_ops_t * ops)430 void CameraModule::getVendorTagOps(vendor_tag_ops_t* ops) {
431     if (mModule->get_vendor_tag_ops) {
432         ATRACE_BEGIN("camera_module->get_vendor_tag_ops");
433         mModule->get_vendor_tag_ops(ops);
434         ATRACE_END();
435     }
436 }
437 
isSetTorchModeSupported() const438 bool CameraModule::isSetTorchModeSupported() const {
439     if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_4) {
440         if (mModule->set_torch_mode == NULL) {
441             ALOGE("%s: Module 2.4 device must support set torch API!",
442                     __FUNCTION__);
443             return false;
444         }
445         return true;
446     }
447     return false;
448 }
449 
setTorchMode(const char * camera_id,bool enable)450 int CameraModule::setTorchMode(const char* camera_id, bool enable) {
451     int res = INVALID_OPERATION;
452     if (mModule->set_torch_mode != NULL) {
453         ATRACE_BEGIN("camera_module->set_torch_mode");
454         res = mModule->set_torch_mode(camera_id, enable);
455         ATRACE_END();
456     }
457     return res;
458 }
459 
isStreamCombinationSupported(int cameraId,camera_stream_combination_t * streams)460 int CameraModule::isStreamCombinationSupported(int cameraId, camera_stream_combination_t *streams) {
461     int res = INVALID_OPERATION;
462     if (mModule->is_stream_combination_supported != NULL) {
463         ATRACE_BEGIN("camera_module->is_stream_combination_supported");
464         res = mModule->is_stream_combination_supported(cameraId, streams);
465         ATRACE_END();
466     }
467     return res;
468 }
469 
notifyDeviceStateChange(uint64_t deviceState)470 void CameraModule::notifyDeviceStateChange(uint64_t deviceState) {
471    if (getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_5 &&
472            mModule->notify_device_state_change != NULL) {
473        ATRACE_BEGIN("camera_module->notify_device_state_change");
474        ALOGI("%s: calling notify_device_state_change with state %" PRId64, __FUNCTION__,
475                deviceState);
476        mModule->notify_device_state_change(deviceState);
477        ATRACE_END();
478    }
479 }
480 
isLogicalMultiCamera(const common::V1_0::helper::CameraMetadata & metadata,std::unordered_set<std::string> * physicalCameraIds)481 bool CameraModule::isLogicalMultiCamera(
482         const common::V1_0::helper::CameraMetadata& metadata,
483         std::unordered_set<std::string>* physicalCameraIds) {
484     if (physicalCameraIds == nullptr) {
485         ALOGE("%s: physicalCameraIds must not be null", __FUNCTION__);
486         return false;
487     }
488 
489     bool isLogicalMultiCamera = false;
490     camera_metadata_ro_entry_t capabilities =
491             metadata.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
492     for (size_t i = 0; i < capabilities.count; i++) {
493         if (capabilities.data.u8[i] ==
494                 ANDROID_REQUEST_AVAILABLE_CAPABILITIES_LOGICAL_MULTI_CAMERA) {
495             isLogicalMultiCamera = true;
496             break;
497         }
498     }
499 
500     if (isLogicalMultiCamera) {
501         camera_metadata_ro_entry_t entry =
502                 metadata.find(ANDROID_LOGICAL_MULTI_CAMERA_PHYSICAL_IDS);
503         const uint8_t* ids = entry.data.u8;
504         size_t start = 0;
505         for (size_t i = 0; i < entry.count; ++i) {
506             if (ids[i] == '\0') {
507                 if (start != i) {
508                     const char* physicalId = reinterpret_cast<const char*>(ids+start);
509                     physicalCameraIds->emplace(physicalId);
510                 }
511                 start = i + 1;
512             }
513         }
514     }
515     return isLogicalMultiCamera;
516 }
517 
filterOpenErrorCode(status_t err)518 status_t CameraModule::filterOpenErrorCode(status_t err) {
519     switch(err) {
520         case NO_ERROR:
521         case -EBUSY:
522         case -EINVAL:
523         case -EUSERS:
524             return err;
525         default:
526             break;
527     }
528     return -ENODEV;
529 }
530 
removeCamera(int cameraId)531 void CameraModule::removeCamera(int cameraId) {
532     // Skip HAL1 devices which isn't cached in mCameraInfoMap and don't advertise
533     // static_camera_characteristics
534     if (getDeviceVersion(cameraId) >= CAMERA_DEVICE_API_VERSION_3_0) {
535         std::unordered_set<std::string> physicalIds;
536         camera_metadata_t *metadata = const_cast<camera_metadata_t*>(
537                 mCameraInfoMap.valueFor(cameraId).static_camera_characteristics);
538         common::V1_0::helper::CameraMetadata hidlMetadata(metadata);
539 
540         if (isLogicalMultiCamera(hidlMetadata, &physicalIds)) {
541             for (const auto& id : physicalIds) {
542                 int idInt = std::stoi(id);
543                 if (mPhysicalCameraInfoMap.indexOfKey(idInt) >= 0) {
544                     free_camera_metadata(mPhysicalCameraInfoMap[idInt]);
545                     mPhysicalCameraInfoMap.removeItem(idInt);
546                 } else {
547                     ALOGE("%s: Cannot find corresponding static metadata for physical id %s",
548                             __FUNCTION__, id.c_str());
549                 }
550             }
551         }
552     }
553 
554     mCameraInfoMap.removeItem(cameraId);
555     mDeviceVersionMap.removeItem(cameraId);
556 }
557 
getModuleApiVersion() const558 uint16_t CameraModule::getModuleApiVersion() const {
559     return mModule->common.module_api_version;
560 }
561 
getModuleName() const562 const char* CameraModule::getModuleName() const {
563     return mModule->common.name;
564 }
565 
getHalApiVersion() const566 uint16_t CameraModule::getHalApiVersion() const {
567     return mModule->common.hal_api_version;
568 }
569 
getModuleAuthor() const570 const char* CameraModule::getModuleAuthor() const {
571     return mModule->common.author;
572 }
573 
getDso()574 void* CameraModule::getDso() {
575     return mModule->common.dso;
576 }
577 
578 } // namespace helper
579 } // namespace V1_0
580 } // namespace common
581 } // namespace camera
582 } // namespace hardware
583 } // namespace android
584