Commit 0d2ac26d authored by Clark DuVall's avatar Clark DuVall Committed by Commit Bot

Fix BundleUtils finding the wrong native lib

In some cases, a library with the name we want will be present in a
system directory such as /system/product/lib. The isolated split class
loader will then "find" the lib there and return it. To get around this,
first we check for libs with the base class loader, then fallback to
ContextUtils.getApplicationContext() class loader if it's not found.

Bug: 1126301
Change-Id: I551b6a59c75711bdf6cccae0dde8d7c658eff0db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521293
Commit-Queue: Clark DuVall <cduvall@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824573}
parent 6c3cee39
...@@ -100,22 +100,10 @@ public final class BundleUtils { ...@@ -100,22 +100,10 @@ public final class BundleUtils {
@CalledByNative @CalledByNative
public static String getNativeLibraryPath(String libraryName) { public static String getNativeLibraryPath(String libraryName) {
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
ClassLoader classLoader = ContextUtils.getApplicationContext().getClassLoader(); // Due to b/171269960 isolated split class loaders have an empty library path, so check
String path = getNativeLibraryPathFromClassLoader(classLoader, libraryName); // the base module class loader which loaded BundleUtils.
// TODO(b/171269960): Isolated split class loaders have an empty library path, so check return ((BaseDexClassLoader) BundleUtils.class.getClassLoader())
// the parent class loader as well. .findLibrary(libraryName);
if (path == null) {
path = getNativeLibraryPathFromClassLoader(classLoader.getParent(), libraryName);
}
return path;
} }
} }
private static String getNativeLibraryPathFromClassLoader(
ClassLoader classLoader, String libraryName) {
if (classLoader == null) {
return null;
}
return ((BaseDexClassLoader) classLoader).findLibrary(libraryName);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment