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

Commit 6e39b955 authored by Michal Karpinski's avatar Michal Karpinski Committed by Android (Google) Code Review
Browse files

Merge "Add restore of Settings keys to...

Merge "Add restore of Settings keys to SettingsBackupAgent.RESTORE_FROM_HIGHER_SDK_INT_SUPPORTED_KEYS"
parents c9af5b30 b52575c5
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -11178,6 +11178,15 @@ public final class Settings {
        public static final String LOCATION_GLOBAL_KILL_SWITCH =
                "location_global_kill_switch";

        /**
         * If set to 1, SettingsProvider's restoreAnyVersion="true" attribute will be ignored
         * and restoring to lower version of platform API will be skipped.
         *
         * @hide
         */
        public static final String OVERRIDE_SETTINGS_PROVIDER_RESTORE_ANY_VERSION =
                "override_settings_provider_restore_any_version";

        /**
         * Settings to backup. This is here so that it's in the same place as the settings
         * keys and easy to update.
+2 −1
Original line number Diff line number Diff line
@@ -428,7 +428,8 @@ public class SettingsBackupTest {
                    Settings.Global.ZEN_MODE,
                    Settings.Global.ZEN_MODE_CONFIG_ETAG,
                    Settings.Global.ZEN_MODE_RINGER_LEVEL,
                    Settings.Global.ZRAM_ENABLED);
                    Settings.Global.ZRAM_ENABLED,
                    Settings.Global.OVERRIDE_SETTINGS_PROVIDER_RESTORE_ANY_VERSION);

    private static final Set<String> BACKUP_BLACKLISTED_SECURE_SETTINGS =
             newHashSet(
+33 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.SettingsValidators.Validator;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.BackupUtils;
@@ -155,6 +156,9 @@ public class SettingsBackupAgent extends BackupAgentHelper {
            new ArraySet<String>(Arrays.asList(new String[] {
                KEY_NETWORK_POLICIES,
                KEY_WIFI_NEW_CONFIG,
                KEY_SYSTEM,
                KEY_SECURE,
                KEY_GLOBAL,
            }));

    private SettingsHelper mSettingsHelper;
@@ -223,6 +227,15 @@ public class SettingsBackupAgent extends BackupAgentHelper {
            Log.d(TAG, "onRestore(): appVersionCode: " + appVersionCode
                    + "; Build.VERSION.SDK_INT: " + Build.VERSION.SDK_INT);
        }

        boolean overrideRestoreAnyVersion = Settings.Global.getInt(getContentResolver(),
                Settings.Global.OVERRIDE_SETTINGS_PROVIDER_RESTORE_ANY_VERSION, 0) == 1;
        if ((appVersionCode > Build.VERSION.SDK_INT) && overrideRestoreAnyVersion) {
            Log.w(TAG, "Ignoring restore from API" + appVersionCode + " to API"
                    + Build.VERSION.SDK_INT + " due to settings flag override.");
            return;
        }

        // versionCode of com.android.providers.settings corresponds to SDK_INT
        mRestoredFromSdkInt = appVersionCode;

@@ -571,15 +584,19 @@ public class SettingsBackupAgent extends BackupAgentHelper {
        // Figure out the white list and redirects to the global table.  We restore anything
        // in either the backup whitelist or the legacy-restore whitelist for this table.
        final String[] whitelist;
        Map<String, Validator> validators = null;
        if (contentUri.equals(Settings.Secure.CONTENT_URI)) {
            whitelist = concat(Settings.Secure.SETTINGS_TO_BACKUP,
                    Settings.Secure.LEGACY_RESTORE_SETTINGS);
            validators = Settings.Secure.VALIDATORS;
        } else if (contentUri.equals(Settings.System.CONTENT_URI)) {
            whitelist = concat(Settings.System.SETTINGS_TO_BACKUP,
                    Settings.System.LEGACY_RESTORE_SETTINGS);
            validators = Settings.System.VALIDATORS;
        } else if (contentUri.equals(Settings.Global.CONTENT_URI)) {
            whitelist = concat(Settings.Global.SETTINGS_TO_BACKUP,
                    Settings.Global.LEGACY_RESTORE_SETTINGS);
            validators = Settings.Global.VALIDATORS;
        } else {
            throw new IllegalArgumentException("Unknown URI: " + contentUri);
        }
@@ -627,6 +644,13 @@ public class SettingsBackupAgent extends BackupAgentHelper {
                continue;
            }

            // only restore the settings that have valid values
            if (!isValidSettingValue(key, value, validators)) {
                Log.w(TAG, "Attempted restore of " + key + " setting, but its value didn't pass"
                        + " validation, value: " + value);
                continue;
            }

            final Uri destination = (movedToGlobal != null && movedToGlobal.contains(key))
                    ? Settings.Global.CONTENT_URI
                    : contentUri;
@@ -639,6 +663,15 @@ public class SettingsBackupAgent extends BackupAgentHelper {
        }
    }

    private boolean isValidSettingValue(String key, String value,
            Map<String, Validator> validators) {
        if (key == null || validators == null) {
            return false;
        }
        Validator validator = validators.get(key);
        return (validator != null) && validator.validate(value);
    }

    private final String[] concat(String[] first, @Nullable String[] second) {
        if (second == null || second.length == 0) {
            return first;