diff options
author | Ruslan Tkhakokhov <rthakohov@google.com> | 2020-01-17 15:22:18 +0000 |
---|---|---|
committer | Ruslan Tkhakokhov <rthakohov@google.com> | 2020-01-28 16:37:35 +0000 |
commit | 9e76d042ca05857e04fae0c742dc3f0242c4c560 (patch) | |
tree | 0a95f5471f4ab537f46317e396e6e226c068d2c0 /services/backup/java | |
parent | ccfe41b875d3f3a61262e3cc0c3e9408e3837917 (diff) |
Stage 'android' package in PerformUnifiedRestoreTask
Bug: 145126096
Test: atest KeyValueRestoreExclusionHostSideTest
atest PerformUnifiedRestoreTaskTest
In a KV restore after getting data from the transport, we save it into a
stage file. Then we go through the keys and do filtering: skip the keys
that should be excluded and extract the widget data into a separate
file. The rest of the data is wirtten into the file where the app's
backup agent will read it from.
However, this process is skipped for 'android' package. It was done as
an optimization before the ability to exclude keys from restore was
introduced: as 'android' backup data doesn't contain any widget info.
However, now we need to process 'android' package as well because it can
contain keys to be excluded.
Change-Id: I612f8cc9c6903c9bd257762360dadb81ed12d106
Diffstat (limited to 'services/backup/java')
-rw-r--r-- | services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java b/services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java index 16484df9f328..f90d936a5f4d 100644 --- a/services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java +++ b/services/backup/java/com/android/server/backup/restore/PerformUnifiedRestoreTask.java @@ -76,6 +76,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -697,11 +698,7 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask { mStageName = new File(backupManagerService.getDataDir(), packageName + ".stage"); mNewStateName = new File(mStateDir, packageName + ".new"); - // don't stage the 'android' package where the wallpaper data lives. this is - // an optimization: we know there's no widget data hosted/published by that - // package, and this way we avoid doing a spurious copy of MB-sized wallpaper - // data following the download. - boolean staging = !packageName.equals(PLATFORM_PACKAGE_NAME); + boolean staging = shouldStageBackupData(packageName); ParcelFileDescriptor stage; File downloadFile = (staging) ? mStageName : mBackupDataName; boolean startedAgentRestore = false; @@ -768,8 +765,7 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask { startedAgentRestore = true; mAgent.doRestoreWithExcludedKeys(mBackupData, appVersionCode, mNewState, mEphemeralOpToken, backupManagerService.getBackupManagerBinder(), - mExcludedKeys.containsKey(packageName) - ? new ArrayList<>(mExcludedKeys.get(packageName)) : null); + new ArrayList<>(getExcludedKeysForPackage(packageName))); } catch (Exception e) { Slog.e(TAG, "Unable to call app for restore: " + packageName, e); EventLog.writeEvent(EventLogTags.RESTORE_AGENT_FAILURE, @@ -785,9 +781,24 @@ public class PerformUnifiedRestoreTask implements BackupRestoreTask { } @VisibleForTesting + boolean shouldStageBackupData(String packageName) { + // Backup data is staged for 2 reasons: + // 1. We might need to exclude keys from the data before passing it to the agent + // 2. Widget metadata needs to be separated from the rest to be handled separately + // But 'android' package doesn't contain widget metadata so we want to skip staging for it + // when there are no keys to be excluded either. + return !packageName.equals(PLATFORM_PACKAGE_NAME) || + !getExcludedKeysForPackage(PLATFORM_PACKAGE_NAME).isEmpty(); + } + + private Set<String> getExcludedKeysForPackage(String packageName) { + return mExcludedKeys.getOrDefault(packageName, Collections.emptySet()); + } + + @VisibleForTesting void filterExcludedKeys(String packageName, BackupDataInput in, BackupDataOutput out) throws Exception { - Set<String> excludedKeysForPackage = mExcludedKeys.get(packageName); + Set<String> excludedKeysForPackage = getExcludedKeysForPackage(packageName); byte[] buffer = new byte[8192]; // will grow when needed while (in.readNextHeader()) { |