Merge "Consider shared libs when precreating WebView classloader."

This commit is contained in:
Treehugger Robot
2018-02-20 21:59:54 +00:00
committed by Gerrit Code Review
3 changed files with 18 additions and 9 deletions

View File

@@ -463,7 +463,7 @@ public final class WebViewFactory {
*/
public static int onWebViewProviderChanged(PackageInfo packageInfo) {
String[] nativeLibs = null;
String originalSourceDir = packageInfo.applicationInfo.sourceDir;
ApplicationInfo originalAppInfo = new ApplicationInfo(packageInfo.applicationInfo);
try {
fixupStubApplicationInfo(packageInfo.applicationInfo,
AppGlobals.getInitialApplication().getPackageManager());
@@ -474,7 +474,7 @@ public final class WebViewFactory {
Log.e(LOGTAG, "error preparing webview native library", t);
}
WebViewZygote.onWebViewProviderChanged(packageInfo, originalSourceDir);
WebViewZygote.onWebViewProviderChanged(packageInfo, originalAppInfo);
return prepareWebViewInSystemServer(nativeLibs);
}

View File

@@ -17,6 +17,7 @@
package android.webkit;
import android.app.LoadedApk;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.os.SystemService;
@@ -68,11 +69,11 @@ public class WebViewZygote {
private static PackageInfo sPackage;
/**
* Cache key for the selected WebView package's classloader. This is set from
* Original ApplicationInfo for the selected WebView package before stub fixup. This is set from
* #onWebViewProviderChanged().
*/
@GuardedBy("sLock")
private static String sPackageCacheKey;
private static ApplicationInfo sPackageOriginalAppInfo;
/**
* Flag for whether multi-process WebView is enabled. If this is false, the zygote
@@ -126,10 +127,11 @@ public class WebViewZygote {
}
}
public static void onWebViewProviderChanged(PackageInfo packageInfo, String cacheKey) {
public static void onWebViewProviderChanged(PackageInfo packageInfo,
ApplicationInfo originalAppInfo) {
synchronized (sLock) {
sPackage = packageInfo;
sPackageCacheKey = cacheKey;
sPackageOriginalAppInfo = originalAppInfo;
// If multi-process is not enabled, then do not start the zygote service.
if (!sMultiprocessEnabled) {
@@ -218,10 +220,17 @@ public class WebViewZygote {
final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) :
TextUtils.join(File.pathSeparator, zipPaths);
// In the case where the ApplicationInfo has been modified by the stub WebView,
// we need to use the original ApplicationInfo to determine what the original classpath
// would have been to use as a cache key.
LoadedApk.makePaths(null, false, sPackageOriginalAppInfo, zipPaths, null);
final String cacheKey = (zipPaths.size() == 1) ? zipPaths.get(0) :
TextUtils.join(File.pathSeparator, zipPaths);
ZygoteProcess.waitForConnectionToZygote(WEBVIEW_ZYGOTE_SOCKET);
Log.d(LOGTAG, "Preloading package " + zip + " " + librarySearchPath);
sZygote.preloadPackageForAbi(zip, librarySearchPath, sPackageCacheKey,
sZygote.preloadPackageForAbi(zip, librarySearchPath, cacheKey,
Build.SUPPORTED_ABIS[0]);
} catch (Exception e) {
Log.e(LOGTAG, "Error connecting to " + serviceName, e);

View File

@@ -304,6 +304,6 @@ public class SystemImpl implements SystemInterface {
// flags declaring we want extra info from the package manager for webview providers
private final static int PACKAGE_FLAGS = PackageManager.GET_META_DATA
| PackageManager.GET_SIGNATURES | PackageManager.MATCH_DEBUG_TRIAGED_MISSING
| PackageManager.MATCH_ANY_USER;
| PackageManager.GET_SIGNATURES | PackageManager.GET_SHARED_LIBRARY_FILES
| PackageManager.MATCH_DEBUG_TRIAGED_MISSING | PackageManager.MATCH_ANY_USER;
}