Add a case for symlinks from APEX to the system partition

Bug: 144533348
Test: atest CtsJniTestCases
Change-Id: I4545e43a64c9ecf26bb7d44b2ea9076e5e44ba31
diff --git a/tests/tests/jni/libjnitest/android_jni_cts_LinkerNamespacesTest.cpp b/tests/tests/jni/libjnitest/android_jni_cts_LinkerNamespacesTest.cpp
index 415bef0..13c6165 100644
--- a/tests/tests/jni/libjnitest/android_jni_cts_LinkerNamespacesTest.cpp
+++ b/tests/tests/jni/libjnitest/android_jni_cts_LinkerNamespacesTest.cpp
@@ -34,6 +34,7 @@
 #include <unordered_set>
 #include <vector>
 
+#include <android-base/file.h>
 #include <android-base/properties.h>
 #include <android-base/strings.h>
 #include <nativehelper/JNIHelp.h>
@@ -186,7 +187,18 @@
 
   std::string baselib = basename(path.c_str());
   bool is_public = public_library_basenames.find(baselib) != public_library_basenames.end();
-  bool is_in_search_path = is_library_on_path(library_search_paths, baselib, path);
+
+  // Special casing for symlinks in APEXes. For bundled APEXes, some files in
+  // the APEXes could be symlinks pointing to libraries in /system/lib to save
+  // storage. In that case, use the realpath so that `is_in_search_path` is
+  // correctly determined
+  bool is_in_search_path;
+  std::string realpath;
+  if (android::base::StartsWith(path, "/apex/") && android::base::Realpath(path, &realpath)) {
+    is_in_search_path = is_library_on_path(library_search_paths, baselib, realpath);
+  } else {
+    is_in_search_path = is_library_on_path(library_search_paths, baselib, path);
+  }
 
   if (is_public) {
     if (is_in_search_path) {