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

Commit 92dd5ada authored by Torne (Richard Coles)'s avatar Torne (Richard Coles)
Browse files

Resolved conflicts for merge of db931a3b to master

Change-Id: I5d71df1e2272b8fc35e5f1e0346284704b9d62ff
parents b2399f3f db931a3b
Loading
Loading
Loading
Loading
+10 −56
Original line number Diff line number Diff line
@@ -28,27 +28,7 @@ import android.util.Log;
 * @hide
 */
public final class WebViewFactory {
    private static final boolean DEFAULT_TO_EXPERIMENTAL_WEBVIEW = true;
    // REMEMBER: property names must be <= 31 chars total.
    private static final String EXPERIMENTAL_PROPERTY_DEFAULT_OFF = "persist.sys.webview.exp";
    private static final String EXPERIMENTAL_PROPERTY_DEFAULT_ON =
            "persist.sys.webview." + Build.ID;

    // Modify the persisted property name when the new webview is on-by-default, so that any user
    // setting override only lives as long as that build.
    private static final String LONG_PROPERTY_NAME = DEFAULT_TO_EXPERIMENTAL_WEBVIEW ?
            EXPERIMENTAL_PROPERTY_DEFAULT_ON : EXPERIMENTAL_PROPERTY_DEFAULT_OFF;
    private static final String WEBVIEW_EXPERIMENTAL_PROPERTY =
            LONG_PROPERTY_NAME.length() > SystemProperties.PROP_NAME_MAX ?
            LONG_PROPERTY_NAME.substring(0, SystemProperties.PROP_NAME_MAX) : LONG_PROPERTY_NAME;

    private static final String FORCE_PROVIDER_PROPERTY = "webview.force_provider";
    private static final String FORCE_PROVIDER_PROPERTY_VALUE_CHROMIUM = "chromium";
    private static final String FORCE_PROVIDER_PROPERTY_VALUE_CLASSIC = "classic";

    // Default Provider factory class name.
    // TODO: When the Chromium powered WebView is ready, it should be the default factory class.
    private static final String DEFAULT_WEBVIEW_FACTORY = "android.webkit.WebViewClassic$Factory";

    private static final String CHROMIUM_WEBVIEW_FACTORY =
            "com.android.webview.chromium.WebViewChromiumFactoryProvider";

@@ -73,38 +53,31 @@ public final class WebViewFactory {
    private static final Object sProviderLock = new Object();

    public static boolean isExperimentalWebViewAvailable() {
        try {
            // Pass false so we don't initialize the class at this point, as this will be wasted if
            // it's not enabled.
            Class.forName(CHROMIUM_WEBVIEW_FACTORY, false, WebViewFactory.class.getClassLoader());
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }
        // TODO: Remove callers of this method then remove it.
        return false;  // Hide the toggle in Developer Settings.
    }

    /** @hide */
    public static void setUseExperimentalWebView(boolean enable) {
        SystemProperties.set(WEBVIEW_EXPERIMENTAL_PROPERTY, enable ? "true" : "false");
        Log.i(LOGTAG, "Use Experimental WebView changed: "
                + SystemProperties.get(WebViewFactory.WEBVIEW_EXPERIMENTAL_PROPERTY, ""));
        // TODO: Remove callers of this method then remove it.
    }

    /** @hide */
    public static boolean useExperimentalWebView() {
        return SystemProperties.getBoolean(WEBVIEW_EXPERIMENTAL_PROPERTY,
            DEFAULT_TO_EXPERIMENTAL_WEBVIEW);
        // TODO: Remove callers of this method then remove it.
        return true;
    }

    /** @hide */
    public static boolean isUseExperimentalWebViewSet() {
        return !SystemProperties.get(WEBVIEW_EXPERIMENTAL_PROPERTY).isEmpty();
        // TODO: Remove callers of this method then remove it.
        return false;  // User has not modifed Developer Settings
    }

    static WebViewFactoryProvider getProvider() {
        synchronized (sProviderLock) {
            // For now the main purpose of this function (and the factory abstraction) is to keep
            // us honest and minimize usage of WebViewClassic internals when binding the proxy.
            // us honest and minimize usage of WebView internals when binding the proxy.
            if (sProviderInstance != null) return sProviderInstance;

            Class<WebViewFactoryProvider> providerClass;
@@ -138,26 +111,7 @@ public final class WebViewFactory {
        }
    }

    // We allow a system property to specify that we should use the experimental Chromium powered
    // WebView. This enables us to switch between implementations at runtime.
    private static boolean isExperimentalWebViewEnabled() {
        if (!isExperimentalWebViewAvailable()) return false;
        String forceProviderName = SystemProperties.get(FORCE_PROVIDER_PROPERTY);
        if (forceProviderName.isEmpty()) return useExperimentalWebView();

        Log.i(LOGTAG, String.format("Provider overridden by property: %s=%s",
                FORCE_PROVIDER_PROPERTY, forceProviderName));
        if (forceProviderName.equals(FORCE_PROVIDER_PROPERTY_VALUE_CHROMIUM)) return true;
        if (forceProviderName.equals(FORCE_PROVIDER_PROPERTY_VALUE_CLASSIC)) return false;
        Log.e(LOGTAG, String.format("Unrecognized provider: %s", forceProviderName));
        return useExperimentalWebView();
    }

    private static Class<WebViewFactoryProvider> getFactoryClass() throws ClassNotFoundException {
        if (isExperimentalWebViewEnabled()) {
        return (Class<WebViewFactoryProvider>) Class.forName(CHROMIUM_WEBVIEW_FACTORY);
        } else  {
            return (Class<WebViewFactoryProvider>) Class.forName(DEFAULT_WEBVIEW_FACTORY);
        }
    }
}