summaryrefslogtreecommitdiffstats
path: root/core/java/android/backup/FileBackupHelper.java
diff options
context:
space:
mode:
authorJoe Onorato <joeo@android.com>2009-06-12 11:06:24 -0700
committerJoe Onorato <joeo@android.com>2009-06-12 16:21:24 -0700
commit1cf587496fcb1d652bab9fc6792fb106b6fefaa4 (patch)
tree96e989c088b0e2fb8560d5b2e24562188a128e19 /core/java/android/backup/FileBackupHelper.java
parent6599426f74371c823fcfe570f61577262eb0df44 (diff)
downloadframeworks_base-1cf587496fcb1d652bab9fc6792fb106b6fefaa4.zip
frameworks_base-1cf587496fcb1d652bab9fc6792fb106b6fefaa4.tar.gz
frameworks_base-1cf587496fcb1d652bab9fc6792fb106b6fefaa4.tar.bz2
Add RestoreFileHelper, BackupDataInput, and add java wrappers for the methods on BackupDataOutput.
Diffstat (limited to 'core/java/android/backup/FileBackupHelper.java')
-rw-r--r--core/java/android/backup/FileBackupHelper.java43
1 files changed, 39 insertions, 4 deletions
diff --git a/core/java/android/backup/FileBackupHelper.java b/core/java/android/backup/FileBackupHelper.java
index 99051bf..ed840bb 100644
--- a/core/java/android/backup/FileBackupHelper.java
+++ b/core/java/android/backup/FileBackupHelper.java
@@ -27,21 +27,56 @@ import java.io.FileDescriptor;
public class FileBackupHelper {
private static final String TAG = "FileBackupHelper";
+ Context mContext;
+ String mKeyPrefix;
+
+ public FileBackupHelper(Context context) {
+ mContext = context;
+ }
+
+ public FileBackupHelper(Context context, String keyPrefix) {
+ mContext = context;
+ mKeyPrefix = keyPrefix;
+ }
+
/**
* Based on oldState, determine which of the files from the application's data directory
* need to be backed up, write them to the data stream, and fill in newState with the
* state as it exists now.
*/
- public static void performBackup(Context context,
- ParcelFileDescriptor oldState, BackupDataOutput data,
+ public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState, String[] files) {
- File base = context.getFilesDir();
+ // file names
+ File base = mContext.getFilesDir();
final int N = files.length;
String[] fullPaths = new String[N];
for (int i=0; i<N; i++) {
fullPaths[i] = (new File(base, files[i])).getAbsolutePath();
}
- performBackup_checked(oldState, data, newState, fullPaths, files);
+
+ // keys
+ String[] keys = makeKeys(mKeyPrefix, files);
+
+ // go
+ performBackup_checked(oldState, data, newState, fullPaths, keys);
+ }
+
+ /**
+ * If keyPrefix is not null, prepend it to each of the strings in <code>original</code>;
+ * otherwise, return original.
+ */
+ static String[] makeKeys(String keyPrefix, String[] original) {
+ if (keyPrefix != null) {
+ String[] keys;
+ final int N = original.length;
+ keys = new String[N];
+ for (int i=0; i<N; i++) {
+ keys[i] = keyPrefix + ':' + original[i];
+ }
+ return keys;
+ } else {
+ return original;
+ }
}
/**