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

Commit 1d0fca3b authored by Christopher Tate's avatar Christopher Tate
Browse files

Introduce legacy settings restore whitelists

On rare occasion we have settings keys that we no longer want to
back up, but which we *do* want to process at restore time for
support of legacy backup datasets.  We now have a little bit of
machinery for the idea of restore-only key whitelists, paralling
the SETTINGS_TO_BACKUP dual-purpose whitelists.

Bug 62263757
Test: manual

Change-Id: Ic32ad679bc4b5028dd52dc71e9ab5836a76307c4
parent e5ef6769
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -3972,6 +3972,15 @@ public final class Settings {
            SHOW_BATTERY_PERCENT
        };

        /**
         * Keys we no longer back up under the current schema, but want to continue to
         * process when restoring historical backup datasets.
         *
         * @hide
         */
        public static final String[] LEGACY_RESTORE_SETTINGS = {
        };

        /**
         * These are all public system settings
         *
@@ -7085,6 +7094,10 @@ public final class Settings {
            NOTIFICATION_BADGING
        };

        /** @hide */
        public static final String[] LEGACY_RESTORE_SETTINGS = {
        };

        /**
         * These entries are considered common between the personal and the managed profile,
         * since the managed profile doesn't get to change them.
@@ -10088,6 +10101,10 @@ public final class Settings {
            BLUETOOTH_ON
        };

        /** @hide */
        public static final String[] LEGACY_RESTORE_SETTINGS = {
        };

        private static final ContentProviderHolder sProviderHolder =
                new ContentProviderHolder(CONTENT_URI);

+21 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.providers.settings;

import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.app.backup.BackupAgentHelper;
import android.app.backup.BackupDataInput;
@@ -30,7 +31,6 @@ import android.net.NetworkPolicyManager;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.provider.Settings;
@@ -590,14 +590,18 @@ public class SettingsBackupAgent extends BackupAgentHelper {
            Log.i(TAG, "restoreSettings: " + contentUri);
        }

        // Figure out the white list and redirects to the global table.
        // 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;
        if (contentUri.equals(Settings.Secure.CONTENT_URI)) {
            whitelist = Settings.Secure.SETTINGS_TO_BACKUP;
            whitelist = concat(Settings.Secure.SETTINGS_TO_BACKUP,
                    Settings.Secure.LEGACY_RESTORE_SETTINGS);
        } else if (contentUri.equals(Settings.System.CONTENT_URI)) {
            whitelist = Settings.System.SETTINGS_TO_BACKUP;
            whitelist = concat(Settings.System.SETTINGS_TO_BACKUP,
                    Settings.System.LEGACY_RESTORE_SETTINGS);
        } else if (contentUri.equals(Settings.Global.CONTENT_URI)) {
            whitelist = Settings.Global.SETTINGS_TO_BACKUP;
            whitelist = concat(Settings.Global.SETTINGS_TO_BACKUP,
                    Settings.Global.LEGACY_RESTORE_SETTINGS);
        } else {
            throw new IllegalArgumentException("Unknown URI: " + contentUri);
        }
@@ -648,6 +652,18 @@ public class SettingsBackupAgent extends BackupAgentHelper {
        }
    }

    private final String[] concat(String[] first, @Nullable String[] second) {
        if (second == null || second.length == 0) {
            return first;
        }
        final int firstLen = first.length;
        final int secondLen = second.length;
        String[] both = new String[firstLen + secondLen];
        System.arraycopy(first, 0, both, 0, firstLen);
        System.arraycopy(second, 0, both, firstLen, secondLen);
        return both;
    }

    /**
     * Restores the owner info enabled and other settings in LockSettings.
     *