From 3c057248af31c12235f6b02154d6fdd3c446b272 Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Thu, 26 Jan 2023 18:42:03 -0800 Subject: [PATCH] Added shell command to check if device uses headless system user mode It will be used by ITestDevice. Test: adb shell cmd user is-headless-system-user-mode Test: adb shell cmd user is-headless-system-user-mode -v Bug: 174775905 Change-Id: Iee0a822fed69e32142efd14122bf0d1851a276a7 --- .../pm/UserManagerServiceShellCommand.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java b/services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java index 6e861232262ea..5bdcbb9587aee 100644 --- a/services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java +++ b/services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java @@ -36,6 +36,7 @@ import android.os.UserManager; import android.util.IndentingPrintWriter; import android.util.Slog; +import com.android.internal.os.RoSystemProperties; import com.android.internal.widget.LockPatternUtils; import com.android.server.LocalServices; import com.android.server.UiThread; @@ -100,6 +101,11 @@ public class UserManagerServiceShellCommand extends ShellCommand { pw.println(" --reboot (which does a full reboot) or"); pw.println(" --no-restart (which requires a manual restart)"); pw.println(); + pw.println(" is-headless-system-user-mode [-v | --verbose]"); + pw.println(" Checks whether the device uses headless system user mode."); + pw.println(" It returns the effective mode, even when using emulation"); + pw.println(" (to get the real mode as well, use -v or --verbose)"); + pw.println(); pw.println(" is-user-visible [--display DISPLAY_ID] "); pw.println(" Checks if the given user is visible in the given display."); pw.println(" If the display option is not set, it uses the user's context to check"); @@ -121,6 +127,8 @@ public class UserManagerServiceShellCommand extends ShellCommand { return runReportPackageAllowlistProblems(); case "set-system-user-mode-emulation": return runSetSystemUserModeEmulation(); + case "is-headless-system-user-mode": + return runIsHeadlessSystemUserMode(); case "is-user-visible": return runIsUserVisible(); default: @@ -407,6 +415,35 @@ public class UserManagerServiceShellCommand extends ShellCommand { return 0; } + private int runIsHeadlessSystemUserMode() { + PrintWriter pw = getOutPrintWriter(); + + boolean verbose = false; + String opt; + while ((opt = getNextOption()) != null) { + switch (opt) { + case "-v": + case "--verbose": + verbose = true; + break; + default: + pw.println("Invalid option: " + opt); + return -1; + } + } + + boolean isHsum = mService.isHeadlessSystemUserMode(); + if (!verbose) { + // NOTE: do not change output below, as it's used by ITestDevice + // (it's ok to change the verbose option though) + pw.println(isHsum); + } else { + pw.printf("effective=%b real=%b\n", isHsum, + RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER); + } + return 0; + } + /** * Gets the {@link UserManager} associated with the context of the given user. */