use of android.app.backup.BackupDataInput in project android_frameworks_base by crdroidandroid.
the class BackupDataTest method testDelete.
public void testDelete() throws IOException {
mFile = new File(mDirectory, "backup_delete_test.dat");
openForWriting();
BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
for (int i = 0; i < KEYS.length; i++) {
deleteEntity(bdo, KEYS[i]);
}
mDataFile.close();
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
int count = 0;
while (bdi.readNextHeader()) {
readAndVerifyDeletedEntity(bdi, KEYS[count]);
count++;
}
assertEquals("four deletes in this stream", KEYS.length, count);
}
use of android.app.backup.BackupDataInput in project android_frameworks_base by crdroidandroid.
the class LocalTransport method performBackup.
@Override
public int performBackup(PackageInfo packageInfo, ParcelFileDescriptor data) {
if (DEBUG) {
try {
StructStat ss = Os.fstat(data.getFileDescriptor());
Log.v(TAG, "performBackup() pkg=" + packageInfo.packageName + " size=" + ss.st_size);
} catch (ErrnoException e) {
Log.w(TAG, "Unable to stat input file in performBackup() on " + packageInfo.packageName);
}
}
File packageDir = new File(mCurrentSetIncrementalDir, packageInfo.packageName);
packageDir.mkdirs();
// Each 'record' in the restore set is kept in its own file, named by
// the record key. Wind through the data file, extracting individual
// record operations and building a set of all the updates to apply
// in this update.
BackupDataInput changeSet = new BackupDataInput(data.getFileDescriptor());
try {
int bufSize = 512;
byte[] buf = new byte[bufSize];
while (changeSet.readNextHeader()) {
String key = changeSet.getKey();
String base64Key = new String(Base64.encode(key.getBytes()));
File entityFile = new File(packageDir, base64Key);
int dataSize = changeSet.getDataSize();
if (DEBUG)
Log.v(TAG, "Got change set key=" + key + " size=" + dataSize + " key64=" + base64Key);
if (dataSize >= 0) {
if (entityFile.exists()) {
entityFile.delete();
}
FileOutputStream entity = new FileOutputStream(entityFile);
if (dataSize > bufSize) {
bufSize = dataSize;
buf = new byte[bufSize];
}
changeSet.readEntityData(buf, 0, dataSize);
if (DEBUG) {
try {
long cur = Os.lseek(data.getFileDescriptor(), 0, SEEK_CUR);
Log.v(TAG, " read entity data; new pos=" + cur);
} catch (ErrnoException e) {
Log.w(TAG, "Unable to stat input file in performBackup() on " + packageInfo.packageName);
}
}
try {
entity.write(buf, 0, dataSize);
} catch (IOException e) {
Log.e(TAG, "Unable to update key file " + entityFile.getAbsolutePath());
return TRANSPORT_ERROR;
} finally {
entity.close();
}
} else {
entityFile.delete();
}
}
return TRANSPORT_OK;
} catch (IOException e) {
// oops, something went wrong. abort the operation and return error.
Log.v(TAG, "Exception reading backup input:", e);
return TRANSPORT_ERROR;
}
}
use of android.app.backup.BackupDataInput in project android_frameworks_base by AOSPA.
the class BackupDataTest method testSingle.
public void testSingle() throws IOException {
mFile = new File(mDirectory, "backup_mixed_sinlge.dat");
openForWriting();
BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
writeEntity(bdo, KEY1, DATA1.getBytes());
mDataFile.close();
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
int count = 0;
while (bdi.readNextHeader()) {
readAndVerifyEntity(bdi, KEY1, DATA1.getBytes());
count++;
}
assertEquals("only one entity in this stream", 1, count);
}
use of android.app.backup.BackupDataInput in project android_frameworks_base by AOSPA.
the class BackupDataTest method testMixed.
public void testMixed() throws IOException {
mFile = new File(mDirectory, "backup_mixed_test.dat");
openForWriting();
BackupDataOutput bdo = new BackupDataOutput(mDataFile.getFileDescriptor());
int i = 0;
deleteEntity(bdo, KEYS[i]);
i++;
writeEntity(bdo, KEYS[i], DATA[i].getBytes());
i++;
writeEntity(bdo, KEYS[i], DATA[i].getBytes());
i++;
deleteEntity(bdo, KEYS[i]);
i++;
mDataFile.close();
openForReading();
BackupDataInput bdi = new BackupDataInput(mDataFile.getFileDescriptor());
int out = 0;
assertTrue(bdi.readNextHeader());
readAndVerifyDeletedEntity(bdi, KEYS[out]);
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyEntity(bdi, KEYS[out], DATA[out].getBytes());
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyEntity(bdi, KEYS[out], DATA[out].getBytes());
out++;
assertTrue(bdi.readNextHeader());
readAndVerifyDeletedEntity(bdi, KEYS[out]);
out++;
assertFalse("four items in this stream", bdi.readNextHeader());
}
use of android.app.backup.BackupDataInput in project platform_frameworks_base by android.
the class LocalTransport method performBackup.
@Override
public int performBackup(PackageInfo packageInfo, ParcelFileDescriptor data) {
if (DEBUG) {
try {
StructStat ss = Os.fstat(data.getFileDescriptor());
Log.v(TAG, "performBackup() pkg=" + packageInfo.packageName + " size=" + ss.st_size);
} catch (ErrnoException e) {
Log.w(TAG, "Unable to stat input file in performBackup() on " + packageInfo.packageName);
}
}
File packageDir = new File(mCurrentSetIncrementalDir, packageInfo.packageName);
packageDir.mkdirs();
// Each 'record' in the restore set is kept in its own file, named by
// the record key. Wind through the data file, extracting individual
// record operations and building a set of all the updates to apply
// in this update.
BackupDataInput changeSet = new BackupDataInput(data.getFileDescriptor());
try {
int bufSize = 512;
byte[] buf = new byte[bufSize];
while (changeSet.readNextHeader()) {
String key = changeSet.getKey();
String base64Key = new String(Base64.encode(key.getBytes()));
File entityFile = new File(packageDir, base64Key);
int dataSize = changeSet.getDataSize();
if (DEBUG)
Log.v(TAG, "Got change set key=" + key + " size=" + dataSize + " key64=" + base64Key);
if (dataSize >= 0) {
if (entityFile.exists()) {
entityFile.delete();
}
FileOutputStream entity = new FileOutputStream(entityFile);
if (dataSize > bufSize) {
bufSize = dataSize;
buf = new byte[bufSize];
}
changeSet.readEntityData(buf, 0, dataSize);
if (DEBUG) {
try {
long cur = Os.lseek(data.getFileDescriptor(), 0, SEEK_CUR);
Log.v(TAG, " read entity data; new pos=" + cur);
} catch (ErrnoException e) {
Log.w(TAG, "Unable to stat input file in performBackup() on " + packageInfo.packageName);
}
}
try {
entity.write(buf, 0, dataSize);
} catch (IOException e) {
Log.e(TAG, "Unable to update key file " + entityFile.getAbsolutePath());
return TRANSPORT_ERROR;
} finally {
entity.close();
}
} else {
entityFile.delete();
}
}
return TRANSPORT_OK;
} catch (IOException e) {
// oops, something went wrong. abort the operation and return error.
Log.v(TAG, "Exception reading backup input:", e);
return TRANSPORT_ERROR;
}
}
Aggregations