Skip to content

Commit

Permalink
Check if product is treblelized
Browse files Browse the repository at this point in the history
Previous change on handling product partition was based on the
assumption that all devices for mainline update would be product
treblelized, but it was not true. There are some upgrade devices to S
which is not product treblelized. This change checks if the device is
treblelized with first api level and product vndk version.

Bug: 305749591
Test: AOSP cuttlefish boot succeeded
Test: libnativeloader_e2e_tests passed
Change-Id: I46f9c0e253363b891bdc6b073df3cc14e9f7b5aa
  • Loading branch information
Kiyoung Kim committed Oct 19, 2023
1 parent 534d18f commit 760e495
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
7 changes: 5 additions & 2 deletions libnativeloader/library_namespaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
} else if (apk_origin == APK_ORIGIN_PRODUCT && is_product_treblelized()) {
unbundled_app_origin = APK_ORIGIN_PRODUCT;
apk_origin_msg = "unbundled product apk";

Expand Down Expand Up @@ -405,7 +405,10 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t
auto product_libs = filter_public_libraries(target_sdk_version, uses_libraries,
product_public_libraries());
if (!product_libs.empty()) {
auto target_ns = NativeLoaderNamespace::GetExportedNamespace(kProductNamespaceName, is_bridged);
auto target_ns = system_ns;
if (is_product_treblelized()) {
target_ns = NativeLoaderNamespace::GetExportedNamespace(kProductNamespaceName, is_bridged);
}
if (target_ns.ok()) {
linked = app_ns->Link(&target_ns.value(), product_libs);
if (!linked.ok()) {
Expand Down
21 changes: 12 additions & 9 deletions libnativeloader/native_loader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -378,13 +378,16 @@ TEST_P(NativeLoaderTest_Create, UnbundledProductApp) {
dex_path = "/product/app/foo/foo.apk";
is_shared = false;

expected_namespace_prefix = "product-clns";
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 (is_product_treblelized()) {
expected_namespace_prefix = "product-clns";
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;
}

SetExpectations();
RunTest();
Expand Down
24 changes: 23 additions & 1 deletion libnativeloader/public_libraries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ 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;
ReadExtensionLibraries("/product/etc", &sonames);
if (is_product_treblelized()) {
ReadExtensionLibraries("/product/etc", &sonames);
}
std::string libs = android::base::Join(sonames, ':');
ALOGD("InitProductPublicLibraries: %s", libs.c_str());
return libs;
Expand All @@ -216,6 +218,9 @@ static std::string InitExtendedPublicLibraries() {
std::vector<std::string> sonames;
ReadExtensionLibraries("/system/etc", &sonames);
ReadExtensionLibraries("/system_ext/etc", &sonames);
if (!is_product_treblelized()) {
ReadExtensionLibraries("/product/etc", &sonames);
}
std::string libs = android::base::Join(sonames, ':');
ALOGD("InitExtendedPublicLibraries: %s", libs.c_str());
return libs;
Expand Down Expand Up @@ -256,6 +261,10 @@ static std::string InitLlndkLibrariesVendor() {
}

static std::string InitLlndkLibrariesProduct() {
if (!is_product_treblelized()) {
ALOGD("InitLlndkLibrariesProduct: Product is not treblelized");
return "";
}
std::string config_file;
if (IsProductVndkEnabled()) {
config_file = kLlndkLibrariesFile;
Expand Down Expand Up @@ -416,6 +425,19 @@ const std::map<std::string, std::string>& apex_public_libraries() {
return public_libraries;
}

bool is_product_treblelized() {
#if defined(ART_TARGET_ANDROID)
// 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
}

std::string get_vndk_version(bool is_product_vndk) {
#if defined(ART_TARGET_ANDROID)
if (is_product_vndk) {
Expand Down
6 changes: 6 additions & 0 deletions libnativeloader/public_libraries.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ const std::map<std::string, std::string>& apex_public_libraries();

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 {

Expand Down

0 comments on commit 760e495

Please sign in to comment.