Hide remove user option for main user in multi user settings

Added isMain() user check in UserDetailsSettings.initialize and
UserDetailsSettings.canDeleteUser to hide and restrict
delete user option for main user in multi user settings.

Added unit tests for the same.

Bug: 260200162

Test: Manual test on headless to check remove user option
is not visible for the main user.

Test: Run robo tests with this command:
make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.users.UserDetailsSettingsTest"

Change-Id: Ia455611a3d0b1e0945f61f00658425b7bf6c2dae
This commit is contained in:
Nikhil Kumar
2022-11-24 19:16:55 +00:00
parent 845426e9e5
commit b61949c841
2 changed files with 38 additions and 2 deletions

View File

@@ -317,8 +317,12 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
mRemoveUserPref.setTitle(R.string.user_remove_user);
removePreference(KEY_APP_COPYING);
}
// Remove preference KEY_REMOVE_USER if DISALLOW_REMOVE_USER restriction is set
// on the current user or the user selected in user details settings is a main user.
if (RestrictedLockUtilsInternal.hasBaseUserRestriction(context,
UserManager.DISALLOW_REMOVE_USER, UserHandle.myUserId())) {
UserManager.DISALLOW_REMOVE_USER, UserHandle.myUserId())
|| mUserInfo.isMain()) {
removePreference(KEY_REMOVE_USER);
}
@@ -331,7 +335,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
@VisibleForTesting
boolean canDeleteUser() {
if (!mUserManager.isAdminUser()) {
if (!mUserManager.isAdminUser() || mUserInfo.isMain()) {
return false;
}