From ec5aa8f126cfc10219a875f81c094ce0b5fc0af1 Mon Sep 17 00:00:00 2001 From: Yasin Kilicdere Date: Thu, 8 Dec 2022 16:35:12 +0000 Subject: [PATCH] ActivityManagerShellCommand calls getUserSwitchability with wrong user UserManager.getUserSwitchability API is always called with userId 0 from ActivityManagerShellCommand. This CL fixes that issue by passing the userId parameter came from the command line to the API. Bug: 261857907 Test: adb shell am switch-user -w 10 Change-Id: I3d6fa18f63f4b6e01acbf197cfcb5cedb614925c --- .../server/am/ActivityManagerShellCommand.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java index 0b94798b170e5..f847f1c606ae8 100644 --- a/services/core/java/com/android/server/am/ActivityManagerShellCommand.java +++ b/services/core/java/com/android/server/am/ActivityManagerShellCommand.java @@ -2006,12 +2006,6 @@ final class ActivityManagerShellCommand extends ShellCommand { } int runSwitchUser(PrintWriter pw) throws RemoteException { - UserManager userManager = mInternal.mContext.getSystemService(UserManager.class); - final int userSwitchable = userManager.getUserSwitchability(); - if (userSwitchable != UserManager.SWITCHABILITY_STATUS_OK) { - getErrPrintWriter().println("Error: " + userSwitchable); - return -1; - } boolean wait = false; String opt; while ((opt = getNextOption()) != null) { @@ -2024,6 +2018,14 @@ final class ActivityManagerShellCommand extends ShellCommand { } int userId = Integer.parseInt(getNextArgRequired()); + + UserManager userManager = mInternal.mContext.getSystemService(UserManager.class); + final int userSwitchable = userManager.getUserSwitchability(UserHandle.of(userId)); + if (userSwitchable != UserManager.SWITCHABILITY_STATUS_OK) { + getErrPrintWriter().println("Error: UserSwitchabilityResult=" + userSwitchable); + return -1; + } + boolean switched; Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "shell_runSwitchUser"); try {