diff options
author | 2014-10-09 12:21:56 -0700 | |
---|---|---|
committer | 2014-10-10 10:49:32 -0700 | |
commit | 1e10d29bc8975ea45ca5e3bdf1936aa418161bcb (patch) | |
tree | 5335837308f4be45cab40477313534fde9001323 /java/src/com/android/inputmethod/latin/BackupAgent.java | |
parent | 6e565332df385d67d58543879f9d81263e667c06 (diff) | |
download | latinime-1e10d29bc8975ea45ca5e3bdf1936aa418161bcb.tar.gz latinime-1e10d29bc8975ea45ca5e3bdf1936aa418161bcb.tar.xz latinime-1e10d29bc8975ea45ca5e3bdf1936aa418161bcb.zip |
Don't restore device specific preferences
There are two categories of preferences:
1. That are part of the default shared preference
They were all getting backed up and restored.
Added a blacklist to not restore some of these.
e.g. current account
2. That are in a non-default shared preference file.
These are not getting backed up currently, but added a specific
local preference file for all such preferences.
Bug: 17288591
Change-Id: I2f748be971a2337543e5014434aa39313fd1e1d8
Diffstat (limited to 'java/src/com/android/inputmethod/latin/BackupAgent.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/BackupAgent.java | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/java/src/com/android/inputmethod/latin/BackupAgent.java b/java/src/com/android/inputmethod/latin/BackupAgent.java index 1f044618a..fb672e14b 100644 --- a/java/src/com/android/inputmethod/latin/BackupAgent.java +++ b/java/src/com/android/inputmethod/latin/BackupAgent.java @@ -17,15 +17,42 @@ package com.android.inputmethod.latin; import android.app.backup.BackupAgentHelper; +import android.app.backup.BackupDataInput; import android.app.backup.SharedPreferencesBackupHelper; +import android.content.SharedPreferences; +import android.os.ParcelFileDescriptor; + +import com.android.inputmethod.latin.settings.LocalSettingsConstants; + +import java.io.IOException; /** - * Backs up the Latin IME shared preferences. + * Backup/restore agent for LatinIME. + * Currently it backs up the default shared preferences. */ public final class BackupAgent extends BackupAgentHelper { + private static final String PREF_SUFFIX = "_preferences"; + @Override public void onCreate() { addHelper("shared_pref", new SharedPreferencesBackupHelper(this, - getPackageName() + "_preferences")); + getPackageName() + PREF_SUFFIX)); + } + + @Override + public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) + throws IOException { + // Let the restore operation go through + super.onRestore(data, appVersionCode, newState); + + // Remove the preferences that we don't want restored. + final SharedPreferences.Editor prefEditor = getSharedPreferences( + getPackageName() + PREF_SUFFIX, MODE_PRIVATE).edit(); + final String[] prefsToRemove = LocalSettingsConstants.PREFS_TO_SKIP_RESTORING; + for (final String key : prefsToRemove) { + prefEditor.remove(key); + } + // Flush the changes to disk. + prefEditor.commit(); } } |