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

Commit 092e3c0b authored by Daniel Nishi's avatar Daniel Nishi
Browse files

Don't show owner as a secondary user.

Change-Id: I0a67eb176528a0f95595107b12c6ecc679a1041f
Fixes: 36138657
Test: Robotest
parent 397a1b80
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.settings.core.PreferenceController;
import java.util.ArrayList;
import java.util.List;


/**
 * SecondaryUserController controls the preferences on the Storage screen which had to do with
 * secondary users.
@@ -62,7 +63,7 @@ public class SecondaryUserController extends PreferenceController implements
        List<UserInfo> infos = userManager.getUsers();
        for (int i = 0, size = infos.size(); i < size; i++) {
            UserInfo info = infos.get(i);
            if (info.equals(primaryUser)) {
            if (info.isPrimary()) {
                continue;
            }

+20 −0
Original line number Diff line number Diff line
@@ -69,6 +69,7 @@ public class SecondaryUserControllerTest {
        MockitoAnnotations.initMocks(this);
        mContext = RuntimeEnvironment.application;
        mPrimaryUser = new UserInfo();
        mPrimaryUser.flags = UserInfo.FLAG_PRIMARY;
        mController = new SecondaryUserController(mContext, mPrimaryUser);

        when(mScreen.getContext()).thenReturn(mContext);
@@ -167,4 +168,23 @@ public class SecondaryUserControllerTest {

        assertThat(preference.getSummary()).isEqualTo("99.00B");
    }

    @Test
    public void dontAddPrimaryProfileAsASecondaryProfile() throws Exception {
        ArrayList<UserInfo> userInfos = new ArrayList<>();
        // The primary UserInfo may be a different object with a different name... but represent the
        // same user!
        UserInfo primaryUserRenamed = new UserInfo();
        primaryUserRenamed.name = "Owner";
        primaryUserRenamed.flags = UserInfo.FLAG_PRIMARY;
        userInfos.add(primaryUserRenamed);
        when(mUserManager.getPrimaryUser()).thenReturn(mPrimaryUser);
        when(mUserManager.getUsers()).thenReturn(userInfos);
        List<PreferenceController> controllers =
                SecondaryUserController.getSecondaryUserControllers(mContext, mUserManager);

        assertThat(controllers).hasSize(1);
        // We should have the NoSecondaryUserController.
        assertThat(controllers.get(0) instanceof SecondaryUserController).isFalse();
    }
}