Loading core/java/android/webkit/WebViewFactory.java +1 −45 Original line number Diff line number Diff line Loading @@ -321,45 +321,6 @@ public final class WebViewFactory { } } /** * If the ApplicationInfo provided is for a stub WebView, fix up the object to include the * required values from the donor package. If the ApplicationInfo is for a full WebView, * leave it alone. Throws MissingWebViewPackageException if the donor is missing. */ private static void fixupStubApplicationInfo(ApplicationInfo ai, PackageManager pm) throws MissingWebViewPackageException { String donorPackageName = null; if (ai.metaData != null) { donorPackageName = ai.metaData.getString("com.android.webview.WebViewDonorPackage"); } if (donorPackageName != null) { PackageInfo donorPackage; try { donorPackage = pm.getPackageInfo( donorPackageName, PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.MATCH_DEBUG_TRIAGED_MISSING | PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_FACTORY_ONLY); } catch (PackageManager.NameNotFoundException e) { throw new MissingWebViewPackageException("Failed to find donor package: " + donorPackageName); } ApplicationInfo donorInfo = donorPackage.applicationInfo; // Replace the stub's code locations with the donor's. ai.sourceDir = donorInfo.sourceDir; ai.splitSourceDirs = donorInfo.splitSourceDirs; ai.nativeLibraryDir = donorInfo.nativeLibraryDir; ai.secondaryNativeLibraryDir = donorInfo.secondaryNativeLibraryDir; // Copy the donor's primary and secondary ABIs, since the stub doesn't have native code // and so they are unset. ai.primaryCpuAbi = donorInfo.primaryCpuAbi; ai.secondaryCpuAbi = donorInfo.secondaryCpuAbi; } } @UnsupportedAppUsage private static Context getWebViewContextAndSetProvider() throws MissingWebViewPackageException { Application initialApplication = AppGlobals.getInitialApplication(); Loading Loading @@ -411,7 +372,6 @@ public final class WebViewFactory { verifyPackageInfo(response.packageInfo, newPackageInfo); ApplicationInfo ai = newPackageInfo.applicationInfo; fixupStubApplicationInfo(ai, pm); Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "initialApplication.createApplicationContext"); Loading Loading @@ -494,18 +454,14 @@ public final class WebViewFactory { */ public static int onWebViewProviderChanged(PackageInfo packageInfo) { int startedRelroProcesses = 0; ApplicationInfo originalAppInfo = new ApplicationInfo(packageInfo.applicationInfo); try { fixupStubApplicationInfo(packageInfo.applicationInfo, AppGlobals.getInitialApplication().getPackageManager()); startedRelroProcesses = WebViewLibraryLoader.prepareNativeLibraries(packageInfo); } catch (Throwable t) { // Log and discard errors at this stage as we must not crash the system server. Log.e(LOGTAG, "error preparing webview native library", t); } WebViewZygote.onWebViewProviderChanged(packageInfo, originalAppInfo); WebViewZygote.onWebViewProviderChanged(packageInfo); return startedRelroProcesses; } Loading core/java/android/webkit/WebViewZygote.java +2 −44 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package android.webkit; import android.app.LoadedApk; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.os.AsyncTask; import android.os.Build; Loading @@ -29,10 +27,6 @@ import android.util.Log; import com.android.internal.annotations.GuardedBy; import java.io.File; import java.util.ArrayList; import java.util.List; /** @hide */ public class WebViewZygote { private static final String LOGTAG = "WebViewZygote"; Loading @@ -55,13 +49,6 @@ public class WebViewZygote { @GuardedBy("sLock") private static PackageInfo sPackage; /** * Original ApplicationInfo for the selected WebView package before stub fixup. This is set from * #onWebViewProviderChanged(). */ @GuardedBy("sLock") private static ApplicationInfo sPackageOriginalAppInfo; /** * Flag for whether multi-process WebView is enabled. If this is {@code false}, the zygote * will not be started. Loading Loading @@ -110,11 +97,9 @@ public class WebViewZygote { } } public static void onWebViewProviderChanged(PackageInfo packageInfo, ApplicationInfo originalAppInfo) { static void onWebViewProviderChanged(PackageInfo packageInfo) { synchronized (sLock) { sPackage = packageInfo; sPackageOriginalAppInfo = originalAppInfo; // If multi-process is not enabled, then do not start the zygote service. if (!sMultiprocessEnabled) { Loading Loading @@ -165,34 +150,7 @@ public class WebViewZygote { Process.FIRST_ISOLATED_UID, Integer.MAX_VALUE); // TODO(b/123615476) deal with user-id ranges properly ZygoteProcess.waitForConnectionToZygote(sZygote.getPrimarySocketAddress()); if (sPackageOriginalAppInfo.sourceDir.equals(sPackage.applicationInfo.sourceDir)) { // No stub WebView is involved here, so we can preload the package the "clean" way // using the ApplicationInfo. sZygote.preloadApp(sPackage.applicationInfo, abi); } else { // Legacy path to support the stub WebView. // Reuse the logic from LoadedApk to determine the correct paths and pass them to // the zygote as strings. final List<String> zipPaths = new ArrayList<>(10); final List<String> libPaths = new ArrayList<>(10); LoadedApk.makePaths(null, false, sPackage.applicationInfo, zipPaths, libPaths); final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths); final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) : TextUtils.join(File.pathSeparator, zipPaths); String libFileName = WebViewFactory.getWebViewLibrary(sPackage.applicationInfo); // 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); Log.d(LOGTAG, "Preloading package " + zip + " " + librarySearchPath); sZygote.preloadPackageForAbi(zip, librarySearchPath, libFileName, cacheKey, Build.SUPPORTED_ABIS[0]); } } catch (Exception e) { Log.e(LOGTAG, "Error connecting to webview zygote", e); stopZygoteLocked(); Loading Loading
core/java/android/webkit/WebViewFactory.java +1 −45 Original line number Diff line number Diff line Loading @@ -321,45 +321,6 @@ public final class WebViewFactory { } } /** * If the ApplicationInfo provided is for a stub WebView, fix up the object to include the * required values from the donor package. If the ApplicationInfo is for a full WebView, * leave it alone. Throws MissingWebViewPackageException if the donor is missing. */ private static void fixupStubApplicationInfo(ApplicationInfo ai, PackageManager pm) throws MissingWebViewPackageException { String donorPackageName = null; if (ai.metaData != null) { donorPackageName = ai.metaData.getString("com.android.webview.WebViewDonorPackage"); } if (donorPackageName != null) { PackageInfo donorPackage; try { donorPackage = pm.getPackageInfo( donorPackageName, PackageManager.GET_SHARED_LIBRARY_FILES | PackageManager.MATCH_DEBUG_TRIAGED_MISSING | PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_FACTORY_ONLY); } catch (PackageManager.NameNotFoundException e) { throw new MissingWebViewPackageException("Failed to find donor package: " + donorPackageName); } ApplicationInfo donorInfo = donorPackage.applicationInfo; // Replace the stub's code locations with the donor's. ai.sourceDir = donorInfo.sourceDir; ai.splitSourceDirs = donorInfo.splitSourceDirs; ai.nativeLibraryDir = donorInfo.nativeLibraryDir; ai.secondaryNativeLibraryDir = donorInfo.secondaryNativeLibraryDir; // Copy the donor's primary and secondary ABIs, since the stub doesn't have native code // and so they are unset. ai.primaryCpuAbi = donorInfo.primaryCpuAbi; ai.secondaryCpuAbi = donorInfo.secondaryCpuAbi; } } @UnsupportedAppUsage private static Context getWebViewContextAndSetProvider() throws MissingWebViewPackageException { Application initialApplication = AppGlobals.getInitialApplication(); Loading Loading @@ -411,7 +372,6 @@ public final class WebViewFactory { verifyPackageInfo(response.packageInfo, newPackageInfo); ApplicationInfo ai = newPackageInfo.applicationInfo; fixupStubApplicationInfo(ai, pm); Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "initialApplication.createApplicationContext"); Loading Loading @@ -494,18 +454,14 @@ public final class WebViewFactory { */ public static int onWebViewProviderChanged(PackageInfo packageInfo) { int startedRelroProcesses = 0; ApplicationInfo originalAppInfo = new ApplicationInfo(packageInfo.applicationInfo); try { fixupStubApplicationInfo(packageInfo.applicationInfo, AppGlobals.getInitialApplication().getPackageManager()); startedRelroProcesses = WebViewLibraryLoader.prepareNativeLibraries(packageInfo); } catch (Throwable t) { // Log and discard errors at this stage as we must not crash the system server. Log.e(LOGTAG, "error preparing webview native library", t); } WebViewZygote.onWebViewProviderChanged(packageInfo, originalAppInfo); WebViewZygote.onWebViewProviderChanged(packageInfo); return startedRelroProcesses; } Loading
core/java/android/webkit/WebViewZygote.java +2 −44 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package android.webkit; import android.app.LoadedApk; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.os.AsyncTask; import android.os.Build; Loading @@ -29,10 +27,6 @@ import android.util.Log; import com.android.internal.annotations.GuardedBy; import java.io.File; import java.util.ArrayList; import java.util.List; /** @hide */ public class WebViewZygote { private static final String LOGTAG = "WebViewZygote"; Loading @@ -55,13 +49,6 @@ public class WebViewZygote { @GuardedBy("sLock") private static PackageInfo sPackage; /** * Original ApplicationInfo for the selected WebView package before stub fixup. This is set from * #onWebViewProviderChanged(). */ @GuardedBy("sLock") private static ApplicationInfo sPackageOriginalAppInfo; /** * Flag for whether multi-process WebView is enabled. If this is {@code false}, the zygote * will not be started. Loading Loading @@ -110,11 +97,9 @@ public class WebViewZygote { } } public static void onWebViewProviderChanged(PackageInfo packageInfo, ApplicationInfo originalAppInfo) { static void onWebViewProviderChanged(PackageInfo packageInfo) { synchronized (sLock) { sPackage = packageInfo; sPackageOriginalAppInfo = originalAppInfo; // If multi-process is not enabled, then do not start the zygote service. if (!sMultiprocessEnabled) { Loading Loading @@ -165,34 +150,7 @@ public class WebViewZygote { Process.FIRST_ISOLATED_UID, Integer.MAX_VALUE); // TODO(b/123615476) deal with user-id ranges properly ZygoteProcess.waitForConnectionToZygote(sZygote.getPrimarySocketAddress()); if (sPackageOriginalAppInfo.sourceDir.equals(sPackage.applicationInfo.sourceDir)) { // No stub WebView is involved here, so we can preload the package the "clean" way // using the ApplicationInfo. sZygote.preloadApp(sPackage.applicationInfo, abi); } else { // Legacy path to support the stub WebView. // Reuse the logic from LoadedApk to determine the correct paths and pass them to // the zygote as strings. final List<String> zipPaths = new ArrayList<>(10); final List<String> libPaths = new ArrayList<>(10); LoadedApk.makePaths(null, false, sPackage.applicationInfo, zipPaths, libPaths); final String librarySearchPath = TextUtils.join(File.pathSeparator, libPaths); final String zip = (zipPaths.size() == 1) ? zipPaths.get(0) : TextUtils.join(File.pathSeparator, zipPaths); String libFileName = WebViewFactory.getWebViewLibrary(sPackage.applicationInfo); // 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); Log.d(LOGTAG, "Preloading package " + zip + " " + librarySearchPath); sZygote.preloadPackageForAbi(zip, librarySearchPath, libFileName, cacheKey, Build.SUPPORTED_ABIS[0]); } } catch (Exception e) { Log.e(LOGTAG, "Error connecting to webview zygote", e); stopZygoteLocked(); Loading