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 9dc77fc8c006cfdb5c1c5c9d40327833f75f7cd2..0649db9e5af0a3eb69ec46545d211abe3506a32c 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,6 +42,11 @@ 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. |
+ public static boolean sNativeLibraryHack = false; |
+ |
// TODO(cjhopman): Remove this once it's unused. |
/** |
* Doesn't do anything. |
@@ -52,13 +58,14 @@ public class LibraryLoader { |
/** |
* This method blocks until the library is fully loaded and initialized. |
*/ |
- public static void ensureInitialized() throws ProcessInitException { |
+ public static void ensureInitialized(Context context, boolean isBrowserProcess) |
+ throws ProcessInitException { |
synchronized (sLock) { |
if (sInitialized) { |
// Already initialized, nothing to do. |
return; |
} |
- loadAlreadyLocked(); |
+ loadAlreadyLocked(context, isBrowserProcess); |
initializeAlreadyLocked(CommandLine.getJavaSwitchesOrNull()); |
} |
} |
@@ -81,9 +88,10 @@ public class LibraryLoader { |
* |
* @throws ProcessInitException if the native library failed to load. |
*/ |
- public static void loadNow() throws ProcessInitException { |
+ public static void loadNow(Context context, boolean isBrowserProcess) |
+ throws ProcessInitException { |
synchronized (sLock) { |
- loadAlreadyLocked(); |
+ loadAlreadyLocked(context, isBrowserProcess); |
} |
} |
@@ -103,7 +111,8 @@ public class LibraryLoader { |
// Invoke System.loadLibrary(...), triggering JNI_OnLoad in native code |
- private static void loadAlreadyLocked() throws ProcessInitException { |
+ private static void loadAlreadyLocked(Context context, boolean isBrowserProcess) |
+ throws ProcessInitException { |
try { |
if (!sLoaded) { |
assert !sInitialized; |
@@ -118,8 +127,19 @@ public class LibraryLoader { |
Log.i(TAG, "Loading: " + library); |
if (useChromiumLinker) |
Linker.loadLibrary(library); |
- else |
- System.loadLibrary(library); |
+ else { |
+ try { |
+ System.loadLibrary(library); |
+ } catch (UnsatisfiedLinkError e) { |
+ // Try to load from backup directory. |
+ if (LibraryLoaderHelper.tryLoadLibraryUsingWorkaround( |
+ context, library, isBrowserProcess)) { |
+ sNativeLibraryHack = true; |
+ } else { |
+ throw e; |
+ } |
+ } |
+ } |
} |
if (useChromiumLinker) |
Linker.finishLibraryLoad(); |
@@ -143,9 +163,11 @@ public class LibraryLoader { |
throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_WRONG_VERSION); |
} |
+ if (isBrowserProcess) { |
+ LibraryLoaderHelper.cleanupOldLibraries(context, !sNativeLibraryHack); |
+ } |
} |
- |
// Invoke base::android::LibraryLoaded in library_loader_hooks.cc |
private static void initializeAlreadyLocked(String[] initCommandLine) |
throws ProcessInitException { |