Watch out for deleted user when exiting async task
Fixes a problem where the async task can take a while to execute and in the meantime the user can be removed. On exiting the async task and updating the UI, make sure the user hasn't been deleted. Bug: 18411181 Change-Id: I1831f3e53084c49e27557cb7aacec78c753a611b
This commit is contained in:
@@ -1023,4 +1023,21 @@ public final class Utils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries for the UserInfo of a user. Returns null if the user doesn't exist (was removed).
|
||||
* @param userManager Instance of UserManager
|
||||
* @param checkUser The user to check the existence of.
|
||||
* @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 int checkUserId = checkUser.getIdentifier();
|
||||
for (UserInfo user : users) {
|
||||
if (user.id == checkUserId) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user