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

Commit 652989c0 authored by Nikhil Kumar's avatar Nikhil Kumar Committed by Android (Google) Code Review
Browse files

Merge "adb cmd for canSwitchToHeadlessSystemUser and isMainUserPermanentAdmin" into udc-dev

parents 4682a93c a77c22ae
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ import android.util.TimeUtils;
import android.util.TypedValue;
import android.util.Xml;

import com.android.internal.R;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.app.IAppOpsService;
@@ -7369,9 +7370,19 @@ public class UserManagerService extends IUserManager.Stub {
     * If the main user is a permanent admin user it can't be deleted
     * or downgraded to non-admin status.
     */
    private static boolean isMainUserPermanentAdmin() {
    public boolean isMainUserPermanentAdmin() {
        return Resources.getSystem()
                .getBoolean(com.android.internal.R.bool.config_isMainUserPermanentAdmin);
                .getBoolean(R.bool.config_isMainUserPermanentAdmin);
    }

    /**
     * Returns true if {@link com.android.internal.R.bool#config_canSwitchToHeadlessSystemUser}
     * is true. If allowed, headless system user can run in the foreground even though
     * it is not a full user.
     */
    public boolean canSwitchToHeadlessSystemUser() {
        return Resources.getSystem()
                .getBoolean(R.bool.config_canSwitchToHeadlessSystemUser);
    }

}
+18 −0
Original line number Diff line number Diff line
@@ -150,6 +150,10 @@ public class UserManagerServiceShellCommand extends ShellCommand {
                    return runIsUserVisible();
                case "get-main-user":
                    return runGetMainUserId();
                case "can-switch-to-headless-system-user":
                    return canSwitchToHeadlessSystemUser();
                case "is-main-user-permanent-admin":
                    return isMainUserPermanentAdmin();
                default:
                    return handleDefaultCommands(cmd);
            }
@@ -532,6 +536,20 @@ public class UserManagerServiceShellCommand extends ShellCommand {
        return 0;
    }

    private int canSwitchToHeadlessSystemUser() {
        PrintWriter pw = getOutPrintWriter();
        boolean canSwitchToHeadlessSystemUser = mService.canSwitchToHeadlessSystemUser();
        pw.println(canSwitchToHeadlessSystemUser);
        return 0;
    }

    private int isMainUserPermanentAdmin() {
        PrintWriter pw = getOutPrintWriter();
        boolean isMainUserPermanentAdmin = mService.isMainUserPermanentAdmin();
        pw.println(isMainUserPermanentAdmin);
        return 0;
    }

    /**
     * Gets the {@link UserManager} associated with the context of the given user.
     */
+27 −0
Original line number Diff line number Diff line
@@ -121,4 +121,31 @@ public class UserManagerServiceShellCommandTest {
        assertEquals("Couldn't get main user.", mOutStream.toString().trim());
    }

    @Test
    public void testCanSwitchToHeadlessSystemUser() {
        doReturn(true).when(mUserManagerService).canSwitchToHeadlessSystemUser();
        doReturn(mWriter).when(mCommand).getOutPrintWriter();

        assertEquals(0, mCommand.exec(mBinder, in, out, err,
                new String[]{"can-switch-to-headless-system-user"},
                mShellCallback, mResultReceiver));

        mWriter.flush();
        assertEquals("true", mOutStream.toString().trim());
    }


    @Test
    public void testIsMainUserPermanentAdmin() {
        doReturn(false).when(mUserManagerService).isMainUserPermanentAdmin();
        doReturn(mWriter).when(mCommand).getOutPrintWriter();

        assertEquals(0, mCommand.exec(mBinder, in, out, err,
                new String[]{"is-main-user-permanent-admin"}, mShellCallback, mResultReceiver));

        mWriter.flush();
        assertEquals("false", mOutStream.toString().trim());
    }


}