Add back ActivityManagerService.onUserRemoved

ActivityManagerService.onUserRemoved was accidentally removed in
ag/4246926. This cl adds it back.

The part of onUserRemoved that told ActivityTaskManagerService that
the user had stopped (and thereby cleaned up ATMS) was retained, but
the additional actions of AMS.onUserRemoved - namely, telling
BatteryStatsService and UserController - were accidentally removed.
Consequently, those services were never told when a user was removed.

Bug: 140645064
Test: manual verification that profile is removed in  adb shell dumpsys activity users
Change-Id: I903b06ae68d583bdb326ad3b764a63d18b5555d8
This commit is contained in:
Adam Bookatz
2020-04-24 12:50:18 -07:00
parent 56669d830c
commit aa59419bbd
4 changed files with 22 additions and 7 deletions

View File

@@ -80,6 +80,15 @@ public abstract class ActivityManagerInternal {
public abstract boolean startIsolatedProcess(String entryPoint, String[] mainArgs,
String processName, String abiOverride, int uid, Runnable crashHandler);
/**
* Called when a user has been deleted. This can happen during normal device usage
* or just at startup, when partially removed users are purged. Any state persisted by the
* ActivityManager should be purged now.
*
* @param userId The user being cleaned up.
*/
public abstract void onUserRemoved(@UserIdInt int userId);
/**
* Kill foreground apps from the specified user.
*/

View File

@@ -18778,6 +18778,15 @@ public class ActivityManagerService extends IActivityManager.Stub
processName, abiOverride, uid, crashHandler);
}
@Override
public void onUserRemoved(@UserIdInt int userId) {
// Clean up any ActivityTaskManager state (by telling it the user is stopped)
mAtmInternal.onUserStopped(userId);
// Clean up various services by removing the user
mBatteryStatsService.onUserRemoved(userId);
mUserController.onUserRemoved(userId);
}
@Override
public void killForegroundAppsForUser(@UserIdInt int userId) {
synchronized (ActivityManagerService.this) {

View File

@@ -3890,9 +3890,8 @@ public class UserManagerService extends IUserManager.Stub {
new Thread() {
@Override
public void run() {
// Clean up any ActivityTaskManager state
LocalServices.getService(ActivityTaskManagerInternal.class)
.onUserStopped(userId);
LocalServices.getService(ActivityManagerInternal.class)
.onUserRemoved(userId);
removeUserState(userId);
}
}.start();

View File

@@ -306,11 +306,9 @@ public abstract class ActivityTaskManagerInternal {
public abstract void setAllowAppSwitches(@NonNull String type, int uid, int userId);
/**
* Called when a user has been deleted. This can happen during normal device usage
* or just at startup, when partially removed users are purged. Any state persisted by the
* ActivityManager should be purged now.
* Called when a user has been stopped.
*
* @param userId The user being cleaned up.
* @param userId The user being stopped.
*/
public abstract void onUserStopped(int userId);
public abstract boolean isGetTasksAllowed(String caller, int callingPid, int callingUid);