summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2009-06-15 12:31:20 -0700
committerChristopher Tate <ctate@google.com>2009-06-15 12:33:51 -0700
commit8e55eac96d768a4de68a091f57487deadf6d0a87 (patch)
tree364c4575955b6d131da1920e3dd3e4f565f04b22 /core
parent2c723ee0cc9db37b61f55e53ff739ca3fe9cbe8a (diff)
downloadframeworks_base-8e55eac96d768a4de68a091f57487deadf6d0a87.zip
frameworks_base-8e55eac96d768a4de68a091f57487deadf6d0a87.tar.gz
frameworks_base-8e55eac96d768a4de68a091f57487deadf6d0a87.tar.bz2
Bring the test transport's restore code into line
It now reconstructs the backup data stream as it was originally structured, no longer assuming that its backed-up records can simply be concatenated into the destination stream.
Diffstat (limited to 'core')
-rw-r--r--core/java/com/android/internal/backup/LocalTransport.java36
1 files changed, 15 insertions, 21 deletions
diff --git a/core/java/com/android/internal/backup/LocalTransport.java b/core/java/com/android/internal/backup/LocalTransport.java
index 83182f2..f7b89f2 100644
--- a/core/java/com/android/internal/backup/LocalTransport.java
+++ b/core/java/com/android/internal/backup/LocalTransport.java
@@ -1,6 +1,7 @@
package com.android.internal.backup;
import android.backup.BackupDataInput;
+import android.backup.BackupDataOutput;
import android.backup.RestoreSet;
import android.content.Context;
import android.content.pm.PackageInfo;
@@ -147,7 +148,7 @@ public class LocalTransport extends IBackupTransport.Stub {
return packages.toArray(result);
}
- public int getRestoreData(int token, PackageInfo packageInfo, ParcelFileDescriptor output)
+ public int getRestoreData(int token, PackageInfo packageInfo, ParcelFileDescriptor outFd)
throws android.os.RemoteException {
if (DEBUG) Log.v(TAG, "getting restore data " + token + " : " + packageInfo.packageName);
// we only support one hardcoded restore set
@@ -161,28 +162,21 @@ public class LocalTransport extends IBackupTransport.Stub {
File[] blobs = packageDir.listFiles();
int err = 0;
if (blobs != null && blobs.length > 0) {
- for (File f : blobs) {
- err = copyFileToFD(f, output);
- if (err != 0) break;
+ BackupDataOutput out = new BackupDataOutput(mContext, outFd.getFileDescriptor());
+ try {
+ for (File f : blobs) {
+ FileInputStream in = new FileInputStream(f);
+ int size = (int) f.length();
+ byte[] buf = new byte[size];
+ in.read(buf);
+ out.writeEntityHeader(f.getName(), size);
+ out.writeEntityData(buf, size);
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Unable to read backup records");
+ err = -1;
}
}
-
return err;
}
-
- private int copyFileToFD(File source, ParcelFileDescriptor dest) {
- try {
- FileInputStream in = new FileInputStream(source);
- FileOutputStream out = new FileOutputStream(dest.getFileDescriptor());
- byte[] buffer = new byte[4096];
- int bytesRead;
- while ((bytesRead = in.read(buffer)) >= 0) {
- out.write(buffer, 0, bytesRead);
- }
- } catch (IOException e) {
- // something went wrong; claim failure
- return -1;
- }
- return 0;
- }
}