Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Unified Diff: base/android/java/src/org/chromium/base/library_loader/LibraryLoader.java

Issue 684163002: Library loading fallback. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update for review feedback Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..dfb2fd51653078f2537b0ace1ba02b3f9372b76f 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,38 @@ 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;
rmcilroy 2014/10/29 17:20:43 zipFilePath and libFilePath
petrcermak 2014/10/30 19:55:06 Done (changed apkFilename to apkFilePath as well).
+ String libFilename = System.mapLibraryName(library);
+ if (apkFilename != null && Linker.isInZipFile()) {
rmcilroy 2014/10/29 17:20:43 Do we want to add sLibraryLoadFromApkSupported her
petrcermak 2014/10/30 19:55:06 Probably not because Anton's fallback for devices
rmcilroy 2014/10/31 14:20:21 Acknowledged.
+ // The library is in the APK file.
+ if (!Linker.checkLibraryAlignedInApk(apkFilename, libFilename)) {
Anton 2014/10/29 14:18:26 I think that we should really be checking both ali
petrcermak 2014/10/30 19:55:06 Agreed (will do in a separate patch).
+ 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 +238,7 @@ public class LibraryLoader {
}
}
if (!isLoaded) {
- if (zipfile != null) {
- Linker.loadLibraryInZipFile(zipfile, library);
- sLibraryWasLoadedFromApk = true;
- } else {
- Linker.loadLibrary(library);
- }
+ loadLibrary(zipFilename, libFilename);
}
}
@@ -265,6 +289,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) {
rmcilroy 2014/10/29 17:20:43 zipFilePath and libFilePath
petrcermak 2014/10/30 19:55:06 Done.
+ 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.

Powered by Google App Engine
This is Rietveld 408576698