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

Commit b7d5cbc0 authored by Jonathan Dixon's avatar Jonathan Dixon
Browse files

Reset the Experimental WebView property per build

In order to increase test coverage, reset to the default value everytime
the build ID changes.

Bug: 10427705
Change-Id: I75e301d26ee0ca52265c5f7fe48661787b596168
parent 435e7dfd
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -29,13 +29,18 @@ import android.util.Log;
 */
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.exp_on";
    private static final String EXPERIMENTAL_PROPERTY_DEFAULT_ON =
            "persist.sys.webview." + Build.ID;

    // Modify the persisted property name when the experiment is on-by-default, so that any user
    // setting override lives in a different property namespace.
    private static final String WEBVIEW_EXPERIMENTAL_PROPERTY = DEFAULT_TO_EXPERIMENTAL_WEBVIEW ?
    // 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";
@@ -80,8 +85,7 @@ public final class WebViewFactory {

    /** @hide */
    public static void setUseExperimentalWebView(boolean enable) {
        SystemProperties.set(WebViewFactory.WEBVIEW_EXPERIMENTAL_PROPERTY,
                enable ? "true" : "false");
        SystemProperties.set(WEBVIEW_EXPERIMENTAL_PROPERTY, enable ? "true" : "false");
        Log.i(LOGTAG, "Use Experimental WebView changed: "
                + SystemProperties.get(WebViewFactory.WEBVIEW_EXPERIMENTAL_PROPERTY, ""));
    }
@@ -92,6 +96,11 @@ public final class WebViewFactory {
            DEFAULT_TO_EXPERIMENTAL_WEBVIEW);
    }

    /** @hide */
    public static boolean isUseExperimentalWebViewSet() {
        return !SystemProperties.get(WEBVIEW_EXPERIMENTAL_PROPERTY).isEmpty();
    }

    static WebViewFactoryProvider getProvider() {
        synchronized (sProviderLock) {
            // For now the main purpose of this function (and the factory abstraction) is to keep