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.
This commit is contained in:
Christopher Tate
2009-06-22 16:44:51 -07:00
parent 3a31a93b8a
commit 5cbbf5652a
9 changed files with 48 additions and 22 deletions

View File

@@ -78,11 +78,16 @@ public abstract class BackupAgent extends ContextWrapper {
*
* @param data An open, read-only ParcelFileDescriptor pointing to a full snapshot
* of the application's data.
* @param appVersionCode The android:versionCode value of the application that backed
* up this particular data set. This makes it easier for an application's
* agent to distinguish among several possible older data versions when
* asked to perform the restore operation.
* @param newState An open, read/write ParcelFileDescriptor pointing to an empty
* file. The application should record the final backup state
* here after restoring its data from dataFd.
*/
public abstract void onRestore(BackupDataInput data, ParcelFileDescriptor newState)
public abstract void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState)
throws IOException;
@@ -121,13 +126,13 @@ public abstract class BackupAgent extends ContextWrapper {
}
}
public void doRestore(ParcelFileDescriptor data,
public void doRestore(ParcelFileDescriptor data, int appVersionCode,
ParcelFileDescriptor newState) throws RemoteException {
// !!! TODO - real implementation; for now just invoke the callbacks directly
Log.v(TAG, "doRestore() invoked");
BackupDataInput input = new BackupDataInput(data.getFileDescriptor());
try {
BackupAgent.this.onRestore(input, newState);
BackupAgent.this.onRestore(input, appVersionCode, newState);
} catch (IOException ex) {
Log.d(TAG, "onRestore (" + BackupAgent.this.getClass().getName() + ") threw", ex);
throw new RuntimeException(ex);

View File

@@ -53,6 +53,6 @@ public class FullBackupAgent extends BackupAgent {
}
@Override
public void onRestore(BackupDataInput data, ParcelFileDescriptor newState) {
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState) {
}
}

View File

@@ -51,9 +51,14 @@ interface IBackupAgent {
* app's backup. This is to be a <i>replacement</i> of the app's
* current data, not to be merged into it.
*
* @param appVersionCode The android:versionCode attribute of the application
* that created this data set. This can help the agent distinguish among
* various historical backup content possibilities.
*
* @param newState Read-write file, empty when onRestore() is called,
* that is to be written with the state description that holds after
* the restore has been completed.
*/
void doRestore(in ParcelFileDescriptor data, in ParcelFileDescriptor newState);
void doRestore(in ParcelFileDescriptor data, int appVersionCode,
in ParcelFileDescriptor newState);
}

View File

@@ -39,9 +39,9 @@ public class BackupHelperAgent extends BackupAgent {
}
@Override
public void onRestore(BackupDataInput data, ParcelFileDescriptor newState)
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
throws IOException {
mDispatcher.performRestore(data, newState);
mDispatcher.performRestore(data, appVersionCode, newState);
}
public BackupHelperDispatcher getDispatcher() {

View File

@@ -46,7 +46,8 @@ public class BackupHelperDispatcher {
}
}
public void performRestore(BackupDataInput input, ParcelFileDescriptor newState)
public void performRestore(BackupDataInput input, int appVersionCode,
ParcelFileDescriptor newState)
throws IOException {
boolean alreadyComplained = false;

View File

@@ -33,19 +33,19 @@ interface IBackupManager {
* Tell the system service that the caller has made changes to its
* data, and therefore needs to undergo an incremental backup pass.
*/
oneway void dataChanged(String packageName);
void dataChanged(String packageName);
/**
* Notifies the Backup Manager Service that an agent has become available. This
* method is only invoked by the Activity Manager.
*/
oneway void agentConnected(String packageName, IBinder agent);
void agentConnected(String packageName, IBinder agent);
/**
* Notify the Backup Manager Service that an agent has unexpectedly gone away.
* This method is only invoked by the Activity Manager.
*/
oneway void agentDisconnected(String packageName);
void agentDisconnected(String packageName);
/**
* Schedule an immediate backup attempt for all pending updates. This is
@@ -57,7 +57,7 @@ interface IBackupManager {
*
* <p>Callers must hold the android.permission.BACKUP permission to use this method.
*/
oneway void backupNow();
void backupNow();
/**
* Identify the currently selected transport. Callers must hold the