Loading services/core/java/com/android/server/pm/UserManagerService.java +13 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } } services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java +18 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading @@ -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. */ Loading services/tests/servicestests/src/com/android/server/pm/UserManagerServiceShellCommandTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -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()); } } Loading
services/core/java/com/android/server/pm/UserManagerService.java +13 −2 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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); } }
services/core/java/com/android/server/pm/UserManagerServiceShellCommand.java +18 −0 Original line number Diff line number Diff line Loading @@ -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); } Loading Loading @@ -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. */ Loading
services/tests/servicestests/src/com/android/server/pm/UserManagerServiceShellCommandTest.java +27 −0 Original line number Diff line number Diff line Loading @@ -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()); } }