summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorInseob Kim2018-05-03 21:39:12 -0500
committerInseob Kim2018-05-15 20:36:25 -0500
commit67cb05654cfa677fd5db33ea0629a9496a9ae907 (patch)
tree09bf4faaeccf76fa4016db43d231c897a2435bd6
parenta3d95cf2f8f5b9acca9be690bc3c6904de6677de (diff)
downloadplatform-system-core-67cb05654cfa677fd5db33ea0629a9496a9ae907.tar.gz
platform-system-core-67cb05654cfa677fd5db33ea0629a9496a9ae907.tar.xz
platform-system-core-67cb05654cfa677fd5db33ea0629a9496a9ae907.zip
Support product-specific libraries
Product-specific libraries in /product/lib can be exposed to Android apps by adding the list of the libs into /product/etc/public.libraries-<companyname>.txt. The libs MUST be named as lib<name>.<companyname>.so. Bug: 73095206 Test: with taimen mma -j and runtest.sh. The libs are all loaded in system, but not in vendor. After reinstalling app using adb -r and reopening app, only libraries listed in .txt are loaded Change-Id: I7c386813c72a7b225a7f244b6c5fec4ac0660fd3
-rw-r--r--libnativeloader/native_loader.cpp86
-rw-r--r--libnativeloader/test/Android.bp20
-rw-r--r--libnativeloader/test/Android.mk7
-rw-r--r--libnativeloader/test/public.libraries-product1.txt2
-rw-r--r--libnativeloader/test/src/android/test/app/TestActivity.java2
-rw-r--r--rootdir/etc/ld.config.txt15
-rw-r--r--rootdir/etc/ld.config.vndk_lite.txt9
7 files changed, 104 insertions, 37 deletions
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 0ebb22647..7fef10685 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -46,6 +46,8 @@
46 "%s:%d: %s CHECK '" #predicate "' failed.",\ 46 "%s:%d: %s CHECK '" #predicate "' failed.",\
47 __FILE__, __LINE__, __FUNCTION__) 47 __FILE__, __LINE__, __FUNCTION__)
48 48
49using namespace std::string_literals;
50
49namespace android { 51namespace android {
50 52
51#if defined(__ANDROID__) 53#if defined(__ANDROID__)
@@ -236,10 +238,15 @@ class LibraryNamespaces {
236 // Different name is useful for debugging 238 // Different name is useful for debugging
237 namespace_name = kVendorClassloaderNamespaceName; 239 namespace_name = kVendorClassloaderNamespaceName;
238 ALOGD("classloader namespace configured for unbundled vendor apk. library_path=%s", library_path.c_str()); 240 ALOGD("classloader namespace configured for unbundled vendor apk. library_path=%s", library_path.c_str());
239 } else if (!oem_public_libraries_.empty()) { 241 } else {
240 // oem_public_libraries are NOT available to vendor apks, otherwise it 242 // oem and product public libraries are NOT available to vendor apks, otherwise it
241 // would be system->vendor violation. 243 // would be system->vendor violation.
242 system_exposed_libraries = system_exposed_libraries + ":" + oem_public_libraries_.c_str(); 244 if (!oem_public_libraries_.empty()) {
245 system_exposed_libraries = system_exposed_libraries + ':' + oem_public_libraries_;
246 }
247 if (!product_public_libraries_.empty()) {
248 system_exposed_libraries = system_exposed_libraries + ':' + product_public_libraries_;
249 }
243 } 250 }
244 251
245 NativeLoaderNamespace native_loader_ns; 252 NativeLoaderNamespace native_loader_ns;
@@ -351,6 +358,8 @@ class LibraryNamespaces {
351 std::string vndksp_native_libraries_system_config = 358 std::string vndksp_native_libraries_system_config =
352 root_dir + kVndkspNativeLibrariesSystemConfigPathFromRoot; 359 root_dir + kVndkspNativeLibrariesSystemConfigPathFromRoot;
353 360
361 std::string product_public_native_libraries_dir = "/product/etc";
362
354 std::string error_msg; 363 std::string error_msg;
355 LOG_ALWAYS_FATAL_IF( 364 LOG_ALWAYS_FATAL_IF(
356 !ReadConfig(public_native_libraries_system_config, &sonames, always_true, &error_msg), 365 !ReadConfig(public_native_libraries_system_config, &sonames, always_true, &error_msg),
@@ -373,7 +382,7 @@ class LibraryNamespaces {
373 // 382 //
374 // TODO(dimitry): this is a bit misleading since we do not know 383 // TODO(dimitry): this is a bit misleading since we do not know
375 // if the vendor public library is going to be opened from /vendor/lib 384 // if the vendor public library is going to be opened from /vendor/lib
376 // we might as well end up loading them from /system/lib 385 // we might as well end up loading them from /system/lib or /product/lib
377 // For now we rely on CTS test to catch things like this but 386 // For now we rely on CTS test to catch things like this but
378 // it should probably be addressed in the future. 387 // it should probably be addressed in the future.
379 for (const auto& soname : sonames) { 388 for (const auto& soname : sonames) {
@@ -387,13 +396,43 @@ class LibraryNamespaces {
387 // system libs that are exposed to apps. The libs in the txt files must be 396 // system libs that are exposed to apps. The libs in the txt files must be
388 // named as lib<name>.<companyname>.so. 397 // named as lib<name>.<companyname>.so.
389 sonames.clear(); 398 sonames.clear();
390 std::string dirname = base::Dirname(public_native_libraries_system_config); 399 ReadExtensionLibraries(base::Dirname(public_native_libraries_system_config).c_str(), &sonames);
391 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(dirname.c_str()), closedir); 400 oem_public_libraries_ = base::Join(sonames, ':');
401
402 // read /product/etc/public.libraries-<companyname>.txt which contain partner defined
403 // product libs that are exposed to apps.
404 sonames.clear();
405 ReadExtensionLibraries(product_public_native_libraries_dir.c_str(), &sonames);
406 product_public_libraries_ = base::Join(sonames, ':');
407
408 // Insert VNDK version to llndk and vndksp config file names.
409 insert_vndk_version_str(&llndk_native_libraries_system_config);
410 insert_vndk_version_str(&vndksp_native_libraries_system_config);
411
412 sonames.clear();
413 ReadConfig(llndk_native_libraries_system_config, &sonames, always_true);
414 system_llndk_libraries_ = base::Join(sonames, ':');
415
416 sonames.clear();
417 ReadConfig(vndksp_native_libraries_system_config, &sonames, always_true);
418 system_vndksp_libraries_ = base::Join(sonames, ':');
419
420 sonames.clear();
421 // This file is optional, quietly ignore if the file does not exist.
422 ReadConfig(kPublicNativeLibrariesVendorConfig, &sonames, always_true, nullptr);
423
424 vendor_public_libraries_ = base::Join(sonames, ':');
425 }
426
427 void Reset() { namespaces_.clear(); }
428
429 private:
430 void ReadExtensionLibraries(const char* dirname, std::vector<std::string>* sonames) {
431 std::unique_ptr<DIR, decltype(&closedir)> dir(opendir(dirname), closedir);
392 if (dir != nullptr) { 432 if (dir != nullptr) {
393 // Failing to opening the dir is not an error, which can happen in 433 // Failing to opening the dir is not an error, which can happen in
394 // webview_zygote. 434 // webview_zygote.
395 struct dirent* ent; 435 while (struct dirent* ent = readdir(dir.get())) {
396 while ((ent = readdir(dir.get())) != nullptr) {
397 if (ent->d_type != DT_REG && ent->d_type != DT_LNK) { 436 if (ent->d_type != DT_REG && ent->d_type != DT_LNK) {
398 continue; 437 continue;
399 } 438 }
@@ -403,14 +442,17 @@ class LibraryNamespaces {
403 const size_t start = kPublicNativeLibrariesExtensionConfigPrefixLen; 442 const size_t start = kPublicNativeLibrariesExtensionConfigPrefixLen;
404 const size_t end = filename.size() - kPublicNativeLibrariesExtensionConfigSuffixLen; 443 const size_t end = filename.size() - kPublicNativeLibrariesExtensionConfigSuffixLen;
405 const std::string company_name = filename.substr(start, end - start); 444 const std::string company_name = filename.substr(start, end - start);
406 const std::string config_file_path = dirname + "/" + filename; 445 const std::string config_file_path = dirname + "/"s + filename;
407 LOG_ALWAYS_FATAL_IF( 446 LOG_ALWAYS_FATAL_IF(
408 company_name.empty(), 447 company_name.empty(),
409 "Error extracting company name from public native library list file path \"%s\"", 448 "Error extracting company name from public native library list file path \"%s\"",
410 config_file_path.c_str()); 449 config_file_path.c_str());
450
451 std::string error_msg;
452
411 LOG_ALWAYS_FATAL_IF( 453 LOG_ALWAYS_FATAL_IF(
412 !ReadConfig( 454 !ReadConfig(
413 config_file_path, &sonames, 455 config_file_path, sonames,
414 [&company_name](const std::string& soname, std::string* error_msg) { 456 [&company_name](const std::string& soname, std::string* error_msg) {
415 if (android::base::StartsWith(soname, "lib") && 457 if (android::base::StartsWith(soname, "lib") &&
416 android::base::EndsWith(soname, "." + company_name + ".so")) { 458 android::base::EndsWith(soname, "." + company_name + ".so")) {
@@ -427,32 +469,9 @@ class LibraryNamespaces {
427 } 469 }
428 } 470 }
429 } 471 }
430 oem_public_libraries_ = base::Join(sonames, ':');
431
432 // Insert VNDK version to llndk and vndksp config file names.
433 insert_vndk_version_str(&llndk_native_libraries_system_config);
434 insert_vndk_version_str(&vndksp_native_libraries_system_config);
435
436 sonames.clear();
437 ReadConfig(llndk_native_libraries_system_config, &sonames, always_true);
438 system_llndk_libraries_ = base::Join(sonames, ':');
439
440 sonames.clear();
441 ReadConfig(vndksp_native_libraries_system_config, &sonames, always_true);
442 system_vndksp_libraries_ = base::Join(sonames, ':');
443
444 sonames.clear();
445 // This file is optional, quietly ignore if the file does not exist.
446 ReadConfig(kPublicNativeLibrariesVendorConfig, &sonames, always_true, nullptr);
447
448 vendor_public_libraries_ = base::Join(sonames, ':');
449 } 472 }
450 473
451 void Reset() {
452 namespaces_.clear();
453 }
454 474
455 private:
456 bool ReadConfig(const std::string& configFile, std::vector<std::string>* sonames, 475 bool ReadConfig(const std::string& configFile, std::vector<std::string>* sonames,
457 const std::function<bool(const std::string& /* soname */, 476 const std::function<bool(const std::string& /* soname */,
458 std::string* /* error_msg */)>& check_soname, 477 std::string* /* error_msg */)>& check_soname,
@@ -559,6 +578,7 @@ class LibraryNamespaces {
559 std::string system_public_libraries_; 578 std::string system_public_libraries_;
560 std::string vendor_public_libraries_; 579 std::string vendor_public_libraries_;
561 std::string oem_public_libraries_; 580 std::string oem_public_libraries_;
581 std::string product_public_libraries_;
562 std::string system_llndk_libraries_; 582 std::string system_llndk_libraries_;
563 std::string system_vndksp_libraries_; 583 std::string system_vndksp_libraries_;
564 584
diff --git a/libnativeloader/test/Android.bp b/libnativeloader/test/Android.bp
index 5cf88b09b..d528f3031 100644
--- a/libnativeloader/test/Android.bp
+++ b/libnativeloader/test/Android.bp
@@ -49,3 +49,23 @@ cc_library {
49 "libbase", 49 "libbase",
50 ], 50 ],
51} 51}
52
53cc_library {
54 name: "libfoo.product1",
55 srcs: ["test.cpp"],
56 cflags: ["-DLIBNAME=\"libfoo.product1.so\""],
57 product_specific: true,
58 shared_libs: [
59 "libbase",
60 ],
61}
62
63cc_library {
64 name: "libbar.product1",
65 srcs: ["test.cpp"],
66 cflags: ["-DLIBNAME=\"libbar.product1.so\""],
67 product_specific: true,
68 shared_libs: [
69 "libbase",
70 ],
71}
diff --git a/libnativeloader/test/Android.mk b/libnativeloader/test/Android.mk
index e62545465..65e7b09bc 100644
--- a/libnativeloader/test/Android.mk
+++ b/libnativeloader/test/Android.mk
@@ -30,6 +30,13 @@ LOCAL_MODULE_PATH := $(TARGET_OUT_ETC)
30include $(BUILD_PREBUILT) 30include $(BUILD_PREBUILT)
31 31
32include $(CLEAR_VARS) 32include $(CLEAR_VARS)
33LOCAL_MODULE := public.libraries-product1.txt
34LOCAL_SRC_FILES:= $(LOCAL_MODULE)
35LOCAL_MODULE_CLASS := ETC
36LOCAL_MODULE_PATH := $(TARGET_OUT_PRODUCT_ETC)
37include $(BUILD_PREBUILT)
38
39include $(CLEAR_VARS)
33LOCAL_PACKAGE_NAME := oemlibrarytest-system 40LOCAL_PACKAGE_NAME := oemlibrarytest-system
34LOCAL_MODULE_TAGS := tests 41LOCAL_MODULE_TAGS := tests
35LOCAL_MANIFEST_FILE := system/AndroidManifest.xml 42LOCAL_MANIFEST_FILE := system/AndroidManifest.xml
diff --git a/libnativeloader/test/public.libraries-product1.txt b/libnativeloader/test/public.libraries-product1.txt
new file mode 100644
index 000000000..358154c62
--- /dev/null
+++ b/libnativeloader/test/public.libraries-product1.txt
@@ -0,0 +1,2 @@
1libfoo.product1.so
2libbar.product1.so
diff --git a/libnativeloader/test/src/android/test/app/TestActivity.java b/libnativeloader/test/src/android/test/app/TestActivity.java
index 214892df2..a7a455d33 100644
--- a/libnativeloader/test/src/android/test/app/TestActivity.java
+++ b/libnativeloader/test/src/android/test/app/TestActivity.java
@@ -29,6 +29,8 @@ public class TestActivity extends Activity {
29 tryLoadingLib("bar.oem1"); 29 tryLoadingLib("bar.oem1");
30 tryLoadingLib("foo.oem2"); 30 tryLoadingLib("foo.oem2");
31 tryLoadingLib("bar.oem2"); 31 tryLoadingLib("bar.oem2");
32 tryLoadingLib("foo.product1");
33 tryLoadingLib("bar.product1");
32 } 34 }
33 35
34 private void tryLoadingLib(String name) { 36 private void tryLoadingLib(String name) {
diff --git a/rootdir/etc/ld.config.txt b/rootdir/etc/ld.config.txt
index ba96cc84a..51e3f9efc 100644
--- a/rootdir/etc/ld.config.txt
+++ b/rootdir/etc/ld.config.txt
@@ -37,7 +37,8 @@ additional.namespaces = sphal,vndk,rs
37############################################################################### 37###############################################################################
38namespace.default.isolated = true 38namespace.default.isolated = true
39 39
40namespace.default.search.paths = /system/${LIB} 40namespace.default.search.paths = /system/${LIB}
41namespace.default.search.paths += /product/${LIB}
41 42
42# We can't have entire /system/${LIB} as permitted paths because doing so 43# We can't have entire /system/${LIB} as permitted paths because doing so
43# makes it possible to load libs in /system/${LIB}/vndk* directories by 44# makes it possible to load libs in /system/${LIB}/vndk* directories by
@@ -49,6 +50,7 @@ namespace.default.search.paths = /system/${LIB}
49namespace.default.permitted.paths = /system/${LIB}/drm 50namespace.default.permitted.paths = /system/${LIB}/drm
50namespace.default.permitted.paths += /system/${LIB}/extractors 51namespace.default.permitted.paths += /system/${LIB}/extractors
51namespace.default.permitted.paths += /system/${LIB}/hw 52namespace.default.permitted.paths += /system/${LIB}/hw
53namespace.default.permitted.paths += /product/${LIB}
52# These are where odex files are located. libart has to be able to dlopen the files 54# These are where odex files are located. libart has to be able to dlopen the files
53namespace.default.permitted.paths += /system/framework 55namespace.default.permitted.paths += /system/framework
54namespace.default.permitted.paths += /system/app 56namespace.default.permitted.paths += /system/app
@@ -68,6 +70,8 @@ namespace.default.permitted.paths += /mnt/expand
68 70
69namespace.default.asan.search.paths = /data/asan/system/${LIB} 71namespace.default.asan.search.paths = /data/asan/system/${LIB}
70namespace.default.asan.search.paths += /system/${LIB} 72namespace.default.asan.search.paths += /system/${LIB}
73namespace.default.asan.search.paths += /data/asan/product/${LIB}
74namespace.default.asan.search.paths += /product/${LIB}
71 75
72namespace.default.asan.permitted.paths = /data 76namespace.default.asan.permitted.paths = /data
73namespace.default.asan.permitted.paths += /system/${LIB}/drm 77namespace.default.asan.permitted.paths += /system/${LIB}/drm
@@ -83,6 +87,7 @@ namespace.default.asan.permitted.paths += /odm/framework
83namespace.default.asan.permitted.paths += /odm/app 87namespace.default.asan.permitted.paths += /odm/app
84namespace.default.asan.permitted.paths += /odm/priv-app 88namespace.default.asan.permitted.paths += /odm/priv-app
85namespace.default.asan.permitted.paths += /oem/app 89namespace.default.asan.permitted.paths += /oem/app
90namespace.default.asan.permitted.paths += /product/${LIB}
86namespace.default.asan.permitted.paths += /product/framework 91namespace.default.asan.permitted.paths += /product/framework
87namespace.default.asan.permitted.paths += /product/app 92namespace.default.asan.permitted.paths += /product/app
88namespace.default.asan.permitted.paths += /product/priv-app 93namespace.default.asan.permitted.paths += /product/priv-app
@@ -320,10 +325,13 @@ namespace.vndk.link.default.allow_all_shared_libs = true
320############################################################################### 325###############################################################################
321namespace.system.isolated = false 326namespace.system.isolated = false
322 327
323namespace.system.search.paths = /system/${LIB} 328namespace.system.search.paths = /system/${LIB}
329namespace.system.search.paths += /product/${LIB}
324 330
325namespace.system.asan.search.paths = /data/asan/system/${LIB} 331namespace.system.asan.search.paths = /data/asan/system/${LIB}
326namespace.system.asan.search.paths += /system/${LIB} 332namespace.system.asan.search.paths += /system/${LIB}
333namespace.system.asan.search.paths += /data/asan/product/${LIB}
334namespace.system.asan.search.paths += /product/${LIB}
327 335
328############################################################################### 336###############################################################################
329# Namespace config for binaries under /postinstall. 337# Namespace config for binaries under /postinstall.
@@ -335,4 +343,5 @@ namespace.system.asan.search.paths += /system/${LIB}
335############################################################################### 343###############################################################################
336[postinstall] 344[postinstall]
337namespace.default.isolated = false 345namespace.default.isolated = false
338namespace.default.search.paths = /system/${LIB} 346namespace.default.search.paths = /system/${LIB}
347namespace.default.search.paths += /product/${LIB}
diff --git a/rootdir/etc/ld.config.vndk_lite.txt b/rootdir/etc/ld.config.vndk_lite.txt
index 1fd419586..ab0375539 100644
--- a/rootdir/etc/ld.config.vndk_lite.txt
+++ b/rootdir/etc/ld.config.vndk_lite.txt
@@ -40,6 +40,7 @@ namespace.default.isolated = false
40namespace.default.search.paths = /system/${LIB} 40namespace.default.search.paths = /system/${LIB}
41namespace.default.search.paths += /odm/${LIB} 41namespace.default.search.paths += /odm/${LIB}
42namespace.default.search.paths += /vendor/${LIB} 42namespace.default.search.paths += /vendor/${LIB}
43namespace.default.search.paths += /product/${LIB}
43 44
44namespace.default.asan.search.paths = /data/asan/system/${LIB} 45namespace.default.asan.search.paths = /data/asan/system/${LIB}
45namespace.default.asan.search.paths += /system/${LIB} 46namespace.default.asan.search.paths += /system/${LIB}
@@ -47,6 +48,8 @@ namespace.default.asan.search.paths += /data/asan/odm/${LIB}
47namespace.default.asan.search.paths += /odm/${LIB} 48namespace.default.asan.search.paths += /odm/${LIB}
48namespace.default.asan.search.paths += /data/asan/vendor/${LIB} 49namespace.default.asan.search.paths += /data/asan/vendor/${LIB}
49namespace.default.asan.search.paths += /vendor/${LIB} 50namespace.default.asan.search.paths += /vendor/${LIB}
51namespace.default.asan.search.paths += /data/asan/product/${LIB}
52namespace.default.asan.search.paths += /product/${LIB}
50 53
51############################################################################### 54###############################################################################
52# "sphal" namespace 55# "sphal" namespace
@@ -205,6 +208,7 @@ namespace.default.search.paths += /vendor/${LIB}/vndk-sp
205namespace.default.search.paths += /system/${LIB}/vndk%VNDK_VER% 208namespace.default.search.paths += /system/${LIB}/vndk%VNDK_VER%
206namespace.default.search.paths += /system/${LIB}/vndk-sp%VNDK_VER% 209namespace.default.search.paths += /system/${LIB}/vndk-sp%VNDK_VER%
207namespace.default.search.paths += /system/${LIB} 210namespace.default.search.paths += /system/${LIB}
211namespace.default.search.paths += /product/${LIB}
208 212
209namespace.default.asan.search.paths = /data/asan/odm/${LIB} 213namespace.default.asan.search.paths = /data/asan/odm/${LIB}
210namespace.default.asan.search.paths += /odm/${LIB} 214namespace.default.asan.search.paths += /odm/${LIB}
@@ -224,6 +228,8 @@ namespace.default.asan.search.paths += /data/asan/system/${LIB}/vndk-sp%VNDK_VER
224namespace.default.asan.search.paths += /system/${LIB}/vndk-sp%VNDK_VER% 228namespace.default.asan.search.paths += /system/${LIB}/vndk-sp%VNDK_VER%
225namespace.default.asan.search.paths += /data/asan/system/${LIB} 229namespace.default.asan.search.paths += /data/asan/system/${LIB}
226namespace.default.asan.search.paths += /system/${LIB} 230namespace.default.asan.search.paths += /system/${LIB}
231namespace.default.asan.search.paths += /data/asan/product/${LIB}
232namespace.default.asan.search.paths += /product/${LIB}
227 233
228############################################################################### 234###############################################################################
229# Namespace config for binaries under /postinstall. 235# Namespace config for binaries under /postinstall.
@@ -235,4 +241,5 @@ namespace.default.asan.search.paths += /system/${LIB}
235############################################################################### 241###############################################################################
236[postinstall] 242[postinstall]
237namespace.default.isolated = false 243namespace.default.isolated = false
238namespace.default.search.paths = /system/${LIB} 244namespace.default.search.paths = /system/${LIB}
245namespace.default.search.paths += /product/${LIB}