From 7b1d974d71a1c7033a56f443a39f76872789ce7b Mon Sep 17 00:00:00 2001 From: Oscar Key Date: Sat, 13 Jan 2018 17:21:49 +0000 Subject: [PATCH] Add FLAG_INCREMENTAL and FLAG_NON_INCREMENTAL to performBackup(). These indicate if backup manager passed any previous state to the backup agent when building a backup. The transport will use these to decide whether to clear any existing encryption related state for the app. I left the new flags as @hide for now. Bug: b/71792427 Test: Tested manually with a buid of GmsCore updated to process the new flag. I am attempting to write a robolectric test. Change-Id: Ica0f6f578cd7d1ad29af532a45a2ee6685c84747 --- .../android/app/backup/BackupTransport.java | 24 ++++++++++++++++++- .../backup/internal/PerformBackupTask.java | 10 +++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/core/java/android/app/backup/BackupTransport.java b/core/java/android/app/backup/BackupTransport.java index da81d19ca3cb2..3558e34304707 100644 --- a/core/java/android/app/backup/BackupTransport.java +++ b/core/java/android/app/backup/BackupTransport.java @@ -55,6 +55,22 @@ public class BackupTransport { // Transport should ignore its own moratoriums for call with this flag set. public static final int FLAG_USER_INITIATED = 1; + /** + * For key value backup, indicates that the backup data is a diff from a previous backup. The + * transport must apply this diff to an existing backup to build the new backup set. + * + * @hide + */ + public static final int FLAG_INCREMENTAL = 1 << 1; + + /** + * For key value backup, indicates that the backup data is a complete set, not a diff from a + * previous backup. The transport should clear any previous backup when storing this backup. + * + * @hide + */ + public static final int FLAG_NON_INCREMENTAL = 1 << 2; + IBackupTransport mBinderImpl = new TransportImpl(); public IBinder getBinder() { @@ -231,12 +247,18 @@ public class BackupTransport { * {@link #TRANSPORT_OK}, {@link #finishBackup} will then be called to ensure the data * is sent and recorded successfully. * + * If the backup data is a diff against the previous backup then the flag {@link + * BackupTransport#FLAG_INCREMENTAL} will be set. Otherwise, if the data is a complete backup + * set then {@link BackupTransport#FLAG_NON_INCREMENTAL} will be set. Before P neither flag will + * be set regardless of whether the backup is incremental or not. + * * @param packageInfo The identity of the application whose data is being backed up. * This specifically includes the signature list for the package. * @param inFd Descriptor of file with data that resulted from invoking the application's * BackupService.doBackup() method. This may be a pipe rather than a file on * persistent media, so it may not be seekable. - * @param flags {@link BackupTransport#FLAG_USER_INITIATED} or 0. + * @param flags a combination of {@link BackupTransport#FLAG_USER_INITIATED}, {@link + * BackupTransport#FLAG_NON_INCREMENTAL}, {@link BackupTransport#FLAG_INCREMENTAL}, or 0. * @return one of {@link BackupTransport#TRANSPORT_OK} (OK so far), * {@link BackupTransport#TRANSPORT_PACKAGE_REJECTED} (to suppress backup of this * specific package, but allow others to proceed), diff --git a/services/backup/java/com/android/server/backup/internal/PerformBackupTask.java b/services/backup/java/com/android/server/backup/internal/PerformBackupTask.java index a002334dac3bd..cd28b748aad4f 100644 --- a/services/backup/java/com/android/server/backup/internal/PerformBackupTask.java +++ b/services/backup/java/com/android/server/backup/internal/PerformBackupTask.java @@ -914,7 +914,15 @@ public class PerformBackupTask implements BackupRestoreTask { backupData = ParcelFileDescriptor.open(mBackupDataName, ParcelFileDescriptor.MODE_READ_ONLY); backupManagerService.addBackupTrace("sending data to transport"); - int flags = mUserInitiated ? BackupTransport.FLAG_USER_INITIATED : 0; + + int userInitiatedFlag = + mUserInitiated ? BackupTransport.FLAG_USER_INITIATED : 0; + int incrementalFlag = + mSavedStateName.length() == 0 + ? BackupTransport.FLAG_NON_INCREMENTAL + : BackupTransport.FLAG_INCREMENTAL; + int flags = userInitiatedFlag | incrementalFlag; + mStatus = transport.performBackup(mCurrentPackage, backupData, flags); }