Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49f650fb authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Added shell command to check if device uses headless system user mode"

parents 13b8bf0e 3c057248
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -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] <USER_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.
     */