Loading src/com/android/settings/deviceinfo/storage/SecondaryUserController.java +2 −1 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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; } Loading tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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(); } } Loading
src/com/android/settings/deviceinfo/storage/SecondaryUserController.java +2 −1 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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; } Loading
tests/robotests/src/com/android/settings/deviceinfo/storage/SecondaryUserControllerTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -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); Loading Loading @@ -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(); } }