From 3fd0aaea464535b683a231bd92627056c2e02518 Mon Sep 17 00:00:00 2001 From: quh4gko8 <88831734+quh4gko8@users.noreply.github.com> Date: Wed, 13 Mar 2024 07:17:56 +0000 Subject: [PATCH] bugfix: properly acquire package state from original package This resolves the NPE crash when updating an application under the new package name that initially had the original package as package name. --- .../core/java/com/android/server/pm/InstallPackageHelper.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/pm/InstallPackageHelper.java b/services/core/java/com/android/server/pm/InstallPackageHelper.java index 3313378e1670..fa392d7c28bc 100644 --- a/services/core/java/com/android/server/pm/InstallPackageHelper.java +++ b/services/core/java/com/android/server/pm/InstallPackageHelper.java @@ -1263,7 +1263,7 @@ private void preparePackageLI(InstallRequest request) throws PrepareFailure { boolean systemApp = false; boolean replace = false; synchronized (mPm.mLock) { - final PackageSetting ps = mPm.mSettings.getPackageLPr(pkgName); + PackageSetting ps = mPm.mSettings.getPackageLPr(pkgName); // Check if installing already existing package if ((installFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) { String oldName = mPm.mSettings.getRenamedPackageLPr(pkgName); @@ -1276,6 +1276,7 @@ private void preparePackageLI(InstallRequest request) throws PrepareFailure { parsedPackage.setPackageName(oldName); pkgName = parsedPackage.getPackageName(); replace = true; + ps = mPm.mSettings.getPackageLPr(pkgName); if (DEBUG_INSTALL) { Slog.d(TAG, "Replacing existing renamed package: oldName=" + oldName + " pkgName=" + pkgName);