Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f663c918 authored by Emilian Peev's avatar Emilian Peev
Browse files

Camera: Check and update vendor tag descriptor cache

The vendor tag descriptor cache will be empty for any clients that
connect to camera service before the camera provider is able to
launch.
Try to avoid this case, by checking any incoming metadata for
unknown vendor metadata ids. If an unknown id arrives make sure
to sync with camera service and update the cache accordingly.

Bug: 164187235
Test: Manual using TestingCamera2,
Camera CTS

Change-Id: I231e2043c2c33f6257e675dd8136c86827153d1e
parent d39f47f3
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -501,6 +501,15 @@ static void CameraMetadata_readFromParcel(JNIEnv *env, jclass thiz, jobject parc
                             "Failed to read from parcel (error code %d)", err);
        return;
    }

    // Update vendor descriptor cache if necessary
    auto vendorId = metadata->getVendorId();
    if ((vendorId != CAMERA_METADATA_INVALID_VENDOR_ID) &&
            !VendorTagDescriptorCache::isVendorCachePresent(vendorId)) {
        ALOGW("%s: Tag vendor id missing or cache not initialized, trying to update!",
                __FUNCTION__);
        CameraMetadata_setupGlobalVendorTagDescriptor(env, thiz);
    }
}

static void CameraMetadata_writeToParcel(JNIEnv *env, jclass thiz, jobject parcel, jlong ptr) {
@@ -642,9 +651,7 @@ static jint CameraMetadata_getTypeFromTagLocal(JNIEnv *env, jclass thiz, jlong p
    CameraMetadata* metadata = CameraMetadata_getPointerNoThrow(ptr);
    metadata_vendor_id_t vendorId = CAMERA_METADATA_INVALID_VENDOR_ID;
    if (metadata) {
        const camera_metadata_t *metaBuffer = metadata->getAndLock();
        vendorId = get_camera_metadata_vendor_id(metaBuffer);
        metadata->unlock(metaBuffer);
        vendorId = metadata->getVendorId();
    }

    int tagType = get_local_camera_metadata_tag_type_vendor_id(tag, vendorId);
@@ -673,9 +680,7 @@ static jint CameraMetadata_getTagFromKeyLocal(JNIEnv *env, jclass thiz, jlong pt
    if (metadata) {
        sp<VendorTagDescriptorCache> cache = VendorTagDescriptorCache::getGlobalVendorTagCache();
        if (cache.get()) {
            const camera_metadata_t *metaBuffer = metadata->getAndLock();
            metadata_vendor_id_t vendorId = get_camera_metadata_vendor_id(metaBuffer);
            metadata->unlock(metaBuffer);
            auto vendorId = metadata->getVendorId();
            cache->getVendorTagDescriptor(vendorId, &vTags);
        }
    }
@@ -703,10 +708,8 @@ static jobject CameraMetadata_getAllVendorKeys(JNIEnv* env, jclass thiz, jlong p
        CameraMetadata* metadata = CameraMetadata_getPointerThrow(env, ptr);
        if (metadata == NULL) return NULL;

        const camera_metadata_t *metaBuffer = metadata->getAndLock();
        vendorId = get_camera_metadata_vendor_id(metaBuffer);
        vendorId = metadata->getVendorId();
        cache->getVendorTagDescriptor(vendorId, &vTags);
        metadata->unlock(metaBuffer);
        if (vTags.get() == nullptr) {
            return nullptr;
        }