diff options
Diffstat (limited to 'core/java/android')
-rw-r--r-- | core/java/android/backup/BackupDataOutput.java | 28 | ||||
-rw-r--r-- | core/java/android/backup/FileBackupHelper.java | 7 |
2 files changed, 19 insertions, 16 deletions
diff --git a/core/java/android/backup/BackupDataOutput.java b/core/java/android/backup/BackupDataOutput.java index 555494e..25ae15b 100644 --- a/core/java/android/backup/BackupDataOutput.java +++ b/core/java/android/backup/BackupDataOutput.java @@ -22,24 +22,30 @@ import java.io.FileDescriptor; /** @hide */ public class BackupDataOutput { - /* package */ FileDescriptor fd; + int mBackupWriter; + private Context mContext; public static final int OP_UPDATE = 1; public static final int OP_DELETE = 2; public BackupDataOutput(Context context, FileDescriptor fd) { - this.fd = fd; + mContext = context; + if (fd == null) throw new NullPointerException(); + mBackupWriter = ctor(fd); + if (mBackupWriter == 0) { + throw new RuntimeException("Native initialization failed with fd=" + fd); + } } - public void close() { - // do we close the fd? + protected void finalize() throws Throwable { + try { + dtor(mBackupWriter); + } finally { + super.finalize(); + } } - public native void flush(); - public native void write(byte[] buffer); - public native void write(int oneByte); - public native void write(byte[] buffer, int offset, int count); - - public native void writeOperation(int op); - public native void writeKey(String key); + + private native static int ctor(FileDescriptor fd); + private native static void dtor(int mBackupWriter); } diff --git a/core/java/android/backup/FileBackupHelper.java b/core/java/android/backup/FileBackupHelper.java index 05159dc..ec16eb1 100644 --- a/core/java/android/backup/FileBackupHelper.java +++ b/core/java/android/backup/FileBackupHelper.java @@ -53,15 +53,12 @@ public class FileBackupHelper { } // oldStateFd can be null FileDescriptor oldStateFd = oldState != null ? oldState.getFileDescriptor() : null; - if (data.fd == null) { - throw new NullPointerException(); - } FileDescriptor newStateFd = newState.getFileDescriptor(); if (newStateFd == null) { throw new NullPointerException(); } - int err = performBackup_native(basePath, oldStateFd, data.fd, newStateFd, files); + int err = performBackup_native(basePath, oldStateFd, data.mBackupWriter, newStateFd, files); if (err != 0) { throw new RuntimeException("Backup failed"); // TODO: more here @@ -69,5 +66,5 @@ public class FileBackupHelper { } native private static int performBackup_native(String basePath, FileDescriptor oldState, - FileDescriptor data, FileDescriptor newState, String[] files); + int data, FileDescriptor newState, String[] files); } |