CameraProvider: Check camera device version

Make sure we are working with supported devices.

Bug: 34392075
Test: Manual using application
Change-Id: I834612303f3e02e79924efbdcc25cff890defefb
This commit is contained in:
Emilian Peev
2017-04-10 16:12:55 +01:00
parent a13ac99f34
commit c9ded51848
2 changed files with 49 additions and 0 deletions

View File

@@ -207,6 +207,20 @@ bool CameraProvider::initialize() {
mNumberOfLegacyCameras = mModule->getNumberOfCameras();
for (int i = 0; i < mNumberOfLegacyCameras; i++) {
struct camera_info info;
auto rc = mModule->getCameraInfo(i, &info);
if (rc != NO_ERROR) {
ALOGE("%s: Camera info query failed!", __func__);
mModule.clear();
return true;
}
if (checkCameraVersion(i, info) != OK) {
ALOGE("%s: Camera version check failed!", __func__);
mModule.clear();
return true;
}
char cameraId[kMaxCameraIdLen];
snprintf(cameraId, sizeof(cameraId), "%d", i);
std::string cameraIdStr(cameraId);
@@ -242,6 +256,40 @@ bool CameraProvider::initialize() {
return false; // mInitFailed
}
/**
* Check that the device HAL version is still in supported.
*/
int CameraProvider::checkCameraVersion(int id, camera_info info) {
if (mModule == nullptr) {
return NO_INIT;
}
// device_version undefined in CAMERA_MODULE_API_VERSION_1_0,
// All CAMERA_MODULE_API_VERSION_1_0 devices are backward-compatible
if (mModule->getModuleApiVersion() >= CAMERA_MODULE_API_VERSION_2_0) {
// Verify the device version is in the supported range
switch (info.device_version) {
case CAMERA_DEVICE_API_VERSION_1_0:
case CAMERA_DEVICE_API_VERSION_3_2:
case CAMERA_DEVICE_API_VERSION_3_3:
case CAMERA_DEVICE_API_VERSION_3_4:
// in support
break;
case CAMERA_DEVICE_API_VERSION_2_0:
case CAMERA_DEVICE_API_VERSION_2_1:
case CAMERA_DEVICE_API_VERSION_3_0:
case CAMERA_DEVICE_API_VERSION_3_1:
// no longer supported
default:
ALOGE("%s: Device %d has HAL version %x, which is not supported",
__FUNCTION__, id, info.device_version);
return NO_INIT;
}
}
return OK;
}
bool CameraProvider::setUpVendorTags() {
ATRACE_CALL();
vendor_tag_ops_t vOps = vendor_tag_ops_t();

View File

@@ -89,6 +89,7 @@ private:
hidl_vec<VendorTagSection> mVendorTagSections;
bool setUpVendorTags();
int checkCameraVersion(int id, camera_info info);
// extract legacy camera ID/device version from a HIDL device name
static std::string getLegacyCameraId(const hidl_string& deviceName);