diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-03-07 21:25:30 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-03-07 21:25:30 +0000 |
commit | bb8bdf1ffed6943de7823008dd9f10d6b5c962c0 (patch) | |
tree | 1cac338d61132ab03a12d1d5685f57ba83f8485f | |
parent | ec9fab685ffc845120e26c2f8757ae9895b48d02 (diff) | |
parent | 1cffc693d9babee49cf1104b7bc8dd2214509369 (diff) | |
download | art-bb8bdf1ffed6943de7823008dd9f10d6b5c962c0.tar.gz |
Snap for 11545237 from 1cffc693d9babee49cf1104b7bc8dd2214509369 to android14-tests-release
Change-Id: I036b055f41aaeef7c16aadf1b9798f4ad0a78cd1
-rw-r--r-- | libnativeloader/library_namespaces.cpp | 5 | ||||
-rw-r--r-- | libnativeloader/native_loader_test.cpp | 18 | ||||
-rw-r--r-- | libnativeloader/public_libraries.cpp | 61 | ||||
-rw-r--r-- | libnativeloader/public_libraries.h | 10 | ||||
-rwxr-xr-x | tools/buildbot-build.sh | 3 |
5 files changed, 71 insertions, 26 deletions
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp index 9aeebf38ad..1e29f4e457 100644 --- a/libnativeloader/library_namespaces.cpp +++ b/libnativeloader/library_namespaces.cpp @@ -255,7 +255,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t // Different name is useful for debugging namespace_name = kVendorClassloaderNamespaceName; - } else if (apk_origin == APK_ORIGIN_PRODUCT && is_product_vndk_version_defined()) { + } else if (apk_origin == APK_ORIGIN_PRODUCT && is_product_treblelized()) { unbundled_app_origin = APK_ORIGIN_PRODUCT; apk_origin_msg = "unbundled product apk"; @@ -406,8 +406,7 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t product_public_libraries()); if (!product_libs.empty()) { auto target_ns = system_ns; - if (is_product_vndk_version_defined()) { - // If ro.product.vndk.version is defined, product namespace provides the product libraries. + if (is_product_treblelized()) { target_ns = NativeLoaderNamespace::GetExportedNamespace(kProductNamespaceName, is_bridged); } if (target_ns.ok()) { diff --git a/libnativeloader/native_loader_test.cpp b/libnativeloader/native_loader_test.cpp index 6c0c8b17a7..72348ed364 100644 --- a/libnativeloader/native_loader_test.cpp +++ b/libnativeloader/native_loader_test.cpp @@ -18,9 +18,9 @@ #include "native_loader_test.h" -#include <dlfcn.h> - +#include <android-base/properties.h> #include <android-base/strings.h> +#include <dlfcn.h> #include <gtest/gtest.h> #include "nativehelper/scoped_utf_chars.h" @@ -348,7 +348,9 @@ TEST_P(NativeLoaderTest_Create, UnbundledVendorApp) { expected_permitted_path = expected_permitted_path + ":/vendor/" LIB_DIR; expected_shared_libs_to_platform_ns = default_public_libraries() + ":" + llndk_libraries_vendor(); - expected_link_with_vndk_ns = true; + if (android::base::GetProperty("ro.vndk.version", "") != "") { + expected_link_with_vndk_ns = true; + } SetExpectations(); RunTest(); } @@ -378,15 +380,19 @@ TEST_P(NativeLoaderTest_Create, UnbundledProductApp) { dex_path = "/product/app/foo/foo.apk"; is_shared = false; - if (is_product_vndk_version_defined()) { + if (is_product_treblelized()) { expected_namespace_prefix = "product-clns"; - expected_library_path = expected_library_path + ":/product/" LIB_DIR ":/system/product/" LIB_DIR; + expected_library_path = + expected_library_path + ":/product/" LIB_DIR ":/system/product/" LIB_DIR; expected_permitted_path = expected_permitted_path + ":/product/" LIB_DIR ":/system/product/" LIB_DIR; expected_shared_libs_to_platform_ns = append_extended_libraries(default_public_libraries() + ":" + llndk_libraries_product()); - expected_link_with_vndk_product_ns = true; + if (android::base::GetProperty("ro.product.vndk.version", "") != "") { + expected_link_with_vndk_product_ns = true; + } } + SetExpectations(); RunTest(); } diff --git a/libnativeloader/public_libraries.cpp b/libnativeloader/public_libraries.cpp index 896c5c7106..87210c8f14 100644 --- a/libnativeloader/public_libraries.cpp +++ b/libnativeloader/public_libraries.cpp @@ -55,6 +55,7 @@ constexpr const char* kExtendedPublicLibrariesFileSuffix = ".txt"; constexpr const char* kApexLibrariesConfigFile = "/linkerconfig/apex.libraries.config.txt"; constexpr const char* kVendorPublicLibrariesFile = "/vendor/etc/public.libraries.txt"; constexpr const char* kLlndkLibrariesFile = "/apex/com.android.vndk.v{}/etc/llndk.libraries.{}.txt"; +constexpr const char* kLlndkLibrariesNoVndkFile = "/system/etc/llndk.libraries.txt"; constexpr const char* kVndkLibrariesFile = "/apex/com.android.vndk.v{}/etc/vndksp.libraries.{}.txt"; @@ -200,7 +201,7 @@ static std::string InitVendorPublicLibraries() { // contains the extended public libraries that are loaded from the system namespace. static std::string InitProductPublicLibraries() { std::vector<std::string> sonames; - if (is_product_vndk_version_defined()) { + if (is_product_treblelized()) { ReadExtensionLibraries("/product/etc", &sonames); } std::string libs = android::base::Join(sonames, ':'); @@ -217,7 +218,7 @@ static std::string InitExtendedPublicLibraries() { std::vector<std::string> sonames; ReadExtensionLibraries("/system/etc", &sonames); ReadExtensionLibraries("/system_ext/etc", &sonames); - if (!is_product_vndk_version_defined()) { + if (!is_product_treblelized()) { ReadExtensionLibraries("/product/etc", &sonames); } std::string libs = android::base::Join(sonames, ':'); @@ -225,9 +226,30 @@ static std::string InitExtendedPublicLibraries() { return libs; } +bool IsVendorVndkEnabled() { +#if defined(ART_TARGET_ANDROID) + return android::base::GetProperty("ro.vndk.version", "") != ""; +#else + return true; +#endif +} + +bool IsProductVndkEnabled() { +#if defined(ART_TARGET_ANDROID) + return android::base::GetProperty("ro.product.vndk.version", "") != ""; +#else + return true; +#endif +} + static std::string InitLlndkLibrariesVendor() { - std::string config_file = kLlndkLibrariesFile; - InsertVndkVersionStr(&config_file, false); + std::string config_file; + if (IsVendorVndkEnabled()) { + config_file = kLlndkLibrariesFile; + InsertVndkVersionStr(&config_file, false); + } else { + config_file = kLlndkLibrariesNoVndkFile; + } auto sonames = ReadConfig(config_file, always_true); if (!sonames.ok()) { LOG_ALWAYS_FATAL("%s: %s", config_file.c_str(), sonames.error().message().c_str()); @@ -239,12 +261,17 @@ static std::string InitLlndkLibrariesVendor() { } static std::string InitLlndkLibrariesProduct() { - if (!is_product_vndk_version_defined()) { - ALOGD("InitLlndkLibrariesProduct: No product VNDK version defined"); + if (!is_product_treblelized()) { + ALOGD("InitLlndkLibrariesProduct: Product is not treblelized"); return ""; } - std::string config_file = kLlndkLibrariesFile; - InsertVndkVersionStr(&config_file, true); + std::string config_file; + if (IsProductVndkEnabled()) { + config_file = kLlndkLibrariesFile; + InsertVndkVersionStr(&config_file, true); + } else { + config_file = kLlndkLibrariesNoVndkFile; + } auto sonames = ReadConfig(config_file, always_true); if (!sonames.ok()) { LOG_ALWAYS_FATAL("%s: %s", config_file.c_str(), sonames.error().message().c_str()); @@ -256,6 +283,11 @@ static std::string InitLlndkLibrariesProduct() { } static std::string InitVndkspLibrariesVendor() { + if (!IsVendorVndkEnabled()) { + ALOGD("InitVndkspLibrariesVendor: VNDK is deprecated with vendor"); + return ""; + } + std::string config_file = kVndkLibrariesFile; InsertVndkVersionStr(&config_file, false); auto sonames = ReadConfig(config_file, always_true); @@ -269,8 +301,8 @@ static std::string InitVndkspLibrariesVendor() { } static std::string InitVndkspLibrariesProduct() { - if (!is_product_vndk_version_defined()) { - ALOGD("InitVndkspLibrariesProduct: No product VNDK version defined"); + if (!IsProductVndkEnabled()) { + ALOGD("InitVndkspLibrariesProduct: VNDK is deprecated with product"); return ""; } std::string config_file = kVndkLibrariesFile; @@ -393,9 +425,14 @@ const std::map<std::string, std::string>& apex_public_libraries() { return public_libraries; } -bool is_product_vndk_version_defined() { +bool is_product_treblelized() { #if defined(ART_TARGET_ANDROID) - return android::sysprop::VndkProperties::product_vndk_version().has_value(); + // Product is not treblelized iff launching version is prior to R and + // ro.product.vndk.version is not defined + static bool product_treblelized = + !(android::base::GetIntProperty("ro.product.first_api_level", 0) < __ANDROID_API_R__ && + !android::sysprop::VndkProperties::product_vndk_version().has_value()); + return product_treblelized; #else return false; #endif diff --git a/libnativeloader/public_libraries.h b/libnativeloader/public_libraries.h index 6f5a13c9b3..1830824704 100644 --- a/libnativeloader/public_libraries.h +++ b/libnativeloader/public_libraries.h @@ -47,12 +47,14 @@ const std::string& apex_jni_libraries(const std::string& apex_name); // but provided by com.android.foo APEX. const std::map<std::string, std::string>& apex_public_libraries(); -// Returns true if libnativeloader is running on devices and the device has -// ro.product.vndk.version property. It returns false for host. -bool is_product_vndk_version_defined(); - std::string get_vndk_version(bool is_product_vndk); +// Returnes true if libnativeloader is running on devices and the device has +// treblelized product partition. It returns false for host. +// TODO: Remove this function and assume it is always true once when Mainline does not support any +// devices launched with Q or below. +bool is_product_treblelized(); + // These are exported for testing namespace internal { diff --git a/tools/buildbot-build.sh b/tools/buildbot-build.sh index cac98cb131..1467037149 100755 --- a/tools/buildbot-build.sh +++ b/tools/buildbot-build.sh @@ -411,6 +411,7 @@ EOF msginfo "Generating linkerconfig" "in $linkerconfig_out" rm -rf $linkerconfig_out mkdir -p $linkerconfig_out - $ANDROID_HOST_OUT/bin/linkerconfig --target $linkerconfig_out --root $linkerconfig_root --vndk $platform_version + # TODO(b/300291157): Remove VNDK versions and enable Treble once VNDK deprecation is set as default + $ANDROID_HOST_OUT/bin/linkerconfig --target $linkerconfig_out --root $linkerconfig_root --vndk $platform_version --product_vndk $platform_version msgnote "Don't be scared by \"Unable to access VNDK APEX\" message, it's not fatal" fi |