Use versioned VNDK directories

VNDK directories will have "-$VER" as their suffix, where $VER is set
by the property "ro.vndk.version".
For example, if the $VER is "28", the vndk-sp directory is
"system/lib[64]/vndk-sp-28/".

Bug: 69984421
Test: Check if the apps that uses RS works without problem.
Change-Id: I24a9b0ca51f12ab5562a661761401d057d6346a0
diff --git a/cpu_ref/rsCpuExecutable.cpp b/cpu_ref/rsCpuExecutable.cpp
index 9dcc842..3c62d05 100644
--- a/cpu_ref/rsCpuExecutable.cpp
+++ b/cpu_ref/rsCpuExecutable.cpp
@@ -137,16 +137,20 @@
     linkDriverName.erase(linkDriverName.length() - 3);
     linkDriverName.replace(0, 3, "-l");
 
+    static const std::string vndkLibCompilerRt =
+        getVndkSysLibPath() + "/libcompiler_rt.so";
     const char *compiler_rt = isRunningInVndkNamespace() ?
-        SYSLIBPATH_VNDK "/libcompiler_rt.so" : SYSLIBPATH "/libcompiler_rt.so";
+        vndkLibCompilerRt.c_str() : SYSLIBPATH "/libcompiler_rt.so";
     const char *mTriple = "-mtriple=" DEFAULT_TARGET_TRIPLE_STRING;
     const char *libPath = "--library-path=" SYSLIBPATH;
     // vndk path is only added when RS framework is running in vndk namespace.
     // If we unconditionally add the vndk path to the library path, then RS
     // driver in the vndk-sp directory will always be used even for CPU fallback
     // case, where RS framework is loaded from the default namespace.
+    static const std::string vndkLibPathString =
+        "--library-path=" + getVndkSysLibPath();
     const char *vndkLibPath = isRunningInVndkNamespace() ?
-        "--library-path=" SYSLIBPATH_VNDK : "";
+        vndkLibPathString.c_str() : "";
     const char *vendorLibPath = "--library-path=" SYSLIBPATH_VENDOR;
 
     // The search path order should be vendor -> vndk -> system
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index cb13b11..2961321 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -161,8 +161,9 @@
 // be for a source APK change or an OTA. In either case, the APK would be
 // reinstalled, which would already clear the code_cache/ directory.
 bool isChecksumNeeded(const char *cacheDir) {
+    static const std::string sysLibPathVndk = getVndkSysLibPath();
     if ((::strcmp(SYSLIBPATH, cacheDir) == 0) ||
-        (::strcmp(SYSLIBPATH_VNDK, cacheDir) == 0) ||
+        (::strcmp(sysLibPathVndk.c_str(), cacheDir) == 0) ||
         (::strcmp(SYSLIBPATH_VENDOR, cacheDir) == 0))
         return false;
     char buf[PROP_VALUE_MAX];
diff --git a/cpu_ref/rsCpuScript.h b/cpu_ref/rsCpuScript.h
index bd192ab..a8f0db6 100644
--- a/cpu_ref/rsCpuScript.h
+++ b/cpu_ref/rsCpuScript.h
@@ -194,6 +194,16 @@
   }
 }
 
+inline std::string getVndkSysLibPath() {
+  char buf[PROP_VALUE_MAX];
+  android::renderscript::property_get("ro.vndk.version", buf, "");
+  std::string versionStr = buf;
+  if (versionStr != "" && versionStr != "current") {
+    return SYSLIBPATH_VNDK "-" + versionStr;
+  }
+  return SYSLIBPATH_VNDK;
+}
+
 }  // anonymous namespace
 
 #endif  // RSD_CPU_SCRIPT_H