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:
Amith Yamasani
2014-11-19 17:12:46 -08:00
parent 3a84d40133
commit 45f86236e4
3 changed files with 88 additions and 74 deletions

View File

@@ -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;
}
}