From 0b930eeb61b97e19f6345435ab33b3a6e26fca04 Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A5rten=20Kongstad?= Date: Wed, 21 Feb 2018 10:43:13 +0100 Subject: [PATCH] Fix NPE in package manager when asserting overlays When a newer version of a package exists on /data, the package manager will skip scanning the outdated version on /system. This means the PackageSetting.pkg corresponding to the outdated version will be null. This will cause an NPE when asserting that an upgraded overlay is non-static (). Prevent the exception by checking for null, and, if needed, explicitly scan the outdated version of the overlay within the scope of the assertion. Bug: 78871949 Test: manual (have a pre-installed overlay, adb install a newer version, reboot) Change-Id: I74d12c913705309dbb34f837b6806bb0fef25086 --- .../com/android/server/pm/PackageManagerService.java | 17 ++++++++++++++++- 1 file changed, 16 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 af5521d036af..e7910d3c4944 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -11102,8 +11102,23 @@ public class PackageManagerService extends IPackageManager.Stub mSettings.getPackageLPr(pkg.packageName), "previous package state not present"); + // previousPkg.pkg may be null: the package will be not be scanned if the + // package manager knows there is a newer version on /data. + // TODO[b/79435695]: Find a better way to keep track of the "static" + // property for RROs instead of having to parse packages on /system + PackageParser.Package ppkg = previousPkg.pkg; + if (ppkg == null) { + try { + final PackageParser pp = new PackageParser(); + ppkg = pp.parsePackage(previousPkg.codePath, + parseFlags | PackageParser.PARSE_IS_SYSTEM_DIR); + } catch (PackageParserException e) { + Slog.w(TAG, "failed to parse " + previousPkg.codePath, e); + } + } + // Static overlays cannot be updated. - if (previousPkg.pkg.mOverlayIsStatic) { + if (ppkg != null && ppkg.mOverlayIsStatic) { throw new PackageManagerException("Overlay " + pkg.packageName + " is static and cannot be upgraded."); // Non-static overlays cannot be converted to static overlays. -- 2.11.0