Replaced calls to UserManager.getUsers(true) to UserManger.getAliveUsers()
Test: m Bug: 157921703 Change-Id: I94973c91c14ad47c43cc1168ab766dc9e2815e54
This commit is contained in:
@@ -525,7 +525,7 @@ public final class Utils extends com.android.settingslib.Utils {
|
|||||||
* @return UserInfo of the user or null for non-existent user.
|
* @return UserInfo of the user or null for non-existent user.
|
||||||
*/
|
*/
|
||||||
public static UserInfo getExistingUser(UserManager userManager, UserHandle checkUser) {
|
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();
|
final int checkUserId = checkUser.getIdentifier();
|
||||||
for (UserInfo user : users) {
|
for (UserInfo user : users) {
|
||||||
if (user.id == checkUserId) {
|
if (user.id == checkUserId) {
|
||||||
|
@@ -526,7 +526,7 @@ public class AppInfoDashboardFragment extends DashboardFragment
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
int getNumberOfUserWithPackageInstalled(String packageName) {
|
int getNumberOfUserWithPackageInstalled(String packageName) {
|
||||||
final List<UserInfo> userInfos = mUserManager.getUsers(true);
|
final List<UserInfo> userInfos = mUserManager.getAliveUsers();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
for (final UserInfo userInfo : userInfos) {
|
for (final UserInfo userInfo : userInfos) {
|
||||||
|
@@ -309,7 +309,7 @@ public class UserDetailsSettings extends SettingsPreferenceFragment
|
|||||||
// Update the guest's restrictions, if there is a guest
|
// Update the guest's restrictions, if there is a guest
|
||||||
// TODO: Maybe setDefaultGuestRestrictions() can internally just set the restrictions
|
// TODO: Maybe setDefaultGuestRestrictions() can internally just set the restrictions
|
||||||
// on any existing guest rather than do it here with multiple Binder calls.
|
// 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) {
|
for (UserInfo user : users) {
|
||||||
if (user.isGuest()) {
|
if (user.isGuest()) {
|
||||||
UserHandle userHandle = UserHandle.of(user.id);
|
UserHandle userHandle = UserHandle.of(user.id);
|
||||||
|
@@ -820,7 +820,7 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
if (context == null) {
|
if (context == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final List<UserInfo> users = mUserManager.getUsers(true);
|
final List<UserInfo> users = mUserManager.getAliveUsers();
|
||||||
|
|
||||||
final ArrayList<Integer> missingIcons = new ArrayList<>();
|
final ArrayList<Integer> missingIcons = new ArrayList<>();
|
||||||
final ArrayList<UserPreference> userPreferences = new ArrayList<>();
|
final ArrayList<UserPreference> userPreferences = new ArrayList<>();
|
||||||
|
@@ -297,7 +297,7 @@ public final class AppInfoDashboardFragmentTest {
|
|||||||
final List<UserInfo> userInfos = new ArrayList<>();
|
final List<UserInfo> userInfos = new ArrayList<>();
|
||||||
userInfos.add(new UserInfo(userID1, "User1", UserInfo.FLAG_PRIMARY));
|
userInfos.add(new UserInfo(userID1, "User1", UserInfo.FLAG_PRIMARY));
|
||||||
userInfos.add(new UserInfo(userID2, "yue", UserInfo.FLAG_GUEST));
|
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();
|
final ApplicationInfo appInfo = new ApplicationInfo();
|
||||||
appInfo.flags = ApplicationInfo.FLAG_INSTALLED;
|
appInfo.flags = ApplicationInfo.FLAG_INSTALLED;
|
||||||
when(mPackageManager.getApplicationInfoAsUser(
|
when(mPackageManager.getApplicationInfoAsUser(
|
||||||
@@ -320,7 +320,7 @@ public final class AppInfoDashboardFragmentTest {
|
|||||||
final List<UserInfo> userInfos = new ArrayList<>();
|
final List<UserInfo> userInfos = new ArrayList<>();
|
||||||
userInfos.add(new UserInfo(userID1, "User1", UserInfo.FLAG_PRIMARY));
|
userInfos.add(new UserInfo(userID1, "User1", UserInfo.FLAG_PRIMARY));
|
||||||
userInfos.add(new UserInfo(userID2, "yue", UserInfo.FLAG_GUEST));
|
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();
|
final ApplicationInfo appInfo = new ApplicationInfo();
|
||||||
appInfo.flags = ApplicationInfo.FLAG_INSTALLED;
|
appInfo.flags = ApplicationInfo.FLAG_INSTALLED;
|
||||||
when(mPackageManager.getApplicationInfoAsUser(
|
when(mPackageManager.getApplicationInfoAsUser(
|
||||||
|
@@ -23,7 +23,6 @@ import static android.os.UserManager.SWITCHABILITY_STATUS_USER_SWITCH_DISALLOWED
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.ArgumentMatchers.notNull;
|
import static org.mockito.ArgumentMatchers.notNull;
|
||||||
@@ -575,7 +574,7 @@ public class UserSettingsTest {
|
|||||||
|
|
||||||
verify(mUserManager, never()).getUserIcon(anyInt());
|
verify(mUserManager, never()).getUserIcon(anyInt());
|
||||||
// updateUserList should be called only once
|
// updateUserList should be called only once
|
||||||
verify(mUserManager).getUsers(true);
|
verify(mUserManager).getAliveUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -592,7 +591,7 @@ public class UserSettingsTest {
|
|||||||
|
|
||||||
verify(mUserManager).getUserIcon(ACTIVE_USER_ID);
|
verify(mUserManager).getUserIcon(ACTIVE_USER_ID);
|
||||||
// updateUserList should be called another time after loading the icons
|
// updateUserList should be called another time after loading the icons
|
||||||
verify(mUserManager, times(2)).getUsers(true);
|
verify(mUserManager, times(2)).getAliveUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -672,7 +671,7 @@ public class UserSettingsTest {
|
|||||||
private void givenUsers(UserInfo... userInfo) {
|
private void givenUsers(UserInfo... userInfo) {
|
||||||
List<UserInfo> users = Arrays.asList(userInfo);
|
List<UserInfo> users = Arrays.asList(userInfo);
|
||||||
doReturn(users).when(mUserManager).getUsers();
|
doReturn(users).when(mUserManager).getUsers();
|
||||||
doReturn(users).when(mUserManager).getUsers(anyBoolean());
|
doReturn(users).when(mUserManager).getAliveUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void removeFlag(UserInfo userInfo, int flag) {
|
private static void removeFlag(UserInfo userInfo, int flag) {
|
||||||
|
Reference in New Issue
Block a user