Merge change 5537 into donut
* changes: Add a test for SharedPreferencesBackupHelper
This commit is contained in:
@@ -30,7 +30,7 @@ public class SharedPreferencesBackupHelper extends FileBackupHelperBase implemen
|
||||
private Context mContext;
|
||||
private String[] mPrefGroups;
|
||||
|
||||
public SharedPreferencesBackupHelper(Context context, String[] prefGroups) {
|
||||
public SharedPreferencesBackupHelper(Context context, String... prefGroups) {
|
||||
super(context);
|
||||
|
||||
mContext = context;
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.backuptest;
|
||||
|
||||
import android.backup.BackupHelperAgent;
|
||||
import android.backup.FileBackupHelper;
|
||||
import android.backup.SharedPreferencesBackupHelper;
|
||||
|
||||
public class BackupTestAgent extends BackupHelperAgent
|
||||
{
|
||||
@@ -25,6 +26,7 @@ public class BackupTestAgent extends BackupHelperAgent
|
||||
addHelper("data_files", new FileBackupHelper(this, BackupTestActivity.FILE_NAME));
|
||||
addHelper("more_data_files", new FileBackupHelper(this, "another_file.txt", "3.txt",
|
||||
"empty.txt"));
|
||||
addHelper("shared_prefs", new SharedPreferencesBackupHelper(this, "settings", "raw"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ adb shell bmgr transport 1
|
||||
adb shell "rm /data/data/com.android.backuptest/files/* ; \
|
||||
mkdir /data/data/com.android.backuptest ; \
|
||||
mkdir /data/data/com.android.backuptest/files ; \
|
||||
mkdir /data/data/com.android.backuptest/shared_prefs ; \
|
||||
echo -n \"<map><int name=\\\"pref\\\" value=\\\"1\\\" /></map>\" > /data/data/com.android.backuptest/shared_prefs/raw.xml ; \
|
||||
echo -n first file > /data/data/com.android.backuptest/files/file.txt ; \
|
||||
echo -n asdf > /data/data/com.android.backuptest/files/another_file.txt ; \
|
||||
echo -n 3 > /data/data/com.android.backuptest/files/3.txt ; \
|
||||
@@ -20,3 +22,6 @@ adb shell bmgr backup com.android.backuptest
|
||||
|
||||
# run the backup
|
||||
adb shell bmgr run
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
function check_file
|
||||
{
|
||||
data=$(adb shell cat /data/data/com.android.backuptest/files/$1)
|
||||
data=$(adb shell cat /data/data/com.android.backuptest/$1)
|
||||
if [ "$data" = "$2" ] ; then
|
||||
echo "$1 has correct value [$2]"
|
||||
else
|
||||
@@ -16,8 +16,12 @@ function check_file
|
||||
echo --- Previous files
|
||||
adb shell "ls -l /data/data/com.android.backuptest/files"
|
||||
adb shell "rm /data/data/com.android.backuptest/files/*"
|
||||
echo --- Erased files
|
||||
echo --- Previous shared_prefs
|
||||
adb shell "ls -l /data/data/com.android.backuptest/shared_prefs"
|
||||
adb shell "rm /data/data/com.android.backuptest/shared_prefs/*"
|
||||
echo --- Erased files and shared_prefs
|
||||
adb shell "ls -l /data/data/com.android.backuptest/files"
|
||||
adb shell "ls -l /data/data/com.android.backuptest/shared_prefs"
|
||||
echo ---
|
||||
|
||||
echo
|
||||
@@ -32,15 +36,18 @@ echo
|
||||
echo
|
||||
|
||||
# check the results
|
||||
check_file file.txt "first file"
|
||||
check_file another_file.txt "asdf"
|
||||
check_file 3.txt "3"
|
||||
check_file empty.txt ""
|
||||
check_file files/file.txt "first file"
|
||||
check_file files/another_file.txt "asdf"
|
||||
check_file files/3.txt "3"
|
||||
check_file files/empty.txt ""
|
||||
check_file shared_prefs/raw.xml '<map><int name="pref" value="1" /></map>'
|
||||
|
||||
echo
|
||||
echo
|
||||
echo
|
||||
echo --- Restored files
|
||||
adb shell "ls -l /data/data/com.android.backuptest/files"
|
||||
echo --- Restored shared_prefs
|
||||
adb shell "ls -l /data/data/com.android.backuptest/shared_prefs"
|
||||
echo ---
|
||||
echo
|
||||
|
||||
Reference in New Issue
Block a user