diff options
author | Ruslan Tkhakokhov <rthakohov@google.com> | 2021-03-19 12:45:08 +0000 |
---|---|---|
committer | Ruslan Tkhakokhov <rthakohov@google.com> | 2021-03-19 12:52:00 +0000 |
commit | bc8317cef12033ccc7425fc4cbc841e46ce2e3ae (patch) | |
tree | 58637696be1fcea6f527e9b8c10458007615394f | |
parent | ef9671de172ad6356b05f248c071bf79dacee34e (diff) |
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
2 files changed, 15 insertions, 92 deletions
diff --git a/services/backup/java/com/android/server/backup/utils/BackupEligibilityRules.java b/services/backup/java/com/android/server/backup/utils/BackupEligibilityRules.java index 002f6d7e7790..818155c6c14b 100644 --- a/services/backup/java/com/android/server/backup/utils/BackupEligibilityRules.java +++ b/services/backup/java/com/android/server/backup/utils/BackupEligibilityRules.java @@ -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. diff --git a/services/tests/servicestests/src/com/android/server/backup/utils/BackupEligibilityRulesTest.java b/services/tests/servicestests/src/com/android/server/backup/utils/BackupEligibilityRulesTest.java index 738527e1df0b..7323096121c4 100644 --- a/services/tests/servicestests/src/com/android/server/backup/utils/BackupEligibilityRulesTest.java +++ b/services/tests/servicestests/src/com/android/server/backup/utils/BackupEligibilityRulesTest.java @@ -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); @@ -478,34 +479,6 @@ public class BackupEligibilityRulesTest { } @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(); packageInfo.applicationInfo = new ApplicationInfo(); @@ -543,52 +516,6 @@ public class BackupEligibilityRulesTest { } @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); |