Update D2D logic in line with new opt-out rules

* Ignore android:fullBackupContent for apps targeting Android S+ while
  in D2D
* Update LocalTransport::getTransportFlags() to support
  FLAG_DEVICE_TO_DEVICE_TRANSFER (required for CTS testing)

Bug: 180523564
Test: atest FullBackupRulesHostSideTest
Change-Id: I115c1c76f4b0d8b486cc9f146ef630fda3ff2a03
This commit is contained in:
Ruslan Tkhakokhov
2021-02-26 10:13:51 +00:00
parent bfcab5ff65
commit 75ee2bf7f1
4 changed files with 19 additions and 13 deletions

View File

@@ -564,10 +564,6 @@ public abstract class BackupAgent extends ContextWrapper {
@VisibleForTesting
public IncludeExcludeRules getIncludeExcludeRules(FullBackup.BackupScheme backupScheme)
throws IOException, XmlPullParserException {
if (isDeviceToDeviceMigration()) {
return IncludeExcludeRules.emptyRules();
}
Map<String, Set<PathWithRequiredFlags>> manifestIncludeMap;
ArraySet<PathWithRequiredFlags> manifestExcludeSet;

View File

@@ -20,11 +20,15 @@ import static android.app.backup.BackupManager.OperationType;
import android.annotation.Nullable;
import android.annotation.StringDef;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.XmlResourceParser;
import android.os.Build;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.storage.StorageManager;
@@ -96,6 +100,14 @@ public class FullBackup {
public static final String FLAG_REQUIRED_FAKE_CLIENT_SIDE_ENCRYPTION =
"fakeClientSideEncryption";
/**
* When this change is enabled, include / exclude rules specified via
* {@code android:fullBackupContent} are ignored during D2D transfers.
*/
@ChangeId
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.S)
private static final long IGNORE_FULL_BACKUP_CONTENT_IN_D2D = 180523564L;
@StringDef({
ConfigSection.CLOUD_BACKUP,
ConfigSection.DEVICE_TRANSFER
@@ -527,7 +539,10 @@ public class FullBackup {
}
}
// TODO(b/180523564): Ignore the old config for apps targeting Android S+ during D2D.
if (operationType == OperationType.MIGRATION
&& CompatChanges.isChangeEnabled(IGNORE_FULL_BACKUP_CONTENT_IN_D2D)) {
return;
}
if (mFullBackupContent != 0) {
// Fall back to the old config.

View File

@@ -56,14 +56,6 @@ public class BackupAgentTest {
MockitoAnnotations.initMocks(this);
}
@Test
public void testGetIncludeExcludeRules_isMigration_returnsEmptyRules() throws Exception {
mBackupAgent = getAgentForOperationType(OperationType.MIGRATION);
IncludeExcludeRules rules = mBackupAgent.getIncludeExcludeRules(mBackupScheme);
assertThat(rules).isEqualTo(IncludeExcludeRules.emptyRules());
}
@Test
public void testGetIncludeExcludeRules_isNotMigration_returnsRules() throws Exception {
PathWithRequiredFlags path = new PathWithRequiredFlags("path", /* requiredFlags */ 0);

View File

@@ -162,6 +162,9 @@ public class LocalTransport extends BackupTransport {
if (mParameters.isFakeEncryptionFlag()) {
flags |= BackupAgent.FLAG_FAKE_CLIENT_SIDE_ENCRYPTION_ENABLED;
}
if (mParameters.isDeviceTransfer()) {
flags |= BackupAgent.FLAG_DEVICE_TO_DEVICE_TRANSFER;
}
return flags;
}