Merge "Always call finishBackup() if performFullBackup() succeeded" into lmp-dev

This commit is contained in:
Christopher Tate
2014-07-16 20:53:00 +00:00
committed by Android (Google) Code Review
2 changed files with 22 additions and 7 deletions

View File

@@ -331,6 +331,10 @@ public class BackupTransport {
* its datastore, if appropriate, and close the socket that had been provided in
* {@link #performFullBackup(PackageInfo, ParcelFileDescriptor)}.
*
* <p class="note">If the transport returns TRANSPORT_OK from this method, then the
* OS will always provide a matching call to {@link #finishBackup()} even if sending
* data via {@link #sendBackupData(int)} failed at some point.
*
* @param targetPackage The package whose data is to follow.
* @param socket The socket file descriptor through which the data will be provided.
* If the transport returns {@link #TRANSPORT_PACKAGE_REJECTED} here, it must still

View File

@@ -3535,19 +3535,30 @@ public class BackupManagerService extends IBackupManager.Stub {
}
} while (nRead > 0 && result == BackupTransport.TRANSPORT_OK);
// Done -- how did it turn out?
if (result == BackupTransport.TRANSPORT_OK){
result = transport.finishBackup();
} else {
Slog.w(TAG, "Error backing up " + target.packageName);
// In all cases we need to give the transport its finish callback
int finishResult = transport.finishBackup();
// If we were otherwise in a good state, now interpret the final
// result based on what finishBackup() returned. If we're in a
// failure case already, preserve that result and ignore whatever
// finishBackup() reported.
if (result == BackupTransport.TRANSPORT_OK) {
result = finishResult;
}
} else if (result == BackupTransport.TRANSPORT_PACKAGE_REJECTED) {
if (result != BackupTransport.TRANSPORT_OK) {
Slog.e(TAG, "Error " + result
+ " backing up " + target.packageName);
}
}
if (result == BackupTransport.TRANSPORT_PACKAGE_REJECTED) {
if (DEBUG) {
Slog.i(TAG, "Transport rejected backup of " + target.packageName
+ ", skipping");
}
// do nothing, clean up, and continue looping
} else {
} else if (result != BackupTransport.TRANSPORT_OK) {
if (DEBUG) {
Slog.i(TAG, "Transport failed; aborting backup");
return;