Merge "Don't show owner as a secondary user."

This commit is contained in:
Daniel Nishi
2017-03-13 22:10:59 +00:00
committed by Android (Google) Code Review
2 changed files with 22 additions and 1 deletions

View File

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

View File

@@ -69,6 +69,7 @@ public class SecondaryUserControllerTest {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application; mContext = RuntimeEnvironment.application;
mPrimaryUser = new UserInfo(); mPrimaryUser = new UserInfo();
mPrimaryUser.flags = UserInfo.FLAG_PRIMARY;
mController = new SecondaryUserController(mContext, mPrimaryUser); mController = new SecondaryUserController(mContext, mPrimaryUser);
when(mScreen.getContext()).thenReturn(mContext); when(mScreen.getContext()).thenReturn(mContext);
@@ -167,4 +168,23 @@ public class SecondaryUserControllerTest {
assertThat(preference.getSummary()).isEqualTo("99.00B"); 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();
}
} }