SettingsApp Implement DISALLOW_GRANT_ADMIN in user creation flow

In the process of creating a user through the Settings app, if the current user has the DISALLOW_GRANT_ADMIN restriction, the dialogue for granting ADMIN privileges will be hidden after this implementation. This action ensures that even if child users can create SECONDARY users, they cannot create ADMIN users.

Design doc: go/unicorn-hsum

Bug: 357819541
Test: manually verified the user is not allowed to create ADMIN user when DISALLOW_GRANT_ADMIN restriction is applied.
Flag: android.multiuser.unicorn_mode_refactoring_for_hsum_read_only
Change-Id: I4b40f83b50d4de0af103d4f5ca400e42345144e0
This commit is contained in:
Nikhil Kumar
2024-08-06 14:15:40 +01:00
parent b377b1c0e4
commit c05f058083

View File

@@ -919,7 +919,7 @@ public class UserSettings extends SettingsPreferenceFragment
d = mCreateUserDialogController.createDialog(
getActivity(),
this::startActivityForResult,
UserManager.isMultipleAdminEnabled(),
canCreateAdminUser(),
(userName, userIcon, isAdmin) -> {
mPendingUserIcon = userIcon;
mPendingUserName = userName;
@@ -937,6 +937,19 @@ public class UserSettings extends SettingsPreferenceFragment
return d;
}
/**
* Checks if the creation of a new admin user is allowed.
* @return {@code true} if creating a new admin is allowed, {@code false} otherwise.
*/
private boolean canCreateAdminUser() {
if (Flags.unicornModeRefactoringForHsumReadOnly()) {
return UserManager.isMultipleAdminEnabled()
&& !mUserManager.hasUserRestriction(UserManager.DISALLOW_GRANT_ADMIN);
} else {
return UserManager.isMultipleAdminEnabled();
}
}
@Override
public int getDialogMetricsCategory(int dialogId) {
switch (dialogId) {