From 7640dd1396d3343c4f65938171af45c5ff43c4bf Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Thu, 18 Jul 2024 14:56:11 +0100 Subject: Fix for b/349878424 Avoid loading the libsobrige library. Test: device boots after mainline update. Bug: 349878424 Bug: 343621630 Change-Id: I19e1b9a9328eb5a39b9a91580f602a09d5366ae7 --- libnativeloader/native_loader.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'libnativeloader/native_loader.cpp') diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp index 580d833d9d..231b3c5aea 100644 --- a/libnativeloader/native_loader.cpp +++ b/libnativeloader/native_loader.cpp @@ -31,6 +31,7 @@ #include "android-base/file.h" #include "android-base/macros.h" +#include #include "android-base/strings.h" #include "android-base/thread_annotations.h" #include "base/macros.h" @@ -40,6 +41,7 @@ #ifdef ART_TARGET_ANDROID #include "android-modules-utils/sdk_level.h" +#include "android/api-level.h" #include "library_namespaces.h" #include "log/log.h" #include "nativeloader/dlext_namespaces.h" @@ -269,6 +271,20 @@ jstring CreateClassLoaderNamespace(JNIEnv* env, return nullptr; } +#if defined(ART_TARGET_ANDROID) +static bool ShouldBypassLoadingLibSoBridge() { + struct stat st; + if (stat("/system/lib64/libsobridge.so", &st) != 0) { + return false; + } + std::string property = android::base::GetProperty("ro.product.build.fingerprint", ""); + return android_get_device_api_level() == 33 && + (property.starts_with("Xiaomi") || + property.starts_with("Redmi") || + property.starts_with("POCO")); +} +#endif + void* OpenNativeLibrary(JNIEnv* env, int32_t target_sdk_version, const char* path, @@ -317,6 +333,16 @@ void* OpenNativeLibrary(JNIEnv* env, } } + // Handle issue b/349878424. + static bool bypass_loading_libsobridge = ShouldBypassLoadingLibSoBridge(); + + if (bypass_loading_libsobridge && strcmp("libsobridge.so", path) == 0) { + // Load a different library to pretend the loading was successful. This + // allows the device to boot. + ALOGD("Loading libbase.so instead of libsobridge.so due to b/349878424"); + path = "libbase.so"; + } + // Fall back to the system namespace. This happens for preloaded JNI // libraries in the zygote. void* handle = OpenSystemLibrary(path, RTLD_NOW); -- cgit v1.2.3-59-g8ed1b