From 6b93c8a98a65b2dd5d6220209b3a00e6e2f88bb6 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Tue, 18 Aug 2020 18:44:11 +0200 Subject: [PATCH] Fix appId to killApplication when hiding packages This function takes either an appId (for all users) or appId + userId (for force stopping an app in a single user). Passing a secondary UID in the appId slot has some really bad consequences: - Framework will decide to try and force stop all packages matching this UID including killing all of the services - ActivityManagerService will successfully turn up a ServiceRecord for each instance that needs to be killed, and mark it for removal. - However the ServiceRecord will not match to a process and will not be killed. Next time we try to start a service, the process will still be running and will be reused as one would expect. This leads to zombie instances of all the Service objects in a class that continue to run, alongside any new instances that get created right after as a result of the framework thinking it killed these services and needs to restart them. Test: Manual: create a managed profile containing AtvRemoteService (app with foreground service), confirm framework hid it in user10, check logs and heap dump to confirm it's no longer running twice. Bug: 160932561 Change-Id: I5d5b2360ea0d72ca9a5c39eb6e8c0ca6a7f33540 --- .../core/java/com/android/server/pm/PackageManagerService.java | 2 +- 1 file changed, 1 insertion(+), 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 9c8b972985eb4..bda35becb8cdf 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -13092,7 +13092,7 @@ public class PackageManagerService extends IPackageManager.Stub return true; } if (sendRemoved) { - killApplication(packageName, UserHandle.getUid(userId, pkgSetting.appId), + killApplication(packageName, pkgSetting.appId, userId, "hiding pkg"); sendApplicationHiddenForUser(packageName, pkgSetting, userId); return true;