diff options
author | Justin Yun <justinyun@google.com> | 2020-02-18 11:29:07 +0900 |
---|---|---|
committer | Justin Yun <justinyun@google.com> | 2020-02-21 10:40:23 +0900 |
commit | eb4f08c577ca3d39d14ada321ea5f9c7444bd06a (patch) | |
tree | 0018cd8ff6e7d0705d0662be909e0ff61b4d84f2 | |
parent | 272b36d1b5cbab951239b32ed679a9dbc4ffdf1a (diff) |
Use a different VNDK namespace for product apps
As product partition may have a different VNDK version than that of
vendor partition, they may not share the same VNDK namespace for
their apps.
Define a new vndk_product namespace in the system section for product
apps that uses ro.product.vndk.version.
Bug: 149063221
Test: atest libnativeloader_test
Change-Id: I1bb76617104a49b0d11af13d2f116959a18390a3
-rw-r--r-- | libnativeloader/library_namespaces.cpp | 22 | ||||
-rw-r--r-- | libnativeloader/native_loader_test.cpp | 12 | ||||
-rw-r--r-- | libnativeloader/public_libraries.cpp | 24 | ||||
-rw-r--r-- | libnativeloader/public_libraries.h | 3 |
4 files changed, 48 insertions, 13 deletions
diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp index 3d74e2d3e5..dfbdefd53d 100644 --- a/libnativeloader/library_namespaces.cpp +++ b/libnativeloader/library_namespaces.cpp @@ -42,6 +42,7 @@ namespace { // vendor and system namespaces. constexpr const char* kVendorNamespaceName = "sphal"; constexpr const char* kVndkNamespaceName = "vndk"; +constexpr const char* kVndkProductNamespaceName = "vndk_product"; constexpr const char* kArtNamespaceName = "com_android_art"; constexpr const char* kNeuralNetworksNamespaceName = "com_android_neuralnetworks"; constexpr const char* kCronetNamespaceName = "com_android_cronet"; @@ -172,12 +173,12 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t std::string system_exposed_libraries = default_public_libraries(); std::string namespace_name = kClassloaderNamespaceName; - bool unbundled_vendor_or_product_app = false; + ApkOrigin unbundled_app_origin = APK_ORIGIN_DEFAULT; if ((apk_origin == APK_ORIGIN_VENDOR || (apk_origin == APK_ORIGIN_PRODUCT && is_product_vndk_version_defined())) && !is_shared) { - unbundled_vendor_or_product_app = true; + unbundled_app_origin = apk_origin; // For vendor / product apks, give access to the vendor / product lib even though // they are treated as unbundled; the libs and apks are still bundled // together in the vendor / product partition. @@ -275,11 +276,22 @@ Result<NativeLoaderNamespace*> LibraryNamespaces::Create(JNIEnv* env, uint32_t t } } - // Give access to VNDK-SP libraries from the 'vndk' namespace. - if (unbundled_vendor_or_product_app && !vndksp_libraries().empty()) { + // Give access to VNDK-SP libraries from the 'vndk' namespace for unbundled vendor apps. + if (unbundled_app_origin == APK_ORIGIN_VENDOR && !vndksp_libraries_vendor().empty()) { auto vndk_ns = NativeLoaderNamespace::GetExportedNamespace(kVndkNamespaceName, is_bridged); if (vndk_ns.ok()) { - linked = app_ns->Link(*vndk_ns, vndksp_libraries()); + linked = app_ns->Link(*vndk_ns, vndksp_libraries_vendor()); + if (!linked.ok()) { + return linked.error(); + } + } + } + + // Give access to VNDK-SP libraries from the 'vndk_product' namespace for unbundled product apps. + if (unbundled_app_origin == APK_ORIGIN_PRODUCT && !vndksp_libraries_product().empty()) { + auto vndk_ns = NativeLoaderNamespace::GetExportedNamespace(kVndkProductNamespaceName, is_bridged); + if (vndk_ns.ok()) { + linked = app_ns->Link(*vndk_ns, vndksp_libraries_product()); if (!linked.ok()) { return linked.error(); } diff --git a/libnativeloader/native_loader_test.cpp b/libnativeloader/native_loader_test.cpp index cc43e58a00..f0446f0db1 100644 --- a/libnativeloader/native_loader_test.cpp +++ b/libnativeloader/native_loader_test.cpp @@ -97,6 +97,7 @@ static std::unordered_map<std::string, Platform::mock_namespace_handle> namespac {"com_android_art", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com_android_art"))}, {"sphal", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("sphal"))}, {"vndk", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("vndk"))}, + {"vndk_product", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("vndk_product"))}, {"com_android_neuralnetworks", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com_android_neuralnetworks"))}, {"com_android_cronet", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com_android_cronet"))}, {"com_android_os_statsd", TO_MOCK_NAMESPACE(TO_ANDROID_NAMESPACE("com_android_os_statsd"))}, @@ -354,6 +355,7 @@ class NativeLoaderTest_Create : public NativeLoaderTest { bool expected_link_with_art_ns = true; bool expected_link_with_sphal_ns = !vendor_public_libraries().empty(); bool expected_link_with_vndk_ns = false; + bool expected_link_with_vndk_product_ns = false; bool expected_link_with_default_ns = false; bool expected_link_with_neuralnetworks_ns = true; bool expected_link_with_cronet_ns = true; @@ -361,7 +363,8 @@ class NativeLoaderTest_Create : public NativeLoaderTest { std::string expected_shared_libs_to_platform_ns = default_public_libraries(); std::string expected_shared_libs_to_art_ns = art_public_libraries(); std::string expected_shared_libs_to_sphal_ns = vendor_public_libraries(); - std::string expected_shared_libs_to_vndk_ns = vndksp_libraries(); + std::string expected_shared_libs_to_vndk_ns = vndksp_libraries_vendor(); + std::string expected_shared_libs_to_vndk_product_ns = vndksp_libraries_product(); std::string expected_shared_libs_to_default_ns = default_public_libraries(); std::string expected_shared_libs_to_neuralnetworks_ns = neuralnetworks_public_libraries(); std::string expected_shared_libs_to_cronet_ns = cronet_public_libraries(); @@ -400,6 +403,11 @@ class NativeLoaderTest_Create : public NativeLoaderTest { StrEq(expected_shared_libs_to_vndk_ns))) .WillOnce(Return(true)); } + if (expected_link_with_vndk_product_ns) { + EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("vndk_product"), + StrEq(expected_shared_libs_to_vndk_product_ns))) + .WillOnce(Return(true)); + } if (expected_link_with_default_ns) { EXPECT_CALL(*mock, mock_link_namespaces(Eq(IsBridged()), _, NsEq("default"), StrEq(expected_shared_libs_to_default_ns))) @@ -512,7 +520,7 @@ TEST_P(NativeLoaderTest_Create, UnbundledProductApp) { expected_permitted_path + ":/product/" LIB_DIR ":/system/product/" LIB_DIR; expected_shared_libs_to_platform_ns = expected_shared_libs_to_platform_ns + ":" + llndk_libraries_product(); - expected_link_with_vndk_ns = true; + expected_link_with_vndk_product_ns = true; } SetExpectations(); RunTest(); diff --git a/libnativeloader/public_libraries.cpp b/libnativeloader/public_libraries.cpp index 35ef4889d0..277d2c90c0 100644 --- a/libnativeloader/public_libraries.cpp +++ b/libnativeloader/public_libraries.cpp @@ -275,9 +275,7 @@ static std::string InitLlndkLibrariesProduct() { return android::base::Join(*sonames, ':'); } -static std::string InitVndkspLibraries() { - // VNDK-SP is used only for vendor hals which are not available for the - // product partition. +static std::string InitVndkspLibrariesVendor() { std::string config_file = kVndkLibrariesFile; InsertVndkVersionStr(&config_file, false); auto sonames = ReadConfig(config_file, always_true); @@ -288,6 +286,17 @@ static std::string InitVndkspLibraries() { return android::base::Join(*sonames, ':'); } +static std::string InitVndkspLibrariesProduct() { + std::string config_file = kVndkLibrariesFile; + InsertVndkVersionStr(&config_file, true); + auto sonames = ReadConfig(config_file, always_true); + if (!sonames.ok()) { + LOG_ALWAYS_FATAL("%s", sonames.error().message().c_str()); + return ""; + } + return android::base::Join(*sonames, ':'); +} + static std::string InitNeuralNetworksPublicLibraries() { return kNeuralNetworksApexPublicLibrary; } @@ -352,8 +361,13 @@ const std::string& llndk_libraries_vendor() { return list; } -const std::string& vndksp_libraries() { - static std::string list = InitVndkspLibraries(); +const std::string& vndksp_libraries_product() { + static std::string list = InitVndkspLibrariesProduct(); + return list; +} + +const std::string& vndksp_libraries_vendor() { + static std::string list = InitVndkspLibrariesVendor(); return list; } diff --git a/libnativeloader/public_libraries.h b/libnativeloader/public_libraries.h index 5fffb86c10..029566ae08 100644 --- a/libnativeloader/public_libraries.h +++ b/libnativeloader/public_libraries.h @@ -39,7 +39,8 @@ const std::string& extended_public_libraries(); const std::string& neuralnetworks_public_libraries(); const std::string& llndk_libraries_product(); const std::string& llndk_libraries_vendor(); -const std::string& vndksp_libraries(); +const std::string& vndksp_libraries_product(); +const std::string& vndksp_libraries_vendor(); // Returns true if libnativeloader is running on devices and the device has // ro.product.vndk.version property. It returns false for host. |