46
46
" %s:%d: %s CHECK '" #predicate " ' failed." ,\
47
47
__FILE__, __LINE__, __FUNCTION__)
48
48
49
+ using namespace std ::string_literals;
50
+
49
51
namespace android {
50
52
51
53
#if defined(__ANDROID__)
@@ -236,10 +238,15 @@ class LibraryNamespaces {
236
238
// Different name is useful for debugging
237
239
namespace_name = kVendorClassloaderNamespaceName ;
238
240
ALOGD (" classloader namespace configured for unbundled vendor apk. library_path=%s" , library_path.c_str ());
239
- } else if (!oem_public_libraries_. empty ()) {
240
- // oem_public_libraries are NOT available to vendor apks, otherwise it
241
+ } else {
242
+ // oem and product public libraries are NOT available to vendor apks, otherwise it
241
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
252
NativeLoaderNamespace native_loader_ns;
@@ -351,6 +358,8 @@ class LibraryNamespaces {
351
358
std::string vndksp_native_libraries_system_config =
352
359
root_dir + kVndkspNativeLibrariesSystemConfigPathFromRoot ;
353
360
361
+ std::string product_public_native_libraries_dir = " /product/etc" ;
362
+
354
363
std::string error_msg;
355
364
LOG_ALWAYS_FATAL_IF (
356
365
!ReadConfig (public_native_libraries_system_config, &sonames, always_true, &error_msg),
@@ -373,7 +382,7 @@ class LibraryNamespaces {
373
382
//
374
383
// TODO(dimitry): this is a bit misleading since we do not know
375
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
386
// For now we rely on CTS test to catch things like this but
378
387
// it should probably be addressed in the future.
379
388
for (const auto & soname : sonames) {
@@ -387,13 +396,43 @@ class LibraryNamespaces {
387
396
// system libs that are exposed to apps. The libs in the txt files must be
388
397
// named as lib<name>.<companyname>.so.
389
398
sonames.clear ();
390
- std::string dirname = base::Dirname (public_native_libraries_system_config);
391
- std::unique_ptr<DIR, decltype (&closedir)> dir (opendir (dirname.c_str ()), closedir);
399
+ ReadExtensionLibraries (base::Dirname (public_native_libraries_system_config).c_str (), &sonames);
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
432
if (dir != nullptr ) {
393
433
// Failing to opening the dir is not an error, which can happen in
394
434
// webview_zygote.
395
- struct dirent * ent;
396
- while ((ent = readdir (dir.get ())) != nullptr ) {
435
+ while (struct dirent * ent = readdir (dir.get ())) {
397
436
if (ent->d_type != DT_REG && ent->d_type != DT_LNK) {
398
437
continue ;
399
438
}
@@ -403,14 +442,17 @@ class LibraryNamespaces {
403
442
const size_t start = kPublicNativeLibrariesExtensionConfigPrefixLen ;
404
443
const size_t end = filename.size () - kPublicNativeLibrariesExtensionConfigSuffixLen ;
405
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
446
LOG_ALWAYS_FATAL_IF (
408
447
company_name.empty (),
409
448
" Error extracting company name from public native library list file path \" %s\" " ,
410
449
config_file_path.c_str ());
450
+
451
+ std::string error_msg;
452
+
411
453
LOG_ALWAYS_FATAL_IF (
412
454
!ReadConfig (
413
- config_file_path, & sonames,
455
+ config_file_path, sonames,
414
456
[&company_name](const std::string& soname, std::string* error_msg) {
415
457
if (android::base::StartsWith (soname, " lib" ) &&
416
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
475
bool ReadConfig (const std::string& configFile, std::vector<std::string>* sonames,
457
476
const std::function<bool (const std::string& /* soname */ ,
458
477
std::string* /* error_msg */ )>& check_soname,
@@ -559,6 +578,7 @@ class LibraryNamespaces {
559
578
std::string system_public_libraries_;
560
579
std::string vendor_public_libraries_;
561
580
std::string oem_public_libraries_;
581
+ std::string product_public_libraries_;
562
582
std::string system_llndk_libraries_;
563
583
std::string system_vndksp_libraries_;
564
584
0 commit comments