2009-07-05 20:17:13 +00:00
|
|
|
/*
|
2010-03-26 22:07:10 +00:00
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
2012-12-19 06:36:55 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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
|
2012-12-19 06:36:55 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-12-19 06:36:55 +00:00
|
|
|
*
|
2009-07-05 20:17:13 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* 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.
|
2009-07-05 20:17:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.android.inputmethod.latin;
|
|
|
|
|
2010-03-30 01:04:13 +00:00
|
|
|
import android.app.backup.BackupAgentHelper;
|
2014-10-09 19:21:56 +00:00
|
|
|
import android.app.backup.BackupDataInput;
|
2010-03-05 23:49:16 +00:00
|
|
|
import android.app.backup.SharedPreferencesBackupHelper;
|
2014-10-09 19:21:56 +00:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.ParcelFileDescriptor;
|
|
|
|
|
|
|
|
import com.android.inputmethod.latin.settings.LocalSettingsConstants;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2009-07-05 20:17:13 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-09 19:21:56 +00:00
|
|
|
* Backup/restore agent for LatinIME.
|
|
|
|
* Currently it backs up the default shared preferences.
|
2009-07-05 20:17:13 +00:00
|
|
|
*/
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class BackupAgent extends BackupAgentHelper {
|
2014-10-09 19:21:56 +00:00
|
|
|
private static final String PREF_SUFFIX = "_preferences";
|
|
|
|
|
2010-08-24 03:38:39 +00:00
|
|
|
@Override
|
2009-07-05 20:17:13 +00:00
|
|
|
public void onCreate() {
|
|
|
|
addHelper("shared_pref", new SharedPreferencesBackupHelper(this,
|
2014-10-09 19:21:56 +00:00
|
|
|
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();
|
2014-10-13 18:22:53 +00:00
|
|
|
for (final String key : LocalSettingsConstants.PREFS_TO_SKIP_RESTORING) {
|
2014-10-09 19:21:56 +00:00
|
|
|
prefEditor.remove(key);
|
|
|
|
}
|
|
|
|
// Flush the changes to disk.
|
|
|
|
prefEditor.commit();
|
2009-07-05 20:17:13 +00:00
|
|
|
}
|
|
|
|
}
|