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

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

Issue 1710083004: Support Crazy Linker in WebAPK to load Chrome's uncompressed native libraries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 10 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 348f9969b5f48921045238e1b9578458c6ed5081..3aa559f0e3d05730a982025c7a0daea12569bce2 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
@@ -6,6 +6,7 @@ package org.chromium.base.library_loader;
import android.annotation.TargetApi;
import android.content.Context;
+import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -21,7 +22,6 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.metrics.RecordHistogram;
-import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Nullable;
@@ -259,8 +259,29 @@ public class LibraryLoader {
String zipFilePath = null;
String libFilePath = System.mapLibraryName(library);
if (Linker.isInZipFile()) {
+ SharedPreferences prefs = context.getSharedPreferences(
+ "MINT_PREFS", Context.MODE_PRIVATE);
+ String packageString = prefs.getString("CHROME_PACKAGE_PREF",
+ DEFAULT_CHROME_PACKAGE_NAME);
+ Context remoteContext = context;
+ if (mLibraryProcessType == LibraryProcessType.PROCESS_CHILD
+ && !context.getPackageName().equals(packageString)) {
+ try {
+ // Construct the context of the WebAPK host, which has native
+ // libraries that the WebAPK.
+ Log.w(TAG, "package name from context: %s",
+ context.getPackageName());
+ remoteContext =
+ context.getApplicationContext().createPackageContext(
+ packageString,
+ Context.CONTEXT_IGNORE_SECURITY
+ | Context.CONTEXT_INCLUDE_CODE);
+ } catch (NameNotFoundException e) {
+ e.printStackTrace();
+ }
+ }
// Load directly from the APK.
- zipFilePath = getLibraryApkPath(context);
+ zipFilePath = getLibraryApkPath(remoteContext);
Log.i(TAG, "Loading " + library + " from within " + zipFilePath);
} else {
// The library is in its own file.
@@ -273,35 +294,9 @@ public class LibraryLoader {
linker.finishLibraryLoad();
} else {
- // TODO(yfriedman): Extract library for Chrome to depend on when using Minted
- // APKs. This should come from that library instead of reading the same shared
- // prefs.
- String packageString =
- context.getSharedPreferences(MINT_PREFS, Context.MODE_PRIVATE)
- .getString(CHROME_PACKAGE_PREF, DEFAULT_CHROME_PACKAGE_NAME);
-
- if (mLibraryProcessType == LibraryProcessType.PROCESS_CHILD
- && !context.getPackageName().equals(packageString)) {
- Context remoteContext = null;
- try {
- Log.w(TAG, "package name from context: %s", context.getPackageName());
- remoteContext = context.getApplicationContext().createPackageContext(
- packageString,
- Context.CONTEXT_IGNORE_SECURITY | Context.CONTEXT_INCLUDE_CODE);
- } catch (NameNotFoundException e1) {
- e1.printStackTrace();
- }
- File input = new File(remoteContext.getApplicationInfo().nativeLibraryDir);
- Log.w(TAG, "load native libraries from remote context: "
- + input.getAbsolutePath());
- for (String library : NativeLibraries.LIBRARIES) {
- System.load(input.getAbsolutePath() + "/lib" + library + ".so");
- }
- } else {
- // Load libraries using the system linker.
- for (String library : NativeLibraries.LIBRARIES) {
- System.loadLibrary(library);
- }
+ // Load libraries using the system linker.
+ for (String library : NativeLibraries.LIBRARIES) {
+ System.loadLibrary(library);
}
}
@@ -342,6 +337,12 @@ public class LibraryLoader {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return appInfo.sourceDir;
}
+ // In minted runtime, getApplicationContext() of its host context returns null, since
+ // we use reflection to construct the host's context. In this case, simply
+ // return its host's sourceDir.
+ if (context.getApplicationContext() == null) {
+ return appInfo.sourceDir;
+ }
PackageInfo packageInfo = PackageUtils.getOwnPackageInfo(context);
if (packageInfo.splitNames != null) {
for (int i = 0; i < packageInfo.splitNames.length; ++i) {

Powered by Google App Engine
This is Rietveld 408576698