blob: 19f7bdd7b2e8aaa105f1a0191c979004f8bf3530 [file] [log] [blame]
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -08001/*
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 "CamProvider@2.4-impl"
18#include <android/log.h>
19
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080020#include "CameraProvider.h"
Yin-Chia Yeh248ed702017-01-23 17:27:26 -080021#include "CameraDevice_1_0.h"
22#include "CameraDevice_3_2.h"
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080023#include <string.h>
24#include <utils/Trace.h>
25
26
27namespace android {
28namespace hardware {
29namespace camera {
30namespace provider {
31namespace V2_4 {
32namespace implementation {
33
34namespace {
35const char *kLegacyProviderName = "legacy/0";
36// "device@<version>/legacy/<id>"
37const std::regex kDeviceNameRE("device@([0-9]+\\.[0-9]+)/legacy/(.+)");
38const char *kHAL3_2 = "3.2";
39const char *kHAL1_0 = "1.0";
40const int kMaxCameraDeviceNameLen = 128;
41const int kMaxCameraIdLen = 16;
42
Andreas Gampe0b171f12017-04-04 20:02:25 -070043bool matchDeviceName(const hidl_string& deviceName, std::string* deviceVersion,
44 std::string* cameraId) {
45 std::string deviceNameStd(deviceName.c_str());
46 std::smatch sm;
47 if (std::regex_match(deviceNameStd, sm, kDeviceNameRE)) {
48 if (deviceVersion != nullptr) {
49 *deviceVersion = sm[1];
50 }
51 if (cameraId != nullptr) {
52 *cameraId = sm[2];
53 }
54 return true;
55 }
56 return false;
57}
58
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080059} // anonymous namespace
60
61using ::android::hardware::camera::common::V1_0::CameraMetadataType;
62using ::android::hardware::camera::common::V1_0::Status;
63
64/**
65 * static callback forwarding methods from HAL to instance
66 */
67void CameraProvider::sCameraDeviceStatusChange(
68 const struct camera_module_callbacks* callbacks,
69 int camera_id,
70 int new_status) {
Yin-Chia Yeh6dc9b532017-02-09 18:43:35 -080071 CameraProvider* cp = const_cast<CameraProvider*>(
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080072 static_cast<const CameraProvider*>(callbacks));
73
74 if (cp == nullptr) {
75 ALOGE("%s: callback ops is null", __FUNCTION__);
76 return;
77 }
78
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080079 Mutex::Autolock _l(cp->mCbLock);
80 char cameraId[kMaxCameraIdLen];
81 snprintf(cameraId, sizeof(cameraId), "%d", camera_id);
82 std::string cameraIdStr(cameraId);
83 cp->mCameraStatusMap[cameraIdStr] = (camera_device_status_t) new_status;
84 if (cp->mCallbacks != nullptr) {
85 CameraDeviceStatus status = (CameraDeviceStatus) new_status;
86 for (auto const& deviceNamePair : cp->mCameraDeviceNames) {
87 if (cameraIdStr.compare(deviceNamePair.first) == 0) {
88 cp->mCallbacks->cameraDeviceStatusChange(
89 deviceNamePair.second, status);
90 }
91 }
92 }
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -080093}
94
95void CameraProvider::sTorchModeStatusChange(
96 const struct camera_module_callbacks* callbacks,
97 const char* camera_id,
98 int new_status) {
Yin-Chia Yeh6dc9b532017-02-09 18:43:35 -080099 CameraProvider* cp = const_cast<CameraProvider*>(
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800100 static_cast<const CameraProvider*>(callbacks));
101
102 if (cp == nullptr) {
103 ALOGE("%s: callback ops is null", __FUNCTION__);
104 return;
105 }
106
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800107 Mutex::Autolock _l(cp->mCbLock);
108 if (cp->mCallbacks != nullptr) {
109 std::string cameraIdStr(camera_id);
110 TorchModeStatus status = (TorchModeStatus) new_status;
111 for (auto const& deviceNamePair : cp->mCameraDeviceNames) {
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800112 if (cameraIdStr.compare(deviceNamePair.first) == 0) {
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800113 cp->mCallbacks->torchModeStatusChange(
114 deviceNamePair.second, status);
115 }
116 }
117 }
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800118}
119
120Status CameraProvider::getHidlStatus(int status) {
121 switch (status) {
122 case 0: return Status::OK;
123 case -ENODEV: return Status::INTERNAL_ERROR;
124 case -EINVAL: return Status::ILLEGAL_ARGUMENT;
125 default:
126 ALOGE("%s: unknown HAL status code %d", __FUNCTION__, status);
127 return Status::INTERNAL_ERROR;
128 }
129}
130
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800131std::string CameraProvider::getLegacyCameraId(const hidl_string& deviceName) {
Andreas Gampe0b171f12017-04-04 20:02:25 -0700132 std::string cameraId;
133 matchDeviceName(deviceName, nullptr, &cameraId);
134 return cameraId;
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800135}
136
137int CameraProvider::getCameraDeviceVersion(const hidl_string& deviceName) {
Andreas Gampe0b171f12017-04-04 20:02:25 -0700138 std::string deviceVersion;
139 bool match = matchDeviceName(deviceName, &deviceVersion, nullptr);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800140 if (!match) {
141 return -1;
142 }
Andreas Gampe0b171f12017-04-04 20:02:25 -0700143 if (deviceVersion == kHAL3_2) {
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800144 // maybe switched to 3.4 or define the hidl version enum later
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800145 return CAMERA_DEVICE_API_VERSION_3_2;
Andreas Gampe0b171f12017-04-04 20:02:25 -0700146 } else if (deviceVersion == kHAL1_0) {
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800147 return CAMERA_DEVICE_API_VERSION_1_0;
148 }
149 return 0;
150}
151
152std::string CameraProvider::getHidlDeviceName(
153 std::string cameraId, int deviceVersion) {
154 // Maybe consider create a version check method and SortedVec to speed up?
155 if (deviceVersion != CAMERA_DEVICE_API_VERSION_1_0 &&
156 deviceVersion != CAMERA_DEVICE_API_VERSION_3_2 &&
157 deviceVersion != CAMERA_DEVICE_API_VERSION_3_3 &&
158 deviceVersion != CAMERA_DEVICE_API_VERSION_3_4 ) {
159 return hidl_string("");
160 }
161 const char* versionStr = (deviceVersion == CAMERA_DEVICE_API_VERSION_1_0) ? kHAL1_0 : kHAL3_2;
162 char deviceName[kMaxCameraDeviceNameLen];
163 snprintf(deviceName, sizeof(deviceName), "device@%s/legacy/%s",
164 versionStr, cameraId.c_str());
165 return deviceName;
166}
167
168CameraProvider::CameraProvider() :
169 camera_module_callbacks_t({sCameraDeviceStatusChange,
170 sTorchModeStatusChange}) {
171 mInitFailed = initialize();
172}
173
174CameraProvider::~CameraProvider() {}
175
176bool CameraProvider::initialize() {
177 camera_module_t *rawModule;
178 int err = hw_get_module(CAMERA_HARDWARE_MODULE_ID,
179 (const hw_module_t **)&rawModule);
180 if (err < 0) {
181 ALOGE("Could not load camera HAL module: %d (%s)", err, strerror(-err));
182 return true;
183 }
184
185 mModule = new CameraModule(rawModule);
186 err = mModule->init();
187 if (err != OK) {
Yin-Chia Yehfca2e742017-01-31 16:00:20 -0800188 ALOGE("Could not initialize camera HAL module: %d (%s)", err, strerror(-err));
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800189 mModule.clear();
190 return true;
191 }
192 ALOGI("Loaded \"%s\" camera module", mModule->getModuleName());
193
Shuzhen Wangefb7bfa2017-03-15 18:26:39 -0700194 // Setup vendor tags here so HAL can setup vendor keys in camera characteristics
195 VendorTagDescriptor::clearGlobalVendorTagDescriptor();
196 if (!setUpVendorTags()) {
197 ALOGE("%s: Vendor tag setup failed, will not be available.", __FUNCTION__);
198 }
199
Yin-Chia Yehfca2e742017-01-31 16:00:20 -0800200 // Setup callback now because we are going to try openLegacy next
201 err = mModule->setCallbacks(this);
202 if (err != OK) {
203 ALOGE("Could not set camera module callback: %d (%s)", err, strerror(-err));
204 mModule.clear();
205 return true;
206 }
207
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800208 mNumberOfLegacyCameras = mModule->getNumberOfCameras();
209 for (int i = 0; i < mNumberOfLegacyCameras; i++) {
Emilian Peevc9ded512017-04-10 16:12:55 +0100210 struct camera_info info;
211 auto rc = mModule->getCameraInfo(i, &info);
212 if (rc != NO_ERROR) {
213 ALOGE("%s: Camera info query failed!", __func__);
214 mModule.clear();
215 return true;
216 }
217
218 if (checkCameraVersion(i, info) != OK) {
219 ALOGE("%s: Camera version check failed!", __func__);
220 mModule.clear();
221 return true;
222 }
223
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800224 char cameraId[kMaxCameraIdLen];
225 snprintf(cameraId, sizeof(cameraId), "%d", i);
226 std::string cameraIdStr(cameraId);
227 mCameraStatusMap[cameraIdStr] = CAMERA_DEVICE_STATUS_PRESENT;
228 mCameraIds.add(cameraIdStr);
229
230 // initialize mCameraDeviceNames and mOpenLegacySupported
231 mOpenLegacySupported[cameraIdStr] = false;
232 int deviceVersion = mModule->getDeviceVersion(i);
233 mCameraDeviceNames.add(
234 std::make_pair(cameraIdStr,
235 getHidlDeviceName(cameraIdStr, deviceVersion)));
236 if (deviceVersion >= CAMERA_DEVICE_API_VERSION_3_2 &&
237 mModule->isOpenLegacyDefined()) {
238 // try open_legacy to see if it actually works
239 struct hw_device_t* halDev = nullptr;
240 int ret = mModule->openLegacy(cameraId, CAMERA_DEVICE_API_VERSION_1_0, &halDev);
241 if (ret == 0) {
242 mOpenLegacySupported[cameraIdStr] = true;
243 halDev->close(halDev);
244 mCameraDeviceNames.add(
245 std::make_pair(cameraIdStr,
246 getHidlDeviceName(cameraIdStr, CAMERA_DEVICE_API_VERSION_1_0)));
247 } else if (ret == -EBUSY || ret == -EUSERS) {
248 // Looks like this provider instance is not initialized during
249 // system startup and there are other camera users already.
250 // Not a good sign but not fatal.
251 ALOGW("%s: open_legacy try failed!", __FUNCTION__);
252 }
253 }
254 }
255
Eino-Ville Talvala0f5eb832017-02-09 19:45:31 -0800256 return false; // mInitFailed
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800257}
258
Emilian Peevc9ded512017-04-10 16:12:55 +0100259/**
260 * Check that the device HAL version is still in supported.
261 */
262int CameraProvider::checkCameraVersion(int id, camera_info info) {
263 if (mModule == nullptr) {
264 return NO_INIT;
265 }
266
267 // device_version undefined in CAMERA_MODULE_API_VERSION_1_0,
268 // All CAMERA_MODULE_API_VERSION_1_0 devices are backward-compatible
269 if (mModule->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_0) {
270 // Verify the device version is in the supported range
271 switch (info.device_version) {
272 case CAMERA_DEVICE_API_VERSION_1_0:
273 case CAMERA_DEVICE_API_VERSION_3_2:
274 case CAMERA_DEVICE_API_VERSION_3_3:
275 case CAMERA_DEVICE_API_VERSION_3_4:
276 // in support
277 break;
278 case CAMERA_DEVICE_API_VERSION_2_0:
279 case CAMERA_DEVICE_API_VERSION_2_1:
280 case CAMERA_DEVICE_API_VERSION_3_0:
281 case CAMERA_DEVICE_API_VERSION_3_1:
282 // no longer supported
283 default:
284 ALOGE("%s: Device %d has HAL version %x, which is not supported",
285 __FUNCTION__, id, info.device_version);
286 return NO_INIT;
287 }
288 }
289
290 return OK;
291}
292
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800293bool CameraProvider::setUpVendorTags() {
294 ATRACE_CALL();
295 vendor_tag_ops_t vOps = vendor_tag_ops_t();
296
297 // Check if vendor operations have been implemented
298 if (!mModule->isVendorTagDefined()) {
299 ALOGI("%s: No vendor tags defined for this device.", __FUNCTION__);
Eino-Ville Talvala0f5eb832017-02-09 19:45:31 -0800300 return true;
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800301 }
302
303 mModule->getVendorTagOps(&vOps);
304
305 // Ensure all vendor operations are present
306 if (vOps.get_tag_count == nullptr || vOps.get_all_tags == nullptr ||
307 vOps.get_section_name == nullptr || vOps.get_tag_name == nullptr ||
308 vOps.get_tag_type == nullptr) {
309 ALOGE("%s: Vendor tag operations not fully defined. Ignoring definitions."
310 , __FUNCTION__);
311 return false;
312 }
313
314 // Read all vendor tag definitions into a descriptor
315 sp<VendorTagDescriptor> desc;
316 status_t res;
317 if ((res = VendorTagDescriptor::createDescriptorFromOps(&vOps, /*out*/desc))
318 != OK) {
319 ALOGE("%s: Could not generate descriptor from vendor tag operations,"
320 "received error %s (%d). Camera clients will not be able to use"
321 "vendor tags", __FUNCTION__, strerror(res), res);
322 return false;
323 }
324
325 // Set the global descriptor to use with camera metadata
326 VendorTagDescriptor::setAsGlobalVendorTagDescriptor(desc);
327 const SortedVector<String8>* sectionNames = desc->getAllSectionNames();
328 size_t numSections = sectionNames->size();
329 std::vector<std::vector<VendorTag>> tagsBySection(numSections);
330 int tagCount = desc->getTagCount();
331 std::vector<uint32_t> tags(tagCount);
332 desc->getTagArray(tags.data());
333 for (int i = 0; i < tagCount; i++) {
334 VendorTag vt;
335 vt.tagId = tags[i];
336 vt.tagName = desc->getTagName(tags[i]);
337 vt.tagType = (CameraMetadataType) desc->getTagType(tags[i]);
338 ssize_t sectionIdx = desc->getSectionIndex(tags[i]);
339 tagsBySection[sectionIdx].push_back(vt);
340 }
341 mVendorTagSections.resize(numSections);
342 for (size_t s = 0; s < numSections; s++) {
343 mVendorTagSections[s].sectionName = (*sectionNames)[s].string();
344 mVendorTagSections[s].tags = tagsBySection[s];
345 }
346 return true;
347}
348
349// Methods from ::android::hardware::camera::provider::V2_4::ICameraProvider follow.
350Return<Status> CameraProvider::setCallback(const sp<ICameraProviderCallback>& callback) {
Yin-Chia Yehfca2e742017-01-31 16:00:20 -0800351 Mutex::Autolock _l(mCbLock);
352 mCallbacks = callback;
353 return Status::OK;
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800354}
355
356Return<void> CameraProvider::getVendorTags(getVendorTags_cb _hidl_cb) {
357 _hidl_cb(Status::OK, mVendorTagSections);
358 return Void();
359}
360
361Return<void> CameraProvider::getCameraIdList(getCameraIdList_cb _hidl_cb) {
362 std::vector<hidl_string> deviceNameList;
363 for (auto const& deviceNamePair : mCameraDeviceNames) {
364 if (mCameraStatusMap[deviceNamePair.first] == CAMERA_DEVICE_STATUS_PRESENT) {
365 deviceNameList.push_back(deviceNamePair.second);
366 }
367 }
368 hidl_vec<hidl_string> hidlDeviceNameList(deviceNameList);
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800369 _hidl_cb(Status::OK, hidlDeviceNameList);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800370 return Void();
371}
372
373Return<void> CameraProvider::isSetTorchModeSupported(isSetTorchModeSupported_cb _hidl_cb) {
374 bool support = mModule->isSetTorchModeSupported();
375 _hidl_cb (Status::OK, support);
376 return Void();
377}
378
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800379Return<void> CameraProvider::getCameraDeviceInterface_V1_x(
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800380 const hidl_string& cameraDeviceName, getCameraDeviceInterface_V1_x_cb _hidl_cb) {
Andreas Gampe0b171f12017-04-04 20:02:25 -0700381 std::string cameraId, deviceVersion;
382 bool match = matchDeviceName(cameraDeviceName, &deviceVersion, &cameraId);
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800383 if (!match) {
384 _hidl_cb(Status::ILLEGAL_ARGUMENT, nullptr);
385 return Void();
386 }
387
Yin-Chia Yeh248ed702017-01-23 17:27:26 -0800388 std::string deviceName(cameraDeviceName.c_str());
389 ssize_t index = mCameraDeviceNames.indexOf(std::make_pair(cameraId, deviceName));
390 if (index == NAME_NOT_FOUND) { // Either an illegal name or a device version mismatch
391 Status status = Status::OK;
392 ssize_t idx = mCameraIds.indexOf(cameraId);
393 if (idx == NAME_NOT_FOUND) {
394 ALOGE("%s: cannot find camera %s!", __FUNCTION__, cameraId.c_str());
395 status = Status::ILLEGAL_ARGUMENT;
396 } else { // invalid version
397 ALOGE("%s: camera device %s does not support version %s!",
398 __FUNCTION__, cameraId.c_str(), deviceVersion.c_str());
399 status = Status::OPERATION_NOT_SUPPORTED;
400 }
401 _hidl_cb(status, nullptr);
402 return Void();
403 }
404
405 if (mCameraStatusMap.count(cameraId) == 0 ||
406 mCameraStatusMap[cameraId] != CAMERA_DEVICE_STATUS_PRESENT) {
407 _hidl_cb(Status::ILLEGAL_ARGUMENT, nullptr);
408 return Void();
409 }
410
411 sp<android::hardware::camera::device::V1_0::implementation::CameraDevice> device =
412 new android::hardware::camera::device::V1_0::implementation::CameraDevice(
413 mModule, cameraId, mCameraDeviceNames);
414
415 if (device == nullptr) {
416 ALOGE("%s: cannot allocate camera device for id %s", __FUNCTION__, cameraId.c_str());
417 _hidl_cb(Status::INTERNAL_ERROR, nullptr);
418 return Void();
419 }
420
421 if (device->isInitFailed()) {
422 ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str());
423 device = nullptr;
424 _hidl_cb(Status::INTERNAL_ERROR, nullptr);
425 return Void();
426 }
427
428 _hidl_cb (Status::OK, device);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800429 return Void();
430}
431
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800432Return<void> CameraProvider::getCameraDeviceInterface_V3_x(
433 const hidl_string& cameraDeviceName, getCameraDeviceInterface_V3_x_cb _hidl_cb) {
Andreas Gampe0b171f12017-04-04 20:02:25 -0700434 std::string cameraId, deviceVersion;
435 bool match = matchDeviceName(cameraDeviceName, &deviceVersion, &cameraId);
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800436 if (!match) {
437 _hidl_cb(Status::ILLEGAL_ARGUMENT, nullptr);
438 return Void();
439 }
440
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800441 std::string deviceName(cameraDeviceName.c_str());
442 ssize_t index = mCameraDeviceNames.indexOf(std::make_pair(cameraId, deviceName));
443 if (index == NAME_NOT_FOUND) { // Either an illegal name or a device version mismatch
444 Status status = Status::OK;
445 ssize_t idx = mCameraIds.indexOf(cameraId);
446 if (idx == NAME_NOT_FOUND) {
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800447 ALOGE("%s: cannot find camera %s!", __FUNCTION__, cameraId.c_str());
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800448 status = Status::ILLEGAL_ARGUMENT;
449 } else { // invalid version
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800450 ALOGE("%s: camera device %s does not support version %s!",
451 __FUNCTION__, cameraId.c_str(), deviceVersion.c_str());
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800452 status = Status::OPERATION_NOT_SUPPORTED;
453 }
454 _hidl_cb(status, nullptr);
455 return Void();
456 }
457
458 if (mCameraStatusMap.count(cameraId) == 0 ||
459 mCameraStatusMap[cameraId] != CAMERA_DEVICE_STATUS_PRESENT) {
460 _hidl_cb(Status::ILLEGAL_ARGUMENT, nullptr);
461 return Void();
462 }
463
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800464 sp<android::hardware::camera::device::V3_2::implementation::CameraDevice> device =
465 new android::hardware::camera::device::V3_2::implementation::CameraDevice(
466 mModule, cameraId, mCameraDeviceNames);
467
468 if (device == nullptr) {
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800469 ALOGE("%s: cannot allocate camera device for id %s", __FUNCTION__, cameraId.c_str());
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800470 _hidl_cb(Status::INTERNAL_ERROR, nullptr);
471 return Void();
472 }
473
474 if (device->isInitFailed()) {
Yin-Chia Yeh9c6dbd52016-12-22 14:55:02 -0800475 ALOGE("%s: camera device %s init failed!", __FUNCTION__, cameraId.c_str());
Yin-Chia Yehf906b3b2016-12-14 19:13:15 -0800476 device = nullptr;
477 _hidl_cb(Status::INTERNAL_ERROR, nullptr);
478 return Void();
479 }
480
481 _hidl_cb (Status::OK, device);
482 return Void();
483}
484
485ICameraProvider* HIDL_FETCH_ICameraProvider(const char* name) {
486 if (strcmp(name, kLegacyProviderName) != 0) {
487 return nullptr;
488 }
489 CameraProvider* provider = new CameraProvider();
490 if (provider == nullptr) {
491 ALOGE("%s: cannot allocate camera provider!", __FUNCTION__);
492 return nullptr;
493 }
494 if (provider->isInitFailed()) {
495 ALOGE("%s: camera provider init failed!", __FUNCTION__);
496 delete provider;
497 return nullptr;
498 }
499 return provider;
500}
501
502} // namespace implementation
503} // namespace V2_4
504} // namespace provider
505} // namespace camera
506} // namespace hardware
507} // namespace android