am e2914615: Merge change 2099 into donut
Merge commit 'e29146158b6048936671decc060d398a68333fc0' * commit 'e29146158b6048936671decc060d398a68333fc0': Hook up the backup data writer, and add a utility to read the backup data files.
This commit is contained in:
committed by
The Android Open Source Project
commit
bad962bf40
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user