LG8n: Add libcamera_metadata shim for stripping out system camera cap

Change-Id: I8f7772fc9ec15a00c4b630866aa7fc162a52c1aa
Signed-off-by: SamarV-121 <samarvispute121@pm.me>
This commit is contained in:
luk1337 2024-07-17 16:28:21 +10:00 committed by xoo2001
parent 262dfe35ac
commit 92e30c2243
3 changed files with 65 additions and 2 deletions

View file

@ -97,8 +97,7 @@ PRODUCT_PACKAGES += \
android.hardware.camera.provider@2.6.vendor android.hardware.camera.provider@2.6.vendor
PRODUCT_PACKAGES += \ PRODUCT_PACKAGES += \
libcamera_metadata.vendor \ libshim_camera_metadata \
libcamera_metadata_shim \
libdng_sdk.vendor \ libdng_sdk.vendor \
libexpat.vendor \ libexpat.vendor \
libpng.vendor libpng.vendor

View file

@ -16,3 +16,10 @@ cc_library_shared {
"libmedia_headers", "libmedia_headers",
], ],
} }
cc_library {
name: "libshim_camera_metadata",
shared_libs: ["libcamera_metadata"],
srcs: ["libshim_camera_metadata.cpp"],
vendor: true
}

View file

@ -0,0 +1,57 @@
/*
* Copyright (C) 2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <dlfcn.h>
#include <system/camera_metadata.h>
#include <vector>
extern "C" int add_camera_metadata_entry(camera_metadata_t* dst, uint32_t tag, const void* data,
size_t data_count) {
static auto add_camera_metadata_entry_orig =
reinterpret_cast<typeof(add_camera_metadata_entry)*>(
dlsym(RTLD_NEXT, "add_camera_metadata_entry"));
if (tag == ANDROID_REQUEST_AVAILABLE_CAPABILITIES) {
std::vector<uint8_t> caps;
auto u8 = reinterpret_cast<const uint8_t*>(data);
for (size_t i = 0; i < data_count; i++) {
if (u8[i] != ANDROID_REQUEST_AVAILABLE_CAPABILITIES_SYSTEM_CAMERA) {
caps.emplace_back(u8[i]);
}
}
return add_camera_metadata_entry_orig(dst, tag, caps.data(), caps.size());
}
return add_camera_metadata_entry_orig(dst, tag, data, data_count);
}
extern "C" int update_camera_metadata_entry(camera_metadata_t* dst, size_t index, const void* data,
size_t data_count,
camera_metadata_entry_t* updated_entry) {
static auto update_camera_metadata_entry_orig =
reinterpret_cast<typeof(update_camera_metadata_entry)*>(
dlsym(RTLD_NEXT, "update_camera_metadata_entry"));
if (camera_metadata_entry_t entry;
find_camera_metadata_entry(dst, ANDROID_REQUEST_AVAILABLE_CAPABILITIES, &entry) == 0 &&
entry.index == index) {
std::vector<uint8_t> caps;
auto u8 = reinterpret_cast<const uint8_t*>(data);
for (size_t i = 0; i < data_count; i++) {
if (u8[i] != ANDROID_REQUEST_AVAILABLE_CAPABILITIES_SYSTEM_CAMERA) {
caps.emplace_back(u8[i]);
}
}
return update_camera_metadata_entry_orig(dst, index, caps.data(), caps.size(),
updated_entry);
}
return update_camera_metadata_entry_orig(dst, index, data, data_count, updated_entry);
}