Disable multiuser toggle when more than 1 user is created

It makes more sense to have the toggle as on permanently as long as there are other users on the device. Otherwise if we toggle off "Allow multiple users", other users get hidden. Also with current behaviour the any admin can switch the toggle and this can block any other user, including main, from being able to use the device.

Bug: 295183792
Test: atest MultiUserSwitchBarControllerTest && UserSettingsTest
Change-Id: I8cb0671d780f45c17a9bb7c9a9d3b108128ead9d
This commit is contained in:
Tetiana Meronyk
2023-08-14 18:33:01 +00:00
parent c06c74af17
commit 7968047fc5
3 changed files with 38 additions and 6 deletions

View File

@@ -290,8 +290,9 @@ public class UserSettings extends SettingsPreferenceFragment
} else {
switchBar.hide();
}
boolean isToggleEnabled = mUserManager.getFullUserCount() == 1;
mSwitchBarController = new MultiUserSwitchBarController(activity,
new MainSwitchBarController(switchBar), this /* listener */);
new MainSwitchBarController(switchBar), isToggleEnabled, this /* listener */);
getSettingsLifecycle().addObserver(mSwitchBarController);
boolean openUserEditDialog = getIntent().getBooleanExtra(
EXTRA_OPEN_DIALOG_USER_PROFILE_EDITOR, false);
@@ -422,6 +423,9 @@ public class UserSettings extends SettingsPreferenceFragment
mRemoveGuestOnExitPreferenceController.getPreferenceKey()));
if (mShouldUpdateUserList) {
updateUI();
// Update state of "Allow multiple users" toggle when list of users updates
boolean isToggleEnabled = mUserManager.getFullUserCount() == 1;
mSwitchBarController.setToggleEnabled(isToggleEnabled);
}
}