From 1e10d29bc8975ea45ca5e3bdf1936aa418161bcb Mon Sep 17 00:00:00 2001 From: Sandeep Siddhartha Date: Thu, 9 Oct 2014 12:21:56 -0700 Subject: 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 --- .../com/android/inputmethod/latin/BackupAgent.java | 31 ++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'java/src/com/android/inputmethod/latin/BackupAgent.java') 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(); } } -- cgit v1.2.3-83-g751a