Replaced calls to UserManager.getUsers(true) to UserManger.getAliveUsers()

Test: m

Bug: 157921703

Change-Id: I94973c91c14ad47c43cc1168ab766dc9e2815e54
This commit is contained in:
Felipe Leme
2020-08-12 20:31:32 -07:00
parent 59d8ab1094
commit c242c62c7a
6 changed files with 9 additions and 10 deletions

View File

@@ -525,7 +525,7 @@ public final class Utils extends com.android.settingslib.Utils {
* @return UserInfo of the user or null for non-existent user.
*/
public static UserInfo getExistingUser(UserManager userManager, UserHandle checkUser) {
final List<UserInfo> users = userManager.getUsers(true /* excludeDying */);
final List<UserInfo> users = userManager.getAliveUsers();
final int checkUserId = checkUser.getIdentifier();
for (UserInfo user : users) {
if (user.id == checkUserId) {

View File

@@ -526,7 +526,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
@VisibleForTesting
int getNumberOfUserWithPackageInstalled(String packageName) {
final List<UserInfo> userInfos = mUserManager.getUsers(true);
final List<UserInfo> userInfos = mUserManager.getAliveUsers();
int count = 0;
for (final UserInfo userInfo : userInfos) {

View File

@@ -309,7 +309,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
// Update the guest's restrictions, if there is a guest
// TODO: Maybe setDefaultGuestRestrictions() can internally just set the restrictions
// on any existing guest rather than do it here with multiple Binder calls.
List<UserInfo> users = mUserManager.getUsers(true);
List<UserInfo> users = mUserManager.getAliveUsers();
for (UserInfo user : users) {
if (user.isGuest()) {
UserHandle userHandle = UserHandle.of(user.id);

View File

@@ -820,7 +820,7 @@ public class UserSettings extends SettingsPreferenceFragment
if (context == null) {
return;
}
final List<UserInfo> users = mUserManager.getUsers(true);
final List<UserInfo> users = mUserManager.getAliveUsers();
final ArrayList<Integer> missingIcons = new ArrayList<>();
final ArrayList<UserPreference> userPreferences = new ArrayList<>();

View File

@@ -297,7 +297,7 @@ public final class AppInfoDashboardFragmentTest {
final List<UserInfo> userInfos = new ArrayList<>();
userInfos.add(new UserInfo(userID1, "User1", UserInfo.FLAG_PRIMARY));
userInfos.add(new UserInfo(userID2, "yue", UserInfo.FLAG_GUEST));
when(mUserManager.getUsers(true)).thenReturn(userInfos);
when(mUserManager.getAliveUsers()).thenReturn(userInfos);
final ApplicationInfo appInfo = new ApplicationInfo();
appInfo.flags = ApplicationInfo.FLAG_INSTALLED;
when(mPackageManager.getApplicationInfoAsUser(
@@ -320,7 +320,7 @@ public final class AppInfoDashboardFragmentTest {
final List<UserInfo> userInfos = new ArrayList<>();
userInfos.add(new UserInfo(userID1, "User1", UserInfo.FLAG_PRIMARY));
userInfos.add(new UserInfo(userID2, "yue", UserInfo.FLAG_GUEST));
when(mUserManager.getUsers(true)).thenReturn(userInfos);
when(mUserManager.getAliveUsers()).thenReturn(userInfos);
final ApplicationInfo appInfo = new ApplicationInfo();
appInfo.flags = ApplicationInfo.FLAG_INSTALLED;
when(mPackageManager.getApplicationInfoAsUser(

View File

@@ -23,7 +23,6 @@ import static android.os.UserManager.SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.notNull;
@@ -575,7 +574,7 @@ public class UserSettingsTest {
verify(mUserManager, never()).getUserIcon(anyInt());
// updateUserList should be called only once
verify(mUserManager).getUsers(true);
verify(mUserManager).getAliveUsers();
}
@Test
@@ -592,7 +591,7 @@ public class UserSettingsTest {
verify(mUserManager).getUserIcon(ACTIVE_USER_ID);
// updateUserList should be called another time after loading the icons
verify(mUserManager, times(2)).getUsers(true);
verify(mUserManager, times(2)).getAliveUsers();
}
@Test
@@ -672,7 +671,7 @@ public class UserSettingsTest {
private void givenUsers(UserInfo... userInfo) {
List<UserInfo> users = Arrays.asList(userInfo);
doReturn(users).when(mUserManager).getUsers();
doReturn(users).when(mUserManager).getUsers(anyBoolean());
doReturn(users).when(mUserManager).getAliveUsers();
}
private static void removeFlag(UserInfo userInfo, int flag) {