From c64fd264199004fe816c7276f9fa1519d976dd87 Mon Sep 17 00:00:00 2001 From: Ruslan Tkhakokhov Date: Mon, 7 Sep 2020 15:49:12 +0100 Subject: [PATCH] Don't check allowBackup in PackageManager This change was first submitted in ag/12316667 and then reverted as it broke StagedInstallTest. The bug has now been fixed - we need to still check if the package != null before requesting restore for it. Below follows the original commit message. During restore at install, PackageManager checks the allowBackup flag for the package to determine whether or not to request a restore by calling BackupManager::restoreAtInstall(). The above check isn't needed because B&R code verifies package elibility before running backup / restore anyway. Furthermore, this check breaks device-to-device migrations where we ignore allowBackup flag: PackageManager doesn't know if the data is restored to the device from cloud or directrly transferred from another device. Remove the check altogether since it's not needed as described above. Bug: 160407842 Test: 1. atest PackageManagerServiceTest 2. atest StagedInstallTest 3. Manual: Run restore at install for packages with allowBackup=true/false and verify the flag is respected. Change-Id: I607fe96904663ccbe07f101eaea51d68a65785cf --- .../java/com/android/server/pm/PackageManagerService.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 9f78f0f08fd1a..93d3fd521a96a 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -14532,13 +14532,11 @@ public class PackageManagerService extends IPackageManager.Stub Log.v(TAG, "restoreAndPostInstall userId=" + userId + " package=" + res.pkg); } - // A restore should be performed at this point if (a) the install - // succeeded, (b) the operation is not an update, and (c) the new - // package has not opted out of backup participation. + // A restore should be requested at this point if (a) the install + // succeeded, (b) the operation is not an update. final boolean update = res.removedInfo != null && res.removedInfo.removedPackage != null; - boolean allowBackup = res.pkg != null && res.pkg.isAllowBackup(); - boolean doRestore = !update && allowBackup; + boolean doRestore = !update && res.pkg != null; // Set up the post-install work request bookkeeping. This will be used // and cleaned up by the post-install event handling regardless of whether