Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5cbbf565 authored by Christopher Tate's avatar Christopher Tate
Browse files

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.
parent 3a31a93b
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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) {
    }
}
+6 −1
Original line number Diff line number Diff line
@@ -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);
}
+2 −2
Original line number Diff line number Diff line
@@ -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() {
+2 −1
Original line number Diff line number Diff line
@@ -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;

Loading