diff --git a/services/core/java/com/android/server/pm/Computer.java b/services/core/java/com/android/server/pm/Computer.java index 423c276091f38..a4e295b4f7df4 100644 --- a/services/core/java/com/android/server/pm/Computer.java +++ b/services/core/java/com/android/server/pm/Computer.java @@ -479,7 +479,7 @@ public interface Computer extends PackageDataSnapshot { boolean getBlockUninstallForUser(@NonNull String packageName, @UserIdInt int userId); @Nullable - String getInstallerPackageName(@NonNull String packageName); + String getInstallerPackageName(@NonNull String packageName, @UserIdInt int userId); @Nullable InstallSourceInfo getInstallSourceInfo(@NonNull String packageName); diff --git a/services/core/java/com/android/server/pm/ComputerEngine.java b/services/core/java/com/android/server/pm/ComputerEngine.java index bef87c4e55212..5d479d52d6ccd 100644 --- a/services/core/java/com/android/server/pm/ComputerEngine.java +++ b/services/core/java/com/android/server/pm/ComputerEngine.java @@ -4928,9 +4928,9 @@ public class ComputerEngine implements Computer { @Nullable @Override - public String getInstallerPackageName(@NonNull String packageName) { + public String getInstallerPackageName(@NonNull String packageName, @UserIdInt int userId) { final int callingUid = Binder.getCallingUid(); - final InstallSource installSource = getInstallSource(packageName, callingUid); + final InstallSource installSource = getInstallSource(packageName, callingUid, userId); if (installSource == null) { throw new IllegalArgumentException("Unknown package: " + packageName); } @@ -4946,7 +4946,8 @@ public class ComputerEngine implements Computer { } @Nullable - private InstallSource getInstallSource(@NonNull String packageName, int callingUid) { + private InstallSource getInstallSource(@NonNull String packageName, int callingUid, + int userId) { final PackageStateInternal ps = mSettings.getPackage(packageName); // Installer info for Apex is not stored in PackageManager @@ -4954,8 +4955,7 @@ public class ComputerEngine implements Computer { return InstallSource.EMPTY; } - if (ps == null || shouldFilterApplicationIncludingUninstalled( - ps, callingUid, UserHandle.getUserId(callingUid))) { + if (ps == null || shouldFilterApplicationIncludingUninstalled(ps, callingUid, userId)) { return null; } @@ -4972,7 +4972,7 @@ public class ComputerEngine implements Computer { String initiatingPackageName; String originatingPackageName; - final InstallSource installSource = getInstallSource(packageName, callingUid); + final InstallSource installSource = getInstallSource(packageName, callingUid, userId); if (installSource == null) { return null; } diff --git a/services/core/java/com/android/server/pm/DeletePackageHelper.java b/services/core/java/com/android/server/pm/DeletePackageHelper.java index 6d31121cea441..88a3f8e4c8c10 100644 --- a/services/core/java/com/android/server/pm/DeletePackageHelper.java +++ b/services/core/java/com/android/server/pm/DeletePackageHelper.java @@ -705,7 +705,8 @@ final class DeletePackageHelper { final int uid = Binder.getCallingUid(); if (!isOrphaned(snapshot, internalPackageName) && !allowSilentUninstall - && !isCallerAllowedToSilentlyUninstall(snapshot, uid, internalPackageName)) { + && !isCallerAllowedToSilentlyUninstall( + snapshot, uid, internalPackageName, userId)) { mPm.mHandler.post(() -> { try { final Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE); @@ -816,15 +817,15 @@ final class DeletePackageHelper { } private boolean isCallerAllowedToSilentlyUninstall(@NonNull Computer snapshot, int callingUid, - String pkgName) { + String pkgName, int userId) { if (callingUid == Process.SHELL_UID || callingUid == Process.ROOT_UID || UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) { return true; } final int callingUserId = UserHandle.getUserId(callingUid); // If the caller installed the pkgName, then allow it to silently uninstall. - if (callingUid == snapshot.getPackageUid(snapshot.getInstallerPackageName(pkgName), 0, - callingUserId)) { + if (callingUid == snapshot.getPackageUid( + snapshot.getInstallerPackageName(pkgName, userId), 0, callingUserId)) { return true; } diff --git a/services/core/java/com/android/server/pm/IPackageManagerBase.java b/services/core/java/com/android/server/pm/IPackageManagerBase.java index c70e6ad6e09df..05a0adcf0a6d2 100644 --- a/services/core/java/com/android/server/pm/IPackageManagerBase.java +++ b/services/core/java/com/android/server/pm/IPackageManagerBase.java @@ -492,7 +492,7 @@ public abstract class IPackageManagerBase extends IPackageManager.Stub { @Override @Deprecated public final String getInstallerPackageName(@NonNull String packageName) { - return snapshot().getInstallerPackageName(packageName); + return snapshot().getInstallerPackageName(packageName, UserHandle.getCallingUserId()); } @Override diff --git a/services/core/java/com/android/server/pm/PackageManagerNative.java b/services/core/java/com/android/server/pm/PackageManagerNative.java index 77d2ec970567a..d035084d8b023 100644 --- a/services/core/java/com/android/server/pm/PackageManagerNative.java +++ b/services/core/java/com/android/server/pm/PackageManagerNative.java @@ -72,12 +72,12 @@ final class PackageManagerNative extends IPackageManagerNative.Stub { @Override public String getInstallerForPackage(String packageName) throws RemoteException { final Computer snapshot = mPm.snapshotComputer(); - final String installerName = snapshot.getInstallerPackageName(packageName); + final int callingUser = UserHandle.getUserId(Binder.getCallingUid()); + final String installerName = snapshot.getInstallerPackageName(packageName, callingUser); if (!TextUtils.isEmpty(installerName)) { return installerName; } // differentiate between preload and sideload - int callingUser = UserHandle.getUserId(Binder.getCallingUid()); ApplicationInfo appInfo = snapshot.getApplicationInfo(packageName, /*flags*/ 0, /*userId*/ callingUser);