Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 689afe41 authored by Torne (Richard Coles)'s avatar Torne (Richard Coles)
Browse files

Remove support for the WebView stub.

The WebView stub is only used in Monochrome configurations and is no
longer required with Trichrome. Remove the special case code used to
support it in the past.

Bug: 129470358
Test: atest CtsWebkitTestCases
Change-Id: Ieb11ae6698f370a1d601459e6253fc7dbe146014
parent 67542eec
Loading
Loading
Loading
Loading
+1 −45
Original line number Diff line number Diff line
@@ -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();
@@ -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");
@@ -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;
    }
+2 −44
Original line number Diff line number Diff line
@@ -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;
@@ -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";
@@ -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.
@@ -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) {
@@ -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();