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

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

Issue 200753002: [Android] Workaround of an android platform bug. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ChildProcessService needs to use the hack Created 6 years, 9 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 4e159553d725d095b593ef8fe911264250873ba6..c3b3b35fc5ec0b8b6e4e9b5f868d88a5ddd8901b 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
@@ -4,6 +4,7 @@
package org.chromium.base.library_loader;
+import android.content.Context;
import android.os.SystemClock;
import android.util.Log;
@@ -41,16 +42,42 @@ public class LibraryLoader {
// library_loader_hooks.cc).
private static boolean sInitialized = false;
+ // One-way switch becomes true if the system library loading failed,
+ // and the right native library was found and loaded by the hack.
+ // The flag is used to report UMA stats later.
+ private static boolean sNativeLibraryHackWasUsed = false;
+
+
/**
- * This method blocks until the library is fully loaded and initialized.
+ * TODO: http://crbug.com/354655
+ * remove this method once WebViewChromiumFactoryProvider.java
+ * changes the call to ensureInitialized(null).
*/
public static void ensureInitialized() throws ProcessInitException {
+ ensureInitialized(null);
+ }
+
+ /**
+ * This method blocks until the library is fully loaded and initialized.
+ *
+ * @param context The context in which the method is called, the caller
+ * may pass in a null context if it doesn't know in which context it
+ * is running, or it doesn't need to work around the issue
+ * http://b/13216167.
+ *
+ * When the context is not null and native library was not extracted
+ * by Android package manager, the LibraryLoader class
+ * will extract the native libraries from APK. This is a hack used to
+ * work around some Sony devices with the following platform bug:
+ * http://b/13216167.
+ */
+ public static void ensureInitialized(Context context) throws ProcessInitException {
synchronized (sLock) {
if (sInitialized) {
// Already initialized, nothing to do.
return;
}
- loadAlreadyLocked();
+ loadAlreadyLocked(context);
initializeAlreadyLocked(CommandLine.getJavaSwitchesOrNull());
}
}
@@ -73,9 +100,9 @@ public class LibraryLoader {
*
* @throws ProcessInitException if the native library failed to load.
*/
- public static void loadNow() throws ProcessInitException {
+ public static void loadNow(Context context) throws ProcessInitException {
synchronized (sLock) {
- loadAlreadyLocked();
+ loadAlreadyLocked(context);
}
}
@@ -93,7 +120,7 @@ public class LibraryLoader {
}
// Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code
- private static void loadAlreadyLocked() throws ProcessInitException {
+ private static void loadAlreadyLocked(Context context) throws ProcessInitException {
try {
if (!sLoaded) {
assert !sInitialized;
@@ -108,7 +135,21 @@ public class LibraryLoader {
if (useChromiumLinker) {
Linker.loadLibrary(library);
} else {
- System.loadLibrary(library);
+ try {
+ System.loadLibrary(library);
+ if (context != null) {
+ LibraryLoaderHelper.deleteWorkaroundLibrariesAsynchronously(
+ context);
+ }
+ } catch (UnsatisfiedLinkError e) {
+ if (context != null
+ && LibraryLoaderHelper.tryLoadLibraryUsingWorkaround(context,
+ library)) {
+ sNativeLibraryHackWasUsed = true;
+ } else {
+ throw e;
+ }
+ }
}
}
if (useChromiumLinker) Linker.finishLibraryLoad();
@@ -154,6 +195,8 @@ public class LibraryLoader {
nativeRecordChromiumAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(),
SysUtils.isLowEndDevice());
}
+
+ nativeRecordNativeLibraryHack(sNativeLibraryHackWasUsed);
}
// Only methods needed before or during normal JNI registration are during System.OnLoad.
@@ -174,4 +217,6 @@ public class LibraryLoader {
// Get the version of the native library. This is needed so that we can check we
// have the right version before initializing the (rest of the) JNI.
private static native String nativeGetVersionNumber();
+
+ private static native void nativeRecordNativeLibraryHack(boolean usedHack);
}

Powered by Google App Engine
This is Rietveld 408576698