Update BackupEligibilityRules
1. Remove unused appIgnoresIncludeExcludeRules() and associated tests 2. Remove logic for enforcing full backup for apps with k/v agents and associated tests 3. Only ignore allowBackup for non-system apps in D2D and guard the behavior by target SDK Bug: 183147249 Test: atest BackupEligibilityRulesTest Change-Id: Id8b0862dae492de69c553858e27859970278d7db
This commit is contained in:
@@ -71,6 +71,14 @@ public class BackupEligibilityRules {
|
||||
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.S)
|
||||
static final long RESTRICT_ADB_BACKUP = 171032338L;
|
||||
|
||||
/**
|
||||
* When this change is enabled, {@code android:allowBackup} is ignored for apps during D2D
|
||||
* (device-to-device) migrations.
|
||||
*/
|
||||
@ChangeId
|
||||
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.S)
|
||||
static final long IGNORE_ALLOW_BACKUP_IN_D2D = 183147249L;
|
||||
|
||||
public static BackupEligibilityRules forBackup(PackageManager packageManager,
|
||||
PackageManagerInternal packageManagerInternal,
|
||||
int userId) {
|
||||
@@ -148,13 +156,15 @@ public class BackupEligibilityRules {
|
||||
* @return boolean indicating whether backup is allowed.
|
||||
*/
|
||||
public boolean isAppBackupAllowed(ApplicationInfo app) {
|
||||
boolean isSystemApp = UserHandle.isCore(app.uid);
|
||||
boolean allowBackup = (app.flags & ApplicationInfo.FLAG_ALLOW_BACKUP) != 0;
|
||||
switch (mOperationType) {
|
||||
case OperationType.MIGRATION:
|
||||
// Backup / restore of all non-system apps is force allowed during
|
||||
// device-to-device migration.
|
||||
return !isSystemApp || allowBackup;
|
||||
boolean isSystemApp = (app.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
boolean ignoreAllowBackup = !isSystemApp && CompatChanges.isChangeEnabled(
|
||||
IGNORE_ALLOW_BACKUP_IN_D2D, app.packageName, UserHandle.of(mUserId));
|
||||
return ignoreAllowBackup || allowBackup;
|
||||
case OperationType.ADB_BACKUP:
|
||||
String packageName = app.packageName;
|
||||
if (packageName == null) {
|
||||
@@ -176,7 +186,7 @@ public class BackupEligibilityRules {
|
||||
|
||||
boolean isPrivileged = (app.flags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0;
|
||||
boolean isDebuggable = (app.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
||||
if (isSystemApp || isPrivileged) {
|
||||
if (UserHandle.isCore(app.uid) || isPrivileged) {
|
||||
try {
|
||||
return mPackageManager.getProperty(PackageManager.PROPERTY_ALLOW_ADB_BACKUP,
|
||||
packageName).getBoolean();
|
||||
@@ -283,11 +293,6 @@ public class BackupEligibilityRules {
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public boolean appGetsFullBackup(PackageInfo pkg) {
|
||||
if (forceFullBackup(pkg.applicationInfo.uid, mOperationType)) {
|
||||
// If this is a migration, all non-system packages get full backup.
|
||||
return true;
|
||||
}
|
||||
|
||||
if (pkg.applicationInfo.backupAgentName != null) {
|
||||
// If it has an agent, it gets full backups only if it says so
|
||||
return (pkg.applicationInfo.flags & ApplicationInfo.FLAG_FULL_BACKUP_ONLY) != 0;
|
||||
@@ -297,15 +302,6 @@ public class BackupEligibilityRules {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean appIgnoresIncludeExcludeRules(ApplicationInfo app) {
|
||||
return forceFullBackup(app.uid, mOperationType);
|
||||
}
|
||||
|
||||
private boolean forceFullBackup(int appUid, @OperationType int operationType) {
|
||||
return operationType == OperationType.MIGRATION &&
|
||||
!UserHandle.isCore(appUid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the app is only capable of doing key/value. We say it's not if it allows full
|
||||
* backup, and it is otherwise.
|
||||
|
||||
@@ -219,6 +219,7 @@ public class BackupEligibilityRulesTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@EnableCompatChanges({BackupEligibilityRules.IGNORE_ALLOW_BACKUP_IN_D2D})
|
||||
public void appIsEligibleForBackup_backupNotAllowedAndInMigration_returnsTrue()
|
||||
throws Exception {
|
||||
ApplicationInfo applicationInfo = getApplicationInfo(Process.FIRST_APPLICATION_UID,
|
||||
@@ -235,7 +236,7 @@ public class BackupEligibilityRulesTest {
|
||||
public void appIsEligibleForBackup_backupNotAllowedForSystemAppAndInMigration_returnsFalse()
|
||||
throws Exception {
|
||||
ApplicationInfo applicationInfo = getApplicationInfo(Process.SYSTEM_UID,
|
||||
/* flags */ 0, CUSTOM_BACKUP_AGENT_NAME);
|
||||
ApplicationInfo.FLAG_SYSTEM, CUSTOM_BACKUP_AGENT_NAME);
|
||||
BackupEligibilityRules eligibilityRules = getBackupEligibilityRules(
|
||||
OperationType.MIGRATION);
|
||||
boolean isEligible = eligibilityRules.appIsEligibleForBackup(applicationInfo);
|
||||
@@ -477,34 +478,6 @@ public class BackupEligibilityRulesTest {
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appGetsFullBackup_withCustomBackupAgentAndWithoutFullBackupOnlyFlagAndInMigration_returnsTrue()
|
||||
throws Exception {
|
||||
PackageInfo packageInfo = new PackageInfo();
|
||||
packageInfo.applicationInfo = getApplicationInfo(Process.FIRST_APPLICATION_UID,
|
||||
~ApplicationInfo.FLAG_FULL_BACKUP_ONLY, CUSTOM_BACKUP_AGENT_NAME);
|
||||
|
||||
BackupEligibilityRules eligibilityRules = getBackupEligibilityRules(
|
||||
OperationType.MIGRATION);
|
||||
boolean result = eligibilityRules.appGetsFullBackup(packageInfo);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appGetsFullBackup_systemAppWithCustomBackupAgentAndWithoutFullBackupOnlyFlagAndInMigration_returnsFalse()
|
||||
throws Exception {
|
||||
PackageInfo packageInfo = new PackageInfo();
|
||||
packageInfo.applicationInfo = getApplicationInfo(Process.SYSTEM_UID,
|
||||
~ApplicationInfo.FLAG_FULL_BACKUP_ONLY, CUSTOM_BACKUP_AGENT_NAME);
|
||||
|
||||
BackupEligibilityRules eligibilityRules = getBackupEligibilityRules(
|
||||
OperationType.MIGRATION);
|
||||
boolean result = eligibilityRules.appGetsFullBackup(packageInfo);
|
||||
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appIsKeyValueOnly_noCustomBackupAgent_returnsTrue() throws Exception {
|
||||
PackageInfo packageInfo = new PackageInfo();
|
||||
@@ -542,52 +515,6 @@ public class BackupEligibilityRulesTest {
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appIgnoresIncludeExcludeRules_systemAppAndInMigration_returnsFalse() {
|
||||
ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
applicationInfo.uid = Process.SYSTEM_UID;
|
||||
|
||||
BackupEligibilityRules eligibilityRules = getBackupEligibilityRules(
|
||||
OperationType.MIGRATION);
|
||||
boolean result = eligibilityRules.appIgnoresIncludeExcludeRules(applicationInfo);
|
||||
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appIgnoresIncludeExcludeRules_systemAppInBackup_returnsFalse() {
|
||||
ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
applicationInfo.uid = Process.SYSTEM_UID;
|
||||
|
||||
BackupEligibilityRules eligibilityRules = getBackupEligibilityRules(
|
||||
OperationType.MIGRATION);
|
||||
boolean result = eligibilityRules.appIgnoresIncludeExcludeRules(applicationInfo);
|
||||
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appIgnoresIncludeExcludeRules_nonSystemAppInMigration_returnsTrue() {
|
||||
ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
applicationInfo.uid = Process.FIRST_APPLICATION_UID;
|
||||
|
||||
BackupEligibilityRules eligibilityRules = getBackupEligibilityRules(
|
||||
OperationType.MIGRATION);
|
||||
boolean result = eligibilityRules.appIgnoresIncludeExcludeRules(applicationInfo);
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appIgnoresIncludeExcludeRules_nonSystemInBackup_returnsFalse() {
|
||||
ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
applicationInfo.uid = Process.FIRST_APPLICATION_UID;
|
||||
|
||||
boolean result = mBackupEligibilityRules.appIgnoresIncludeExcludeRules(applicationInfo);
|
||||
|
||||
assertThat(result).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signaturesMatch_targetIsNull_returnsFalse() throws Exception {
|
||||
boolean result = mBackupEligibilityRules.signaturesMatch(new Signature[] {SIGNATURE_1}, null);
|
||||
|
||||
Reference in New Issue
Block a user