Chromium Code Reviews| 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 |
|
Yaron
2016/02/19 22:10:19
I wonder if this might bite us elsewhere but seems
Xi Han
2016/02/24 19:09:38
Do you know when the splitSourceDirs are used?
Yaron
2016/02/25 05:32:50
It's not used. We thought we'd be using split apks
Xi Han
2016/02/25 14:55:37
Got it. We need to be more careful with dealing wi
|
| + // 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) { |