Refactor multiuser toggle to control user switch feature
The name "Allow multiple users" is too ambiguous. It sounds like by toggling it off, the feature is completely disabled. In fact, it only hides user switcher. In conjunction with hiding other users from the list, it makes it appear as all the users get deleted when the toggle is off. On the contrary, users might be running in background when the toggle is off. After this change, the new name better represents the intention behind this toggle, as well as makes the UI more intuitive. The users are not being hidden anymore. But switching preference gets disabled. Since the toggle can only be enabled or disabled by owner (after this refactoring), it means that Owner has full control over multiuser settings and is able to perform actions on users without having to enable the toggle. Bug: 336762423 Test: atest UserSettingsTest && atest UserDetailsSettingsTest Flag: android.multiuser.new_multiuser_settings_ux Change-Id: Id9d507039b58d3df66fe78710409716fd4816890
This commit is contained in:
@@ -46,10 +46,15 @@ import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.multiuser.Flags;
|
||||
import android.os.Bundle;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||
import android.provider.Settings;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.view.Menu;
|
||||
@@ -75,6 +80,7 @@ import com.android.settingslib.search.SearchIndexableRaw;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.AdditionalMatchers;
|
||||
@@ -142,6 +148,9 @@ public class UserSettingsTest {
|
||||
private UserSettings mFragment;
|
||||
private UserCapabilities mUserCapabilities;
|
||||
|
||||
@Rule
|
||||
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
@@ -406,6 +415,7 @@ public class UserSettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsDisabled({Flags.FLAG_NEW_MULTIUSER_SETTINGS_UX})
|
||||
public void updateUserList_addUserDisallowedByAdmin_shouldNotShowAddUser() {
|
||||
RestrictedLockUtils.EnforcedAdmin enforcedAdmin = mock(
|
||||
RestrictedLockUtils.EnforcedAdmin.class);
|
||||
@@ -420,6 +430,22 @@ public class UserSettingsTest {
|
||||
verify(mAddUserPreference).setVisible(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@RequiresFlagsEnabled({Flags.FLAG_NEW_MULTIUSER_SETTINGS_UX})
|
||||
public void updateUserList_addUserDisallowedByAdmin_shouldShowPrefDisabledByAdmin() {
|
||||
RestrictedLockUtils.EnforcedAdmin enforcedAdmin = mock(
|
||||
RestrictedLockUtils.EnforcedAdmin.class);
|
||||
|
||||
mUserCapabilities.mEnforcedAdmin = enforcedAdmin;
|
||||
mUserCapabilities.mCanAddUser = false;
|
||||
mUserCapabilities.mDisallowAddUser = true;
|
||||
mUserCapabilities.mDisallowAddUserSetByAdmin = true;
|
||||
doReturn(true).when(mAddUserPreference).isEnabled();
|
||||
|
||||
mFragment.updateUserList();
|
||||
|
||||
verify(mAddUserPreference).setDisabledByAdmin(enforcedAdmin);
|
||||
}
|
||||
@Test
|
||||
public void updateUserList_cannotAddUserButCanSwitchUser_shouldNotShowAddUser() {
|
||||
mUserCapabilities.mCanAddUser = false;
|
||||
@@ -461,18 +487,31 @@ public class UserSettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateUserList_userSwitcherDisabled_shouldNotShowAddUser() {
|
||||
public void updateUserList_userSwitcherDisabled_shouldShowAddUser() {
|
||||
givenUsers(getAdminUser(true));
|
||||
mUserCapabilities.mCanAddUser = true;
|
||||
mUserCapabilities.mUserSwitcherEnabled = false;
|
||||
|
||||
mFragment.updateUserList();
|
||||
|
||||
verify(mAddUserPreference).setVisible(false);
|
||||
verify(mAddUserPreference).setVisible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateUserList_userSwitcherDisabled_shouldNotShowAddGuest() {
|
||||
public void updateUserList_userSwitcherDisabled_shouldShowAddGuest() {
|
||||
givenUsers(getAdminUser(true));
|
||||
mUserCapabilities.mCanAddGuest = true;
|
||||
mUserCapabilities.mUserSwitcherEnabled = false;
|
||||
doReturn(true)
|
||||
.when(mUserManager).canAddMoreUsers(eq(UserManager.USER_TYPE_FULL_GUEST));
|
||||
|
||||
mFragment.updateUserList();
|
||||
|
||||
verify(mAddGuestPreference).setVisible(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateUserList_userSwitcherDisabledCannotAddMoreGuests_shouldNotShowAddGuest() {
|
||||
givenUsers(getAdminUser(true));
|
||||
mUserCapabilities.mCanAddGuest = true;
|
||||
mUserCapabilities.mUserSwitcherEnabled = false;
|
||||
@@ -533,18 +572,18 @@ public class UserSettingsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateUserList_existingSecondaryUser_shouldAddOnlyCurrUser_MultiUserIsDisabled() {
|
||||
public void updateUserList_existingSecondaryUser_shouldAddAllUsers_MultiUserIsDisabled() {
|
||||
givenUsers(getAdminUser(true), getSecondaryUser(false));
|
||||
mUserCapabilities.mUserSwitcherEnabled = false;
|
||||
|
||||
mFragment.updateUserList();
|
||||
|
||||
ArgumentCaptor<UserPreference> captor = ArgumentCaptor.forClass(UserPreference.class);
|
||||
verify(mFragment.mUserListCategory, times(1))
|
||||
verify(mFragment.mUserListCategory, times(2))
|
||||
.addPreference(captor.capture());
|
||||
|
||||
List<UserPreference> userPrefs = captor.getAllValues();
|
||||
assertThat(userPrefs.size()).isEqualTo(1);
|
||||
assertThat(userPrefs.size()).isEqualTo(2);
|
||||
assertThat(userPrefs.get(0)).isSameInstanceAs(mMePreference);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user