From 2121fe041378ab18d87381dbe49bf9b411ccf922 Mon Sep 17 00:00:00 2001 From: Patrick Baumann Date: Tue, 22 May 2018 15:34:38 -0700 Subject: [PATCH] Populate mPackages with system pkg even if installed is better System initialization relied on the system package living in mPackages in order to build the expectingBetter map and successfully recover in the case that we fail to scan / parse the updated APK. With this change we properly populate mPackages in this scenario. Test: manual - artificially force scan failure and reboot Change-Id: Id86b579722bdfde8d4e660da3b680b0305a1d7e2 Fixes: 79428784 Fixes: 79360948 --- .../com/android/server/pm/PackageManagerService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 2650ef0b884fb..56e11814f6921 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -8765,8 +8765,16 @@ public class PackageManagerService extends IPackageManager.Stub if (scanSystemPartition && isSystemPkgUpdated && !isSystemPkgBetter) { // The version of the application on the /system partition is less than or - // equal to the version on the /data partition. Throw an exception and use - // the application already installed on the /data partition. + // equal to the version on the /data partition. Even though the disabled system package + // is likely to be replaced by a version on the /data partition, we make assumptions + // that it's part of the mPackages collection during package manager initialization. So, + // add it to mPackages if there isn't already a package in the collection and then throw + // an exception to use the application already installed on the /data partition. + synchronized (mPackages) { + if (!mPackages.containsKey(pkg.packageName)) { + mPackages.put(pkg.packageName, pkg); + } + } throw new PackageManagerException(Log.WARN, "Package " + pkg.packageName + " at " + pkg.codePath + " ignored: updated version " + pkgSetting.versionCode + " better than this " + pkg.getLongVersionCode());