Make full backup API available to apps

New methods for full backup/restore have been added to BackupAgent
(still hidden): onFullBackup() and onRestoreFile().  The former is the
entry point for a full app backup to adb/socket/etc: the app then writes
all of its files, entire, to the output.  During restore, the latter
new callback is invoked, once for each file being restored.

The full backup/restore interface does not use the previously-defined
BackupDataInput / BackupDataOutput classes, because those classes
provide an API designed for incremental key/value data structuring.
Instead, a new FullBackupDataOutput class has been introduced, through
which we restrict apps' abilities to write data during a full backup
operation to *only* writing entire on-disk files via a new BackupAgent
method called fullBackupFile().

"FullBackupAgent" exists now solely as a concrete shell class that
can be instantiated in the case of apps that do not have their own
BackupAgent implementations.

Along with the API change, responsibility for backing up the .apk
file and OBB container has been moved into the framework rather than
have the application side of the transaction do it.

Change-Id: I12849b06b1a6e4c44d080587c1e9828a52b70dae
This commit is contained in:
Christopher Tate
2011-06-24 14:58:49 -07:00
parent be87cc945b
commit 79ec80db70
18 changed files with 531 additions and 388 deletions

View File

@@ -23,7 +23,7 @@
<application android:allowClearUserData="false"
android:permission="android.permission.CONFIRM_FULL_BACKUP"
android:fullBackupAgent=".SharedStorageAgent"
android:backupAgent=".SharedStorageAgent"
android:allowBackup="false" >
</application>
</manifest>

View File

@@ -1,9 +1,10 @@
package com.android.sharedstoragebackup;
import android.app.backup.FullBackup;
import android.app.backup.FullBackupAgent;
import android.app.backup.FullBackup;
import android.app.backup.BackupDataInput;
import android.app.backup.BackupDataOutput;
import android.app.backup.FullBackupDataOutput;
import android.content.Context;
import android.os.Environment;
import android.os.ParcelFileDescriptor;
@@ -30,9 +31,11 @@ public class SharedStorageAgent extends FullBackupAgent {
}
}
/**
* Full backup of the shared-storage filesystem
*/
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
public void onFullBackup(FullBackupDataOutput output) throws IOException {
// If there are shared-storage volumes available, run the inherited directory-
// hierarchy backup process on them. By convention in the Storage Manager, the
// "primary" shared storage volume is first in the list.
@@ -43,19 +46,11 @@ public class SharedStorageAgent extends FullBackupAgent {
// shared/N/path/to/file
// The restore will then extract to the given volume
String domain = FullBackup.SHARED_PREFIX + i;
processTree(null, domain, v.getPath(), null, data);
fullBackupFileTree(null, domain, v.getPath(), null, output);
}
}
}
/**
* Incremental onRestore() implementation is not used.
*/
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
throws IOException {
}
/**
* Full restore of one file to shared storage
*/
@@ -88,6 +83,6 @@ public class SharedStorageAgent extends FullBackupAgent {
Slog.e(TAG, "Skipping data with malformed path " + relpath);
}
FullBackup.restoreToFile(data, size, type, mode, mtime, outFile, false);
FullBackup.restoreFile(data, size, type, -1, mtime, outFile);
}
}