diff --git a/device.mk b/device.mk index ae4b014..bdcaa6f 100644 --- a/device.mk +++ b/device.mk @@ -97,8 +97,7 @@ PRODUCT_PACKAGES += \ android.hardware.camera.provider@2.6.vendor PRODUCT_PACKAGES += \ - libcamera_metadata.vendor \ - libcamera_metadata_shim \ + libshim_camera_metadata \ libdng_sdk.vendor \ libexpat.vendor \ libpng.vendor diff --git a/libshims/Android.bp b/libshims/Android.bp index 3069e6f..5c5f56a 100644 --- a/libshims/Android.bp +++ b/libshims/Android.bp @@ -16,3 +16,10 @@ cc_library_shared { "libmedia_headers", ], } + +cc_library { + name: "libshim_camera_metadata", + shared_libs: ["libcamera_metadata"], + srcs: ["libshim_camera_metadata.cpp"], + vendor: true +} diff --git a/libshims/libshim_camera_metadata.cpp b/libshims/libshim_camera_metadata.cpp new file mode 100644 index 0000000..f98dc7f --- /dev/null +++ b/libshims/libshim_camera_metadata.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 The LineageOS Project + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include + +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( + dlsym(RTLD_NEXT, "add_camera_metadata_entry")); + + if (tag == ANDROID_REQUEST_AVAILABLE_CAPABILITIES) { + std::vector caps; + auto u8 = reinterpret_cast(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( + 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 caps; + auto u8 = reinterpret_cast(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); +} \ No newline at end of file