From ac3532f336c8d52cfbfd40ee247e7ec15b83a668 Mon Sep 17 00:00:00 2001 From: Dario Freni Date: Tue, 30 Apr 2019 18:58:57 +0100 Subject: Enable upgrading persistent APKs on boot. Bug: 131046856 Test: marked the NetworkStack APK as persistent, verified that without this patch: - adb install networkstack.apk fails - adb install --staged networkstack.apk fails (after reboot) with this patch: - adb install networkstack.apk fails - adb install --staged networkstack.apk succeds (after reboot) Change-Id: I346d772e1f4aed94f6faead3b6455efc4666b651 --- services/core/java/com/android/server/pm/PackageManagerService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index e08af6f3521f..bad1ca1ee2ee 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -939,6 +939,7 @@ public class PackageManagerService extends IPackageManager.Stub ComponentName mCustomResolverComponentName; boolean mResolverReplaced = false; + boolean mOkToReplacePersistentPackages = false; private final @Nullable ComponentName mIntentFilterVerifierComponent; private final @Nullable IntentFilterVerifier mIntentFilterVerifier; @@ -17324,7 +17325,8 @@ public class PackageManagerService extends IPackageManager.Stub + " target SDK " + oldTargetSdk + " does."); } // Prevent persistent apps from being updated - if ((oldPackage.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) != 0) { + if (((oldPackage.applicationInfo.flags & ApplicationInfo.FLAG_PERSISTENT) != 0) + && !mOkToReplacePersistentPackages) { throw new PrepareFailure(PackageManager.INSTALL_FAILED_INVALID_APK, "Package " + oldPackage.packageName + " is a persistent app. " + "Persistent apps are not updateable."); @@ -21505,10 +21507,12 @@ public class PackageManagerService extends IPackageManager.Stub mModuleInfoProvider.systemReady(); + mOkToReplacePersistentPackages = true; // Installer service might attempt to install some packages that have been staged for // installation on reboot. Make sure this is the last component to be call since the // installation might require other components to be ready. mInstallerService.restoreAndApplyStagedSessionIfNeeded(); + mOkToReplacePersistentPackages = false; } public void waitForAppDataPrepared() { -- cgit v1.2.3-59-g8ed1b