Load versioned llndk.libraries.txt and vndksp.libraries.txt

When ro.vndk.version has a specific VNDK version in it, use the
llndk.libraries.txt and vndksp.libraries.txt files with the version
suffix in the file names.
If ro.vndk.version is "current" or not set, the version suffix will
not be added.
This is to use a proper VNDK snapshot version configuration for a
vendor patition.

Bug: 69531793
Test: In system/etc directory of a Pixel2 device,
  Change llndk.libraries.txt to llndk.libraries.27.txt
  Change vndksp.libraries.txt to vndksp.libraries.27.txt
  Set ro.vndk.version to 27 in vendor/default.prop
  reboot and check if vendor apks work.

Change-Id: I82d83b6805799ea71cc88d1e0297d265a40c0061
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index 5d160ee..f3c70de 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -35,6 +35,10 @@
 #include <android-base/macros.h>
 #include <android-base/strings.h>
 
+#ifdef __BIONIC__
+#include <android-base/properties.h>
+#endif
+
 #define CHECK(predicate) LOG_ALWAYS_FATAL_IF(!(predicate),\
                                              "%s:%d: %s CHECK '" #predicate "' failed.",\
                                              __FILE__, __LINE__, __FUNCTION__)
@@ -110,6 +114,25 @@
   return std::string(debuggable) == "1";
 }
 
+static std::string vndk_version_str() {
+#ifdef __BIONIC__
+  std::string version = android::base::GetProperty("ro.vndk.version", "");
+  if (version != "" && version != "current") {
+    return "." + version;
+  }
+#endif
+  return "";
+}
+
+static void insert_vndk_version_str(std::string* file_name) {
+  CHECK(file_name != nullptr);
+  size_t insert_pos = file_name->find_last_of(".");
+  if (insert_pos == std::string::npos) {
+    insert_pos = file_name->length();
+  }
+  file_name->insert(insert_pos, vndk_version_str());
+}
+
 class LibraryNamespaces {
  public:
   LibraryNamespaces() : initialized_(false) { }
@@ -318,6 +341,10 @@
                         "Error reading public native library list from \"%s\": %s",
                         public_native_libraries_system_config.c_str(), error_msg.c_str());
 
+    // Insert VNDK version to llndk and vndksp config file names.
+    insert_vndk_version_str(&llndk_native_libraries_system_config);
+    insert_vndk_version_str(&vndksp_native_libraries_system_config);
+
     // For debuggable platform builds use ANDROID_ADDITIONAL_PUBLIC_LIBRARIES environment
     // variable to add libraries to the list. This is intended for platform tests only.
     if (is_debuggable()) {
@@ -347,11 +374,11 @@
     system_public_libraries_ = base::Join(sonames, ':');
 
     sonames.clear();
-    ReadConfig(kLlndkNativeLibrariesSystemConfigPathFromRoot, &sonames);
+    ReadConfig(llndk_native_libraries_system_config, &sonames);
     system_llndk_libraries_ = base::Join(sonames, ':');
 
     sonames.clear();
-    ReadConfig(kVndkspNativeLibrariesSystemConfigPathFromRoot, &sonames);
+    ReadConfig(vndksp_native_libraries_system_config, &sonames);
     system_vndksp_libraries_ = base::Join(sonames, ':');
 
     sonames.clear();