Make Multiuser toggle disabled for all non-main users

Only let main user (Owner) change state of the toggle
Bug: 336764498
Test: atest MultiUserSwitchBarControllerTest

Change-Id: Ib694d1cb4685764c64633efc090765b470a0a015
This commit is contained in:
Tetiana Meronyk
2024-05-01 17:21:14 +00:00
parent 377a7a3054
commit dc0c58b427
4 changed files with 27 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.content.pm.UserInfo;
import android.os.UserHandle;
import android.os.UserManager;
@@ -79,4 +80,26 @@ public class MultiUserSwitchBarControllerTest {
verify(mSwitchWidgetController, never()).setDisabledByAdmin(any());
}
@Test
public void onStart_userIsNotMain_shouldNotBeEnabled() {
mUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()),
UserManager.DISALLOW_USER_SWITCH, false);
mUserManager.addUser(10, "Test", UserInfo.FLAG_ADMIN);
mUserManager.switchUser(10);
new MultiUserSwitchBarController(mContext, mSwitchWidgetController, null);
verify(mSwitchWidgetController, never()).setDisabledByAdmin(any());
verify(mSwitchWidgetController).setEnabled(false);
}
@Test
public void onStart_userIsMain_shouldBeEnabled() {
mUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()),
UserManager.DISALLOW_USER_SWITCH, false);
new MultiUserSwitchBarController(mContext, mSwitchWidgetController, null);
verify(mSwitchWidgetController, never()).setDisabledByAdmin(any());
verify(mSwitchWidgetController).setEnabled(true);
}
}