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

Commit 14c033c7 authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Move current WebView provider from Settings.Secure to Settings.Global

The current WebView provider is not user-specific and should therefore
be stored as a Global rather than a Secure setting.

Also do some code cleaning including a fix in WebViewProviderInfo to
always fetch up-to-date information about whether a webview
implementation package is enabled.

Bug: 27142972
Change-Id: I4d4b8fca775e97980fb5c34313be6d82472e7d33
parent eb33c0a5
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -5906,13 +5906,6 @@ public final class Settings {
        public static final String CAMERA_DOUBLE_TAP_POWER_GESTURE_DISABLED =
                "camera_double_tap_power_gesture_disabled";

        /**
         * Name of the package used as WebView provider (if unset the provider is instead determined
         * by the system).
         * @hide
         */
        public static final String WEBVIEW_PROVIDER = "webview_provider";

        /**
         * This are the settings to be backed up.
         *
@@ -6940,6 +6933,13 @@ public final class Settings {
        public static final String WEBVIEW_DATA_REDUCTION_PROXY_KEY =
                "webview_data_reduction_proxy_key";

        /**
         * Name of the package used as WebView provider (if unset the provider is instead determined
         * by the system).
         * @hide
         */
        public static final String WEBVIEW_PROVIDER = "webview_provider";

       /**
        * Whether Wifi display is enabled/disabled
        * 0=disabled. 1=enabled.
+14 −20
Original line number Diff line number Diff line
@@ -97,22 +97,12 @@ public class WebViewProviderInfo implements Parcelable {
     */
    public boolean isEnabled() {
        try {
            PackageManager pm = AppGlobals.getInitialApplication().getPackageManager();
            int enabled_state = pm.getApplicationEnabledSetting(packageName);
            switch (enabled_state) {
                case PackageManager.COMPONENT_ENABLED_STATE_ENABLED:
                    return true;
                case PackageManager.COMPONENT_ENABLED_STATE_DEFAULT:
                    ApplicationInfo applicationInfo = getPackageInfo().applicationInfo;
                    return applicationInfo.enabled;
                default:
                    return false;
            }
            // Explicitly fetch up-to-date package info here since the enabled-state of the package
            // might have changed since we last fetched its package info.
            updatePackageInfo();
            return getPackageInfo().applicationInfo.enabled;
        } catch (WebViewPackageNotFoundException e) {
            return false;
        } catch (IllegalArgumentException e) {
            // Thrown by PackageManager.getApplicationEnabledSetting if the package does not exist
            return false;
        }
    }

@@ -124,8 +114,7 @@ public class WebViewProviderInfo implements Parcelable {
        return availableByDefault;
    }

    public PackageInfo getPackageInfo() {
        if (packageInfo == null) {
    private void updatePackageInfo() {
        try {
            PackageManager pm = AppGlobals.getInitialApplication().getPackageManager();
            packageInfo = pm.getPackageInfo(packageName, PACKAGE_FLAGS);
@@ -133,6 +122,11 @@ public class WebViewProviderInfo implements Parcelable {
            throw new WebViewPackageNotFoundException(e);
        }
    }

    public PackageInfo getPackageInfo() {
        if (packageInfo == null) {
            updatePackageInfo();
        }
        return packageInfo;
    }

+6 −6
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ import android.os.Binder;
import android.os.Process;
import android.os.RemoteException;
import android.provider.Settings;
import android.provider.Settings.Secure;
import android.provider.Settings.Global;
import android.util.AndroidRuntimeException;
import android.util.Slog;
import android.webkit.IWebViewUpdateService;
@@ -90,7 +90,7 @@ public class WebViewUpdateService extends SystemService {
                    // change provider when the new version of the package is being installed).
                    if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)
                        && intent.getExtras().getBoolean(Intent.EXTRA_REPLACING)) {
                        synchronized(this) {
                        synchronized(WebViewUpdateService.this) {
                            if (mCurrentWebViewPackage == null) return;

                            String webViewPackage = "package:" + mCurrentWebViewPackage.packageName;
@@ -267,13 +267,13 @@ public class WebViewUpdateService extends SystemService {
    }

    private static String getUserChosenWebViewProvider() {
        return Settings.Secure.getString(AppGlobals.getInitialApplication().getContentResolver(),
                Settings.Secure.WEBVIEW_PROVIDER);
        return Settings.Global.getString(AppGlobals.getInitialApplication().getContentResolver(),
                Settings.Global.WEBVIEW_PROVIDER);
    }

    private void updateUserSetting(String newProviderName) {
        Settings.Secure.putString(getContext().getContentResolver(),
                Settings.Secure.WEBVIEW_PROVIDER,
        Settings.Global.putString(getContext().getContentResolver(),
                Settings.Global.WEBVIEW_PROVIDER,
                newProviderName == null ? "" : newProviderName);
    }