diff options
author | Joe Onorato <joeo@android.com> | 2009-06-10 17:07:15 -0700 |
---|---|---|
committer | Joe Onorato <joeo@android.com> | 2009-06-11 11:29:57 -0700 |
commit | 23ecae3bbb60c5af940f3a22170d75eb6ac05b69 (patch) | |
tree | 1138102ba856743cffd931121409a71c2bae37c3 /core/java/android/backup/FileBackupHelper.java | |
parent | 0b77453076a22569f24318d194b378b68f11a63e (diff) | |
download | frameworks_base-23ecae3bbb60c5af940f3a22170d75eb6ac05b69.zip frameworks_base-23ecae3bbb60c5af940f3a22170d75eb6ac05b69.tar.gz frameworks_base-23ecae3bbb60c5af940f3a22170d75eb6ac05b69.tar.bz2 |
Fix SharedPrefsBackupHelper so it doesn't hard code the paths to the files.
This took quite a bit of refactoring.
Diffstat (limited to 'core/java/android/backup/FileBackupHelper.java')
-rw-r--r-- | core/java/android/backup/FileBackupHelper.java | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/core/java/android/backup/FileBackupHelper.java b/core/java/android/backup/FileBackupHelper.java index ec16eb1..99051bf 100644 --- a/core/java/android/backup/FileBackupHelper.java +++ b/core/java/android/backup/FileBackupHelper.java @@ -20,6 +20,7 @@ import android.content.Context; import android.os.ParcelFileDescriptor; import android.util.Log; +import java.io.File; import java.io.FileDescriptor; /** @hide */ @@ -34,22 +35,34 @@ public class FileBackupHelper { public static void performBackup(Context context, ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState, String[] files) { - String basePath = context.getFilesDir().getAbsolutePath(); - performBackup_checked(basePath, oldState, data, newState, files); + File base = context.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); } /** * Check the parameters so the native code doens't have to throw all the exceptions * since it's easier to do that from java. */ - static void performBackup_checked(String basePath, - ParcelFileDescriptor oldState, BackupDataOutput data, - ParcelFileDescriptor newState, String[] files) { + static void performBackup_checked(ParcelFileDescriptor oldState, BackupDataOutput data, + ParcelFileDescriptor newState, String[] files, String[] keys) { if (files.length == 0) { return; } - if (basePath == null) { - throw new NullPointerException(); + // files must be all absolute paths + for (String f: files) { + if (f.charAt(0) != '/') { + throw new RuntimeException("files must have all absolute paths: " + f); + } + } + // the length of files and keys must be the same + if (files.length != keys.length) { + throw new RuntimeException("files.length=" + files.length + + " keys.length=" + keys.length); } // oldStateFd can be null FileDescriptor oldStateFd = oldState != null ? oldState.getFileDescriptor() : null; @@ -58,13 +71,14 @@ public class FileBackupHelper { throw new NullPointerException(); } - int err = performBackup_native(basePath, oldStateFd, data.mBackupWriter, newStateFd, files); + int err = performBackup_native(oldStateFd, data.mBackupWriter, newStateFd, files, keys); if (err != 0) { - throw new RuntimeException("Backup failed"); // TODO: more here + // TODO: more here + throw new RuntimeException("Backup failed 0x" + Integer.toHexString(err)); } } - native private static int performBackup_native(String basePath, FileDescriptor oldState, - int data, FileDescriptor newState, String[] files); + native private static int performBackup_native(FileDescriptor oldState, + int data, FileDescriptor newState, String[] files, String[] keys); } |