Loading services/core/java/com/android/server/am/ActivityManagerService.java +9 −4 Original line number Diff line number Diff line Loading @@ -6490,23 +6490,28 @@ public class ActivityManagerService extends IActivityManager.Stub userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, true, ALLOW_FULL_ONLY, "killBackgroundProcesses", null); final int[] userIds = mUserController.expandUserId(userId); long callingId = Binder.clearCallingIdentity(); try { IPackageManager pm = AppGlobals.getPackageManager(); synchronized(this) { for (int targetUserId : userIds) { int appId = -1; try { appId = UserHandle.getAppId( pm.getPackageUid(packageName, MATCH_DEBUG_TRIAGED_MISSING, userId)); pm.getPackageUid(packageName, MATCH_DEBUG_TRIAGED_MISSING, targetUserId)); } catch (RemoteException e) { } if (appId == -1) { Slog.w(TAG, "Invalid packageName: " + packageName); return; } killPackageProcessesLocked(packageName, appId, userId, synchronized (this) { killPackageProcessesLocked(packageName, appId, targetUserId, ProcessList.SERVICE_ADJ, false, true, true, false, "kill background"); } } } finally { Binder.restoreCallingIdentity(callingId); } services/core/java/com/android/server/am/ActivityManagerShellCommand.java +1 −1 Original line number Diff line number Diff line Loading @@ -2811,7 +2811,7 @@ final class ActivityManagerShellCommand extends ShellCommand { pw.println(" crash [--user <USER_ID>] <PACKAGE|PID>"); pw.println(" Induce a VM crash in the specified package or process"); pw.println(" kill [--user <USER_ID> | all | current] <PACKAGE>"); pw.println(" Kill all processes associated with the given application."); pw.println(" Kill all background processes associated with the given application."); pw.println(" kill-all"); pw.println(" Kill all processes that are safe to kill (cached, etc)."); pw.println(" make-uid-idle [--user <USER_ID> | all | current] <PACKAGE>"); Loading services/core/java/com/android/server/am/UserController.java +14 −0 Original line number Diff line number Diff line Loading @@ -1735,6 +1735,20 @@ class UserController implements Handler.Callback { return mInjector.getUserManager().getUserIds(); } /** * If {@code userId} is {@link UserHandle#USER_ALL}, then return an array with all running user * IDs. Otherwise return an array whose only element is the given user id. * * It doesn't handle other special user IDs such as {@link UserHandle#USER_CURRENT}. */ int[] expandUserId(int userId) { if (userId != UserHandle.USER_ALL) { return new int[] {userId}; } else { return getUsers(); } } boolean exists(int userId) { return mInjector.getUserManager().exists(userId); } Loading Loading
services/core/java/com/android/server/am/ActivityManagerService.java +9 −4 Original line number Diff line number Diff line Loading @@ -6490,23 +6490,28 @@ public class ActivityManagerService extends IActivityManager.Stub userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, true, ALLOW_FULL_ONLY, "killBackgroundProcesses", null); final int[] userIds = mUserController.expandUserId(userId); long callingId = Binder.clearCallingIdentity(); try { IPackageManager pm = AppGlobals.getPackageManager(); synchronized(this) { for (int targetUserId : userIds) { int appId = -1; try { appId = UserHandle.getAppId( pm.getPackageUid(packageName, MATCH_DEBUG_TRIAGED_MISSING, userId)); pm.getPackageUid(packageName, MATCH_DEBUG_TRIAGED_MISSING, targetUserId)); } catch (RemoteException e) { } if (appId == -1) { Slog.w(TAG, "Invalid packageName: " + packageName); return; } killPackageProcessesLocked(packageName, appId, userId, synchronized (this) { killPackageProcessesLocked(packageName, appId, targetUserId, ProcessList.SERVICE_ADJ, false, true, true, false, "kill background"); } } } finally { Binder.restoreCallingIdentity(callingId); }
services/core/java/com/android/server/am/ActivityManagerShellCommand.java +1 −1 Original line number Diff line number Diff line Loading @@ -2811,7 +2811,7 @@ final class ActivityManagerShellCommand extends ShellCommand { pw.println(" crash [--user <USER_ID>] <PACKAGE|PID>"); pw.println(" Induce a VM crash in the specified package or process"); pw.println(" kill [--user <USER_ID> | all | current] <PACKAGE>"); pw.println(" Kill all processes associated with the given application."); pw.println(" Kill all background processes associated with the given application."); pw.println(" kill-all"); pw.println(" Kill all processes that are safe to kill (cached, etc)."); pw.println(" make-uid-idle [--user <USER_ID> | all | current] <PACKAGE>"); Loading
services/core/java/com/android/server/am/UserController.java +14 −0 Original line number Diff line number Diff line Loading @@ -1735,6 +1735,20 @@ class UserController implements Handler.Callback { return mInjector.getUserManager().getUserIds(); } /** * If {@code userId} is {@link UserHandle#USER_ALL}, then return an array with all running user * IDs. Otherwise return an array whose only element is the given user id. * * It doesn't handle other special user IDs such as {@link UserHandle#USER_CURRENT}. */ int[] expandUserId(int userId) { if (userId != UserHandle.USER_ALL) { return new int[] {userId}; } else { return getUsers(); } } boolean exists(int userId) { return mInjector.getUserManager().exists(userId); } Loading