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

Commit dffe6733 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Improve handling of devices without a WebView."

parents 62b4cf99 ff937ac2
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -2972,8 +2972,12 @@ public class WebView extends AbsoluteLayout
            return webviewPackage;
            return webviewPackage;
        }
        }


        IWebViewUpdateService service = WebViewFactory.getUpdateService();
        if (service == null) {
            return null;
        }
        try {
        try {
            return WebViewFactory.getUpdateService().getCurrentWebViewPackage();
            return service.getCurrentWebViewPackage();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+26 −14
Original line number Original line Diff line number Diff line
@@ -51,9 +51,6 @@ public final class WebViewFactory {


    private static final String CHROMIUM_WEBVIEW_FACTORY_METHOD = "create";
    private static final String CHROMIUM_WEBVIEW_FACTORY_METHOD = "create";


    private static final String NULL_WEBVIEW_FACTORY =
            "com.android.webview.nullwebview.NullWebViewFactoryProvider";

    public static final String CHROMIUM_WEBVIEW_VMSIZE_SIZE_PROPERTY =
    public static final String CHROMIUM_WEBVIEW_VMSIZE_SIZE_PROPERTY =
            "persist.sys.webview.vmsize";
            "persist.sys.webview.vmsize";


@@ -66,6 +63,7 @@ public final class WebViewFactory {
    private static WebViewFactoryProvider sProviderInstance;
    private static WebViewFactoryProvider sProviderInstance;
    private static final Object sProviderLock = new Object();
    private static final Object sProviderLock = new Object();
    private static PackageInfo sPackageInfo;
    private static PackageInfo sPackageInfo;
    private static Boolean sWebViewSupported;


    // Error codes for loadWebViewNativeLibraryFromPackage
    // Error codes for loadWebViewNativeLibraryFromPackage
    public static final int LIBLOAD_SUCCESS = 0;
    public static final int LIBLOAD_SUCCESS = 0;
@@ -105,6 +103,16 @@ public final class WebViewFactory {
        public MissingWebViewPackageException(Exception e) { super(e); }
        public MissingWebViewPackageException(Exception e) { super(e); }
    }
    }


    private static boolean isWebViewSupported() {
        // No lock; this is a benign race as Boolean's state is final and the PackageManager call
        // will always return the same value.
        if (sWebViewSupported == null) {
            sWebViewSupported = AppGlobals.getInitialApplication().getPackageManager()
                    .hasSystemFeature(PackageManager.FEATURE_WEBVIEW);
        }
        return sWebViewSupported;
    }

    /**
    /**
     * @hide
     * @hide
     */
     */
@@ -135,6 +143,10 @@ public final class WebViewFactory {
     */
     */
    public static int loadWebViewNativeLibraryFromPackage(String packageName,
    public static int loadWebViewNativeLibraryFromPackage(String packageName,
                                                          ClassLoader clazzLoader) {
                                                          ClassLoader clazzLoader) {
        if (!isWebViewSupported()) {
            return LIBLOAD_WRONG_PACKAGE_NAME;
        }

        WebViewProviderResponse response = null;
        WebViewProviderResponse response = null;
        try {
        try {
            response = getUpdateService().waitForAndGetProvider();
            response = getUpdateService().waitForAndGetProvider();
@@ -188,6 +200,11 @@ public final class WebViewFactory {
                        "For security reasons, WebView is not allowed in privileged processes");
                        "For security reasons, WebView is not allowed in privileged processes");
            }
            }


            if (!isWebViewSupported()) {
                // Device doesn't support WebView; don't try to load it, just throw.
                throw new UnsupportedOperationException();
            }

            StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
            StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
            Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getProvider()");
            Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.getProvider()");
            try {
            try {
@@ -410,15 +427,6 @@ public final class WebViewFactory {
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
                Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
            }
            }
        } catch (MissingWebViewPackageException e) {
        } catch (MissingWebViewPackageException e) {
            // If the package doesn't exist, then try loading the null WebView instead.
            // If that succeeds, then this is a device without WebView support; if it fails then
            // swallow the failure, complain that the real WebView is missing and rethrow the
            // original exception.
            try {
                return (Class<WebViewFactoryProvider>) Class.forName(NULL_WEBVIEW_FACTORY);
            } catch (ClassNotFoundException e2) {
                // Ignore.
            }
            Log.e(LOGTAG, "Chromium WebView package does not exist", e);
            Log.e(LOGTAG, "Chromium WebView package does not exist", e);
            throw new AndroidRuntimeException(e);
            throw new AndroidRuntimeException(e);
        }
        }
@@ -483,7 +491,11 @@ public final class WebViewFactory {


    /** @hide */
    /** @hide */
    public static IWebViewUpdateService getUpdateService() {
    public static IWebViewUpdateService getUpdateService() {
        if (isWebViewSupported()) {
            return IWebViewUpdateService.Stub.asInterface(
            return IWebViewUpdateService.Stub.asInterface(
                    ServiceManager.getService(WEBVIEW_UPDATE_SERVICE_NAME));
                    ServiceManager.getService(WEBVIEW_UPDATE_SERVICE_NAME));
        } else {
            return null;
        }
    }
    }
}
}
+15 −3
Original line number Original line Diff line number Diff line
@@ -31,8 +31,12 @@ public final class WebViewUpdateService {
     * Fetch all packages that could potentially implement WebView.
     * Fetch all packages that could potentially implement WebView.
     */
     */
    public static WebViewProviderInfo[] getAllWebViewPackages() {
    public static WebViewProviderInfo[] getAllWebViewPackages() {
        IWebViewUpdateService service = getUpdateService();
        if (service == null) {
            return new WebViewProviderInfo[0];
        }
        try {
        try {
            return getUpdateService().getAllWebViewPackages();
            return service.getAllWebViewPackages();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -42,8 +46,12 @@ public final class WebViewUpdateService {
     * Fetch all packages that could potentially implement WebView and are currently valid.
     * Fetch all packages that could potentially implement WebView and are currently valid.
     */
     */
    public static WebViewProviderInfo[] getValidWebViewPackages() {
    public static WebViewProviderInfo[] getValidWebViewPackages() {
        IWebViewUpdateService service = getUpdateService();
        if (service == null) {
            return new WebViewProviderInfo[0];
        }
        try {
        try {
            return getUpdateService().getValidWebViewPackages();
            return service.getValidWebViewPackages();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -53,8 +61,12 @@ public final class WebViewUpdateService {
     * Used by DevelopmentSetting to get the name of the WebView provider currently in use.
     * Used by DevelopmentSetting to get the name of the WebView provider currently in use.
     */
     */
    public static String getCurrentWebViewPackageName() {
    public static String getCurrentWebViewPackageName() {
        IWebViewUpdateService service = getUpdateService();
        if (service == null) {
            return null;
        }
        try {
        try {
            return getUpdateService().getCurrentWebViewPackageName();
            return service.getCurrentWebViewPackageName();
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
+7 −5
Original line number Original line Diff line number Diff line
@@ -668,10 +668,12 @@ public final class SystemServer {
        traceEnd();
        traceEnd();


        // Tracks whether the updatable WebView is in a ready state and watches for update installs.
        // Tracks whether the updatable WebView is in a ready state and watches for update installs.
        if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_WEBVIEW)) {
            traceBeginAndSlog("StartWebViewUpdateService");
            traceBeginAndSlog("StartWebViewUpdateService");
            mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class);
            mWebViewUpdateService = mSystemServiceManager.startService(WebViewUpdateService.class);
            traceEnd();
            traceEnd();
        }
        }
    }


    /**
    /**
     * Starts a miscellaneous grab bag of stuff that has yet to be refactored
     * Starts a miscellaneous grab bag of stuff that has yet to be refactored
@@ -1688,10 +1690,10 @@ public final class SystemServer {
            traceEnd();
            traceEnd();


            // No dependency on Webview preparation in system server. But this should
            // No dependency on Webview preparation in system server. But this should
            // be completed before allowring 3rd party
            // be completed before allowing 3rd party
            final String WEBVIEW_PREPARATION = "WebViewFactoryPreparation";
            final String WEBVIEW_PREPARATION = "WebViewFactoryPreparation";
            Future<?> webviewPrep = null;
            Future<?> webviewPrep = null;
            if (!mOnlyCore) {
            if (!mOnlyCore && mWebViewUpdateService != null) {
                webviewPrep = SystemServerInitThreadPool.get().submit(() -> {
                webviewPrep = SystemServerInitThreadPool.get().submit(() -> {
                    Slog.i(TAG, WEBVIEW_PREPARATION);
                    Slog.i(TAG, WEBVIEW_PREPARATION);
                    TimingsTraceLog traceLog = new TimingsTraceLog(
                    TimingsTraceLog traceLog = new TimingsTraceLog(