Make IBackupTransport.finishBackup() also return an int code, since it too can
return TRANSPORT_NOT_INITIALIZED (in fact that's typically how it comes).
For consistency, make other IBackupTransport methods return int instead of
boolean, and handle accordingly.
Make initializeDevice() its own method instead of a flag on performBackup().
This will be needed when un-checking the settings box anyway, and is
conceptually unrelated to whatever happens to be the first post-initialization
backup we perform. (Note that even if the init is sent separately from the
backup operation, the server will remember that an init has been done and
will *not* return NOT_INITIALIZED for the subsequent backup.)
Fix LocalTransport accordingly (trivial changes).
Handle failures more robustly in BackupManagerService -- most notably,
doQueuedBackups() was ignoring the result code of processOneBackup(), so
a NOT_INITIALIZED error would go past unseen (at least until the next
backup pass). Keep track of error code returns more universally now.
(This includes finishBackup(), of course.)
diff --git a/core/java/com/android/internal/backup/LocalTransport.java b/core/java/com/android/internal/backup/LocalTransport.java
index 603f691f..4fc3edc 100644
--- a/core/java/com/android/internal/backup/LocalTransport.java
+++ b/core/java/com/android/internal/backup/LocalTransport.java
@@ -47,25 +47,26 @@
}
- public String transportDirName() throws RemoteException {
+ public String transportDirName() {
return TRANSPORT_DIR_NAME;
}
- public long requestBackupTime() throws RemoteException {
+ public long requestBackupTime() {
// any time is a good time for local backup
return 0;
}
- public int performBackup(PackageInfo packageInfo, ParcelFileDescriptor data,
- boolean wipeAllFirst) throws RemoteException {
+ public int initializeDevice() {
+ if (DEBUG) Log.v(TAG, "wiping all data");
+ deleteContents(mDataDir);
+ return BackupConstants.TRANSPORT_OK;
+ }
+
+ public int performBackup(PackageInfo packageInfo, ParcelFileDescriptor data) {
if (DEBUG) Log.v(TAG, "performBackup() pkg=" + packageInfo.packageName);
File packageDir = new File(mDataDir, packageInfo.packageName);
packageDir.mkdirs();
- if (wipeAllFirst) {
- if (DEBUG) Log.v(TAG, "wiping all data first");
- deleteContents(mDataDir);
- }
// Each 'record' in the restore set is kept in its own file, named by
// the record key. Wind through the data file, extracting individual
@@ -130,7 +131,7 @@
}
}
- public boolean clearBackupData(PackageInfo packageInfo) {
+ public int clearBackupData(PackageInfo packageInfo) {
if (DEBUG) Log.v(TAG, "clearBackupData() pkg=" + packageInfo.packageName);
File packageDir = new File(mDataDir, packageInfo.packageName);
@@ -138,12 +139,12 @@
f.delete();
}
packageDir.delete();
- return true;
+ return BackupConstants.TRANSPORT_OK;
}
- public boolean finishBackup() throws RemoteException {
+ public int finishBackup() {
if (DEBUG) Log.v(TAG, "finishBackup()");
- return true;
+ return BackupConstants.TRANSPORT_OK;
}
// Restore handling
@@ -154,11 +155,11 @@
return array;
}
- public boolean startRestore(long token, PackageInfo[] packages) {
+ public int startRestore(long token, PackageInfo[] packages) {
if (DEBUG) Log.v(TAG, "start restore " + token);
mRestorePackages = packages;
mRestorePackage = -1;
- return true;
+ return BackupConstants.TRANSPORT_OK;
}
public String nextRestorePackage() {
@@ -175,7 +176,7 @@
return "";
}
- public boolean getRestoreData(ParcelFileDescriptor outFd) {
+ public int getRestoreData(ParcelFileDescriptor outFd) {
if (mRestorePackages == null) throw new IllegalStateException("startRestore not called");
if (mRestorePackage < 0) throw new IllegalStateException("nextRestorePackage not called");
File packageDir = new File(mDataDir, mRestorePackages[mRestorePackage].packageName);
@@ -183,9 +184,9 @@
// The restore set is the concatenation of the individual record blobs,
// each of which is a file in the package's directory
File[] blobs = packageDir.listFiles();
- if (blobs == null) {
+ if (blobs == null) { // nextRestorePackage() ensures the dir exists, so this is an error
Log.e(TAG, "Error listing directory: " + packageDir);
- return false; // nextRestorePackage() ensures the dir exists, so this is an error
+ return BackupConstants.TRANSPORT_ERROR;
}
// We expect at least some data if the directory exists in the first place
@@ -206,10 +207,10 @@
in.close();
}
}
- return true;
+ return BackupConstants.TRANSPORT_OK;
} catch (IOException e) {
Log.e(TAG, "Unable to read backup records", e);
- return false;
+ return BackupConstants.TRANSPORT_ERROR;
}
}