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

Commit cec65f20 authored by Danesh M's avatar Danesh M Committed by Gerrit Code Review
Browse files

SettingsBackupAgent : Filter out cm settings on restoration

Change-Id: If3281be2676a0cae0b534cb004a9a152925ea370
parent 0df7e344
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -36,8 +36,10 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.util.Log;

import com.android.internal.util.ArrayUtils;
import com.android.internal.widget.LockPatternUtils;

import cyanogenmod.providers.CMSettings;
import libcore.io.IoUtils;

import java.io.BufferedOutputStream;
@@ -883,6 +885,37 @@ public class SettingsBackupAgent extends BackupAgentHelper {
                Log.d(TAG, "Restored setting: " + destination + " : "+ key + "=" + value);
            }
        }

        restoreCMSetting(cachedEntries);
    }

    private void restoreCMSetting(Map<String, String> cachedEntries) {
        ContentValues cmSettingsValues = new ContentValues();
        ContentResolver cr = getContentResolver();
        for (String key : cachedEntries.keySet()) {
            Uri uri = null;
            if (ArrayUtils.contains(CMSettings.System.LEGACY_SYSTEM_SETTINGS, key)) {
                uri = CMSettings.System.CONTENT_URI;
            } else if (ArrayUtils.contains(CMSettings.Secure.LEGACY_SECURE_SETTINGS, key)) {
                uri = CMSettings.Secure.CONTENT_URI;
            } else if (ArrayUtils.contains(CMSettings.Global.LEGACY_GLOBAL_SETTINGS, key)) {
                uri = CMSettings.Global.CONTENT_URI;
            }
            if (uri != null) {
                String value = cachedEntries.get(key);
                cmSettingsValues.clear();
                cmSettingsValues.put(Settings.NameValueTable.NAME, key);
                cmSettingsValues.put(Settings.NameValueTable.VALUE, value);
                try {
                    cr.insert(uri, cmSettingsValues);
                    if (DEBUG) {
                        Log.d(TAG, "Restored cm setting: " + key + " : " + key + "=" + value);
                    }
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "Failed to migrate " + key + " due to " + e.toString());
                }
            }
        }
    }

    /**