From 8b811f2d2ac814374c23ba39a945f4d605ae2503 Mon Sep 17 00:00:00 2001 From: Patrick Baumann Date: Tue, 30 Jun 2020 13:27:58 -0700 Subject: [PATCH] Add installerSource to packageSetting earlier This change updates the installerSource field of PackageSetting as part of commitReconciledPackage instead of updateSettings. This ensures that the package setting is more complete when added to AppsFilter. Test: atest AppEnumerationTests Fixes: 159939562 Change-Id: I62f09391078d9c1b774899b99eb188f7e3f410f1 --- .../server/pm/PackageManagerService.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 13145d00274f8..fc7f218aedc8c 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -11083,6 +11083,21 @@ public class PackageManagerService extends IPackageManager.Stub pkgSetting.forceQueryableOverride = true; } + // If this is part of a standard install, set the initiating package name, else rely on + // previous device state. + if (reconciledPkg.installArgs != null) { + InstallSource installSource = reconciledPkg.installArgs.installSource; + if (installSource.initiatingPackageName != null) { + final PackageSetting ips = mSettings.mPackages.get( + installSource.initiatingPackageName); + if (ips != null) { + installSource = installSource.setInitiatingPackageSignatures( + ips.signatures); + } + } + pkgSetting.setInstallSource(installSource); + } + // TODO(toddke): Consider a method specifically for modifying the Package object // post scan; or, moving this stuff out of the Package object since it has nothing // to do with the package on disk. @@ -16073,16 +16088,7 @@ public class PackageManagerService extends IPackageManager.Stub ps.setEnabled(COMPONENT_ENABLED_STATE_DEFAULT, userId, installerPackageName); } - if (installSource.initiatingPackageName != null) { - final PackageSetting ips = mSettings.mPackages.get( - installSource.initiatingPackageName); - if (ips != null) { - installSource = installSource.setInitiatingPackageSignatures( - ips.signatures); - } - } - ps.setInstallSource(installSource); - mSettings.addInstallerPackageNames(installSource); + mSettings.addInstallerPackageNames(ps.installSource); // When replacing an existing package, preserve the original install reason for all // users that had the package installed before. Similarly for uninstall reasons.