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

This commit is contained in:
Nikhil Kumar
2023-03-01 15:02:19 +00:00
committed by Android (Google) Code Review
3 changed files with 58 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -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.
*/

View File

@@ -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());
}
}