Pass the originating app's versionCode along with a restore set
This change amends the doRestore() / onRestore() interface to backup agents to
provide the integer android:versionCode of the app that stored the backup set.
This should help agents figure out how to handle whatever historical data set
they're handed at restore time.
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index c60f981..197404e 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -795,6 +795,16 @@
private int mToken;
private RestoreSet mImage;
+ class RestoreRequest {
+ public PackageInfo app;
+ public int storedAppVersion;
+
+ RestoreRequest(PackageInfo _app, int _version) {
+ app = _app;
+ storedAppVersion = _version;
+ }
+ }
+
PerformRestoreThread(IBackupTransport transport, int restoreSetToken) {
mTransport = transport;
mToken = restoreSetToken;
@@ -840,11 +850,13 @@
mPackageManager, allAgentApps());
PackageInfo pmApp = new PackageInfo();
pmApp.packageName = PACKAGE_MANAGER_SENTINEL;
- processOneRestore(pmApp, IBackupAgent.Stub.asInterface(pmAgent.onBind()));
+ // !!! TODO: version currently ignored when 'restoring' the PM metadata
+ processOneRestore(pmApp, 0,
+ IBackupAgent.Stub.asInterface(pmAgent.onBind()));
// build the set of apps we will attempt to restore
PackageInfo[] packages = mTransport.getAppSet(mImage.token);
- HashSet<PackageInfo> appsToRestore = new HashSet<PackageInfo>();
+ HashSet<RestoreRequest> appsToRestore = new HashSet<RestoreRequest>();
for (PackageInfo pkg: packages) {
// get the real PackageManager idea of the package
PackageInfo app = isRestorable(pkg);
@@ -858,7 +870,8 @@
+ " compatible with app version "
+ app.versionCode);
if (signaturesMatch(info.signatures, app.signatures)) {
- appsToRestore.add(app);
+ appsToRestore.add(
+ new RestoreRequest(app, info.versionCode));
} else {
Log.w(TAG, "Sig mismatch restoring "
+ app.packageName);
@@ -896,8 +909,9 @@
}
// restore each app in the queue
- void doQueuedRestores(HashSet<PackageInfo> appsToRestore) {
- for (PackageInfo app : appsToRestore) {
+ void doQueuedRestores(HashSet<RestoreRequest> appsToRestore) {
+ for (RestoreRequest req : appsToRestore) {
+ PackageInfo app = req.app;
Log.d(TAG, "starting agent for restore of " + app);
try {
@@ -908,7 +922,7 @@
IBackupAgent agent = bindToAgentSynchronous(app.applicationInfo,
IApplicationThread.BACKUP_MODE_RESTORE);
if (agent != null) {
- processOneRestore(app, agent);
+ processOneRestore(app, req.storedAppVersion, agent);
}
// unbind even on timeout, just in case
@@ -925,7 +939,7 @@
// Do the guts of a restore of one application, derived from the 'mImage'
// restore set via the 'mTransport' transport.
- void processOneRestore(PackageInfo app, IBackupAgent agent) {
+ void processOneRestore(PackageInfo app, int storedAppVersion, IBackupAgent agent) {
// !!! TODO: actually run the restore through mTransport
final String packageName = app.packageName;
@@ -961,7 +975,7 @@
boolean success = false;
try {
- agent.doRestore(backupData, newState);
+ agent.doRestore(backupData, storedAppVersion, newState);
success = true;
} catch (Exception e) {
Log.e(TAG, "Restore failed for " + packageName);