Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b06a4f74 authored by Tetiana Meronyk's avatar Tetiana Meronyk Committed by Android (Google) Code Review
Browse files

Merge "Make Multiuser toggle disabled for all non-main users" into main

parents 302bd575 dc0c58b4
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -63,8 +63,7 @@ public class MultiUserSwitchBarController implements SwitchWidgetController.OnSw
                    .checkIfRestrictionEnforced(mContext, UserManager.DISALLOW_ADD_USER,
                            UserHandle.myUserId()));
        } else {
            mSwitchBar.setEnabled(!mUserCapabilities.mDisallowSwitchUser
                    && !mUserCapabilities.mIsGuest && mUserCapabilities.isAdmin());
            mSwitchBar.setEnabled(mUserCapabilities.mIsMain);
        }
        mSwitchBar.setListener(this);
    }
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public class UserCapabilities {
    boolean mEnabled = true;
    boolean mCanAddUser = true;
    boolean mCanAddRestrictedProfile;
    boolean mIsMain;
    boolean mIsAdmin;
    boolean mIsGuest;
    boolean mIsEphemeral;
@@ -57,6 +58,7 @@ public class UserCapabilities {
        final UserInfo myUserInfo = userManager.getUserInfo(UserHandle.myUserId());
        caps.mIsGuest = myUserInfo.isGuest();
        caps.mIsAdmin = myUserInfo.isAdmin();
        caps.mIsMain = myUserInfo.isMain();
        caps.mIsEphemeral = myUserInfo.isEphemeral();
        DevicePolicyManager dpm = (DevicePolicyManager) context.getSystemService(
                Context.DEVICE_POLICY_SERVICE);
+1 −1
Original line number Diff line number Diff line
@@ -287,7 +287,7 @@ public class UserSettings extends SettingsPreferenceFragment
        final SettingsActivity activity = (SettingsActivity) getActivity();
        final SettingsMainSwitchBar switchBar = activity.getSwitchBar();
        switchBar.setTitle(getContext().getString(R.string.multiple_users_main_switch_title));
        if (isCurrentUserAdmin()) {
        if (!mUserCaps.mIsGuest) {
            switchBar.show();
        } else {
            switchBar.hide();
+23 −0
Original line number Diff line number Diff line
@@ -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);
    }
}