adb cmd for canSwitchToHeadlessSystemUser and isMainUserPermanentAdmin
Added adb commands in UserManagerShellCommand for config properties canSwitchToHeadlessSystemUser and isMainUserPermanentAdmin and unit tests for the same. Bug: 270688035 Test: atest UserManagerShellCommandTest and with adb commands adb cmd user can-switch-to-headless-system-user and adb cmd user is-main-user-permanent-admin Change-Id: I40e7530e72d2fa87adacbd02a977fc9a654759f2
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user