This source file includes following definitions.
- JNINamespace
- ensureInitialized
- ensureInitialized
- isInitialized
- loadNow
- loadNow
- initialize
- loadAlreadyLocked
- initializeAlreadyLocked
- nativeLibraryLoaded
- nativeRecordChromiumAndroidLinkerHistogram
- nativeGetVersionNumber
- nativeRecordNativeLibraryHack
package org.chromium.base.library_loader;
import android.content.Context;
import android.os.SystemClock;
import android.util.Log;
import org.chromium.base.CommandLine;
import org.chromium.base.JNINamespace;
import org.chromium.base.SysUtils;
import org.chromium.base.TraceEvent;
@JNINamespace("base::android")
public class LibraryLoader {
private static final String TAG = "LibraryLoader";
private static final Object sLock = new Object();
private static boolean sLoaded = false;
private static boolean sInitialized = false;
private static boolean sNativeLibraryHackWasUsed = false;
public static void ensureInitialized() throws ProcessInitException {
ensureInitialized(null, false);
}
public static void ensureInitialized(
Context context, boolean shouldDeleteOldWorkaroundLibraries)
throws ProcessInitException {
synchronized (sLock) {
if (sInitialized) {
return;
}
loadAlreadyLocked(context, shouldDeleteOldWorkaroundLibraries);
initializeAlreadyLocked(CommandLine.getJavaSwitchesOrNull());
}
}
public static boolean isInitialized() {
synchronized (sLock) {
return sInitialized;
}
}
public static void loadNow() throws ProcessInitException {
loadNow(null, false);
}
public static void loadNow(Context context, boolean shouldDeleteOldWorkaroundLibraries)
throws ProcessInitException {
synchronized (sLock) {
loadAlreadyLocked(context, shouldDeleteOldWorkaroundLibraries);
}
}
public static void initialize(String[] initCommandLine) throws ProcessInitException {
synchronized (sLock) {
initializeAlreadyLocked(initCommandLine);
}
}
private static void loadAlreadyLocked(
Context context, boolean shouldDeleteOldWorkaroundLibraries)
throws ProcessInitException {
try {
if (!sLoaded) {
assert !sInitialized;
long startTime = SystemClock.uptimeMillis();
boolean useChromiumLinker = Linker.isUsed();
if (useChromiumLinker) Linker.prepareLibraryLoad();
for (String library : NativeLibraries.LIBRARIES) {
Log.i(TAG, "Loading: " + library);
if (useChromiumLinker) {
Linker.loadLibrary(library);
} else {
try {
System.loadLibrary(library);
} catch (UnsatisfiedLinkError e) {
if (context != null
&& LibraryLoaderHelper.tryLoadLibraryUsingWorkaround(context,
library)) {
sNativeLibraryHackWasUsed = true;
} else {
throw e;
}
}
}
}
if (useChromiumLinker) Linker.finishLibraryLoad();
if (context != null
&& shouldDeleteOldWorkaroundLibraries
&& !sNativeLibraryHackWasUsed) {
LibraryLoaderHelper.deleteWorkaroundLibrariesAsynchronously(
context);
}
long stopTime = SystemClock.uptimeMillis();
Log.i(TAG, String.format("Time to load native libraries: %d ms (timestamps %d-%d)",
stopTime - startTime,
startTime % 10000,
stopTime % 10000));
sLoaded = true;
}
} catch (UnsatisfiedLinkError e) {
throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_LOAD_FAILED, e);
}
Log.i(TAG, String.format(
"Expected native library version number \"%s\"," +
"actual native library version number \"%s\"",
NativeLibraries.VERSION_NUMBER,
nativeGetVersionNumber()));
if (!NativeLibraries.VERSION_NUMBER.equals(nativeGetVersionNumber())) {
throw new ProcessInitException(LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_WRONG_VERSION);
}
}
private static void initializeAlreadyLocked(String[] initCommandLine)
throws ProcessInitException {
if (sInitialized) {
return;
}
if (!nativeLibraryLoaded(initCommandLine)) {
Log.e(TAG, "error calling nativeLibraryLoaded");
throw new ProcessInitException(LoaderErrors.LOADER_ERROR_FAILED_TO_REGISTER_JNI);
}
sInitialized = true;
CommandLine.enableNativeProxy();
TraceEvent.setEnabledToMatchNative();
if (Linker.isUsed()) {
nativeRecordChromiumAndroidLinkerHistogram(Linker.loadAtFixedAddressFailed(),
SysUtils.isLowEndDevice());
}
nativeRecordNativeLibraryHack(sNativeLibraryHackWasUsed);
}
private static native boolean nativeLibraryLoaded(String[] initCommandLine);
private static native void nativeRecordChromiumAndroidLinkerHistogram(
boolean loadedAtFixedAddressFailed,
boolean isLowMemoryDevice);
private static native String nativeGetVersionNumber();
private static native void nativeRecordNativeLibraryHack(boolean usedHack);
}