Chromium Code Reviews| Index: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
| diff --git a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
| index 2f922e045b49a910bd1dcbe62b15d7633b66c567..be01f26cd2afd3039efbdc9963ad583375425d29 100644 |
| --- a/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
| +++ b/base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java |
| @@ -12,6 +12,8 @@ import org.chromium.base.CommandLine; |
| import org.chromium.base.JNINamespace; |
| import org.chromium.base.TraceEvent; |
| +import javax.annotation.Nullable; |
| + |
| /** |
| * This class provides functionality to load and register the native libraries. |
| * Callers are allowed to separate loading the libraries from initializing them. |
| @@ -53,8 +55,12 @@ public class LibraryLoader { |
| private static boolean sIsUsingBrowserSharedRelros = false; |
| private static boolean sLoadAtFixedAddressFailed = false; |
| - // One-way switch becomes true if the library was loaded from the APK file |
| - // directly. |
| + // One-way switch becomes true if the device supports loading the Chromium |
| + // library directly from the APK. |
| + private static boolean sLibraryLoadFromApkSupported = false; |
| + |
| + // One-way switch becomes true if the Chromium library was loaded from the |
| + // APK file directly. |
| private static boolean sLibraryWasLoadedFromApk = false; |
| // One-way switch becomes false if the Chromium library should be loaded |
| @@ -168,6 +174,17 @@ public class LibraryLoader { |
| boolean useChromiumLinker = Linker.isUsed(); |
| if (useChromiumLinker) { |
| + String apkFilename = null; |
| + |
| + // Check if the device supports loading a library directly from the APK file. |
| + if (context != null) { |
| + apkFilename = context.getApplicationInfo().sourceDir; |
| + sLibraryLoadFromApkSupported = Linker.checkLibraryLoadFromApkSupport( |
| + apkFilename); |
| + } else { |
| + Log.w(TAG, "loadAlreadyLocked(): null context"); |
| + } |
| + |
| // Load libraries using the Chromium linker. |
| Linker.prepareLibraryLoad(); |
| @@ -180,26 +197,39 @@ public class LibraryLoader { |
| continue; |
| } |
| - String zipfile = null; |
| - if (Linker.isInZipFile()) { |
| - zipfile = context.getApplicationInfo().sourceDir; |
| - sLibraryWasAlignedInApk = Linker.checkLibraryAlignedInApk( |
| - zipfile, System.mapLibraryName(library)); |
| - Log.i(TAG, "Loading " + library + " from within " + zipfile); |
| + // Determine where the library should be loaded from. |
| + String zipFilename = null; |
| + String libFilename = System.mapLibraryName(library); |
| + if (apkFilename != null && Linker.isInZipFile()) { |
| + // The library is in the APK file. |
| + if (!Linker.checkLibraryAlignedInApk( |
| + apkFilename, System.mapLibraryName(library))) { |
|
Anton
2014/10/29 13:35:35
Replace System.mapLibraryName(library) with libFil
petrcermak
2014/10/29 14:01:01
Done.
|
| + sLibraryWasAlignedInApk = false; |
| + } |
| + if (sLibraryLoadFromApkSupported && sLibraryWasAlignedInApk) { |
| + // Load directly from the APK. |
| + Log.i(TAG, "Loading " + library + " directly from within " + |
| + apkFilename); |
| + zipFilename = apkFilename; |
| + } else { |
| + // Fallback. |
| + Log.i(TAG, "Loading " + library + " using fallback from within " + |
| + apkFilename); |
| + libFilename = LibraryLoaderHelper.buildFallbackLibrary( |
| + context, apkFilename, libFilename); |
| + Log.i(TAG, "Built fallback library " + libFilename); |
| + } |
| } else { |
| - Log.i(TAG, "Loading: " + library); |
| + // The library is in its own file. |
| + Log.i(TAG, "Loading " + library); |
| } |
| + // Load the library. |
| boolean isLoaded = false; |
| if (Linker.isUsingBrowserSharedRelros()) { |
| sIsUsingBrowserSharedRelros = true; |
| try { |
| - if (zipfile != null) { |
| - Linker.loadLibraryInZipFile(zipfile, library); |
| - sLibraryWasLoadedFromApk = true; |
| - } else { |
| - Linker.loadLibrary(library); |
| - } |
| + loadLibrary(zipFilename, libFilename); |
| isLoaded = true; |
| } catch (UnsatisfiedLinkError e) { |
| Log.w(TAG, "Failed to load native library with shared RELRO, " + |
| @@ -209,12 +239,7 @@ public class LibraryLoader { |
| } |
| } |
| if (!isLoaded) { |
| - if (zipfile != null) { |
| - Linker.loadLibraryInZipFile(zipfile, library); |
| - sLibraryWasLoadedFromApk = true; |
| - } else { |
| - Linker.loadLibrary(library); |
| - } |
| + loadLibrary(zipFilename, libFilename); |
| } |
| } |
| @@ -265,6 +290,15 @@ public class LibraryLoader { |
| } |
| } |
| + // Load a native shared library with the Chromium linker. If the zip file |
| + // filename is not null, the library is loaded directly from the zip file. |
| + private static void loadLibrary(@Nullable String zipFilename, String libFilename) { |
| + if (zipFilename != null) { |
| + sLibraryWasLoadedFromApk = true; |
| + } |
| + Linker.loadLibrary(zipFilename, libFilename); |
| + } |
| + |
| // The WebView requires the Command Line to be switched over before |
| // initialization is done. This is okay in the WebView's case since the |
| // JNI is already loaded by this point. |