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
This commit is contained in:
Robin Lee
2020-08-18 18:44:11 +02:00
parent 3623577c19
commit 6b93c8a98a

View File

@@ -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;