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

Commit 6517d885 authored by Michal Karpinski's avatar Michal Karpinski
Browse files

Make SettingsProvider able to restoreAnyVersion, but only

for supported keys

RestoreAnyVersion is supported only for K/V, as full backup
of SettingsProvider has been deprecated (b/71746093).
The supported keys whitelist only contains KEY_WIFI_NEW_CONFIG
and KEY_NETWORK_POLICIES for now, and will be extended in future CLs.

Bug: 64988620
Test: manual (P->P - master without changes to master with changes)
Test: manual (Q->P = API29 -> API28)
Test: a lot of other scenarios covered by our end-to-end tests
Change-Id: I381617b5db9a33b24d400945cffbc59db78ebbd2
parent 3c8c9c1c
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
                 android:process="system"
                 android:backupAgent="SettingsBackupAgent"
                 android:killAfterRestore="false"
                 android:restoreAnyVersion="true"
                 android:icon="@mipmap/ic_launcher_settings"
                 android:defaultToDeviceProtectedStorage="true"
                 android:directBootAware="true">
+23 −0
Original line number Diff line number Diff line
@@ -31,10 +31,12 @@ import android.net.NetworkPolicyManager;
import android.net.Uri;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.os.UserHandle;
import android.provider.Settings;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.BackupUtils;
import android.util.Log;

@@ -50,6 +52,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -147,6 +150,13 @@ public class SettingsBackupAgent extends BackupAgentHelper {
    // stored in the full-backup tarfile as well, so should not be changed.
    private static final String STAGE_FILE = "flattened-data";

    // List of keys that support restore to lower version of the SDK, introduced in Android P
    private static final ArraySet<String> RESTORE_FROM_HIGHER_SDK_INT_SUPPORTED_KEYS =
            new ArraySet<String>(Arrays.asList(new String[] {
                KEY_NETWORK_POLICIES,
                KEY_WIFI_NEW_CONFIG,
            }));

    private SettingsHelper mSettingsHelper;

    private WifiManager mWifiManager;
@@ -209,6 +219,10 @@ public class SettingsBackupAgent extends BackupAgentHelper {
    public void onRestore(BackupDataInput data, int appVersionCode,
            ParcelFileDescriptor newState) throws IOException {

        if (DEBUG) {
            Log.d(TAG, "onRestore(): appVersionCode: " + appVersionCode
                    + "; Build.VERSION.SDK_INT: " + Build.VERSION.SDK_INT);
        }
        // versionCode of com.android.providers.settings corresponds to SDK_INT
        mRestoredFromSdkInt = appVersionCode;

@@ -221,6 +235,15 @@ public class SettingsBackupAgent extends BackupAgentHelper {
        while (data.readNextHeader()) {
            final String key = data.getKey();
            final int size = data.getDataSize();

            // bail out of restoring from higher SDK_INT version for unsupported keys
            if (appVersionCode > Build.VERSION.SDK_INT
                    && !RESTORE_FROM_HIGHER_SDK_INT_SUPPORTED_KEYS.contains(key)) {
                Log.w(TAG, "Not restoring unrecognized key '"
                        + key + "' from future version " + appVersionCode);
                continue;
            }

            switch (key) {
                case KEY_SYSTEM :
                    restoreSettings(data, Settings.System.CONTENT_URI, movedToGlobal);