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

Commit 66a3e014 authored by Al Sutton's avatar Al Sutton
Browse files

Move device specific settings to back up into common package.

This brings the list of device specific settings to backup into the same
package as the other lists of settings which are backed up.

Test: atest SettingsProviderTest
Change-Id: Iea4bef49c356c92773cf189e455cf608b6cdc4e6
parent 5e3e04ce
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -8240,20 +8240,6 @@ public final class Settings {
         */
        public static final String AWARE_LOCK_ENABLED = "aware_lock_enabled";
        /**
         * The settings values which should only be restored if the target device is the
         * same as the source device
         *
         * NOTE: Settings are backed up and restored in the order they appear
         *       in this array. If you have one setting depending on another,
         *       make sure that they are ordered appropriately.
         *
         * @hide
         */
        public static final String[] DEVICE_SPECIFIC_SETTINGS_TO_BACKUP = {
                DISPLAY_DENSITY_FORCED,
        };
        /**
         * Keys we no longer back up under the current schema, but want to continue to
         * process when restoring historical backup datasets.
+36 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.provider.settings.backup;

import android.provider.Settings;

/** Device specific settings list */
public class DeviceSpecificSettings {
    /**
     * The settings values which should only be restored if the target device is the
     * same as the source device
     *
     * NOTE: Settings are backed up and restored in the order they appear
     *       in this array. If you have one setting depending on another,
     *       make sure that they are ordered appropriately.
     *
     * @hide
     */
    public static final String[] DEVICE_SPECIFIC_SETTINGS_TO_BACKUP = {
            Settings.Secure.DISPLAY_DENSITY_FORCED,
    };
}
+2 −2
Original line number Diff line number Diff line
@@ -41,8 +41,8 @@ import java.util.Map;
public class SecureSettingsValidators {
    /**
     * All settings in {@link Secure.SETTINGS_TO_BACKUP} and {@link
     * Secure.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP} array *must* have a non-null validator, otherwise
     * they won't be restored.
     * DeviceSpecificSettings.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP} array *must* have a non-null
     * validator, otherwise they won't be restored.
     */
    public static final Map<String, Validator> VALIDATORS = new ArrayMap<>();

+3 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.provider.Settings;
import android.provider.settings.backup.DeviceSpecificSettings;
import android.provider.settings.backup.GlobalSettings;
import android.provider.settings.backup.SecureSettings;
import android.provider.settings.backup.SystemSettings;
@@ -641,7 +642,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {
        if (contentUri.equals(Settings.Secure.CONTENT_URI)) {
            whitelist = ArrayUtils.concatElements(String.class, SecureSettings.SETTINGS_TO_BACKUP,
                    Settings.Secure.LEGACY_RESTORE_SETTINGS,
                    Settings.Secure.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
                    DeviceSpecificSettings.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
            validators = SecureSettingsValidators.VALIDATORS;
        } else if (contentUri.equals(Settings.System.CONTENT_URI)) {
            whitelist = ArrayUtils.concatElements(String.class, SystemSettings.SETTINGS_TO_BACKUP,
@@ -1000,7 +1001,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {
                     getContentResolver()
                             .query(Settings.Secure.CONTENT_URI, PROJECTION, null, null, null)) {
            return extractRelevantValues(
                    cursor, Settings.Secure.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
                    cursor, DeviceSpecificSettings.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
        }
    }

+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.provider;

import static android.provider.settings.backup.DeviceSpecificSettings.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP;

import static com.google.android.collect.Sets.newHashSet;
import static com.google.common.truth.Truth.assertWithMessage;

@@ -750,7 +752,7 @@ public class SettingsBackupTest {
    public void secureSettingsBackedUpOrBlacklisted() {
        HashSet<String> keys = new HashSet<String>();
        Collections.addAll(keys, SecureSettings.SETTINGS_TO_BACKUP);
        Collections.addAll(keys, Settings.Secure.DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
        Collections.addAll(keys, DEVICE_SPECIFIC_SETTINGS_TO_BACKUP);
        checkSettingsBackedUpOrBlacklisted(
                getCandidateSettings(Settings.Secure.class),
                keys,