Replace 2 synchronized blocks with one in revokeUserAdmin method

Bug: 264546208
Test: atest UserManagerServiceTest
Change-Id: Icdb25fe2c570dbab3d7e240e67eb1507fe15019f
This commit is contained in:
Tetiana Meronyk
2023-01-06 13:41:50 +00:00
parent 2a0fb977d2
commit ce340b8d80

View File

@@ -1476,20 +1476,15 @@ public class UserManagerService extends IUserManager.Stub {
@Override
public void revokeUserAdmin(@UserIdInt int userId) {
checkManageUserAndAcrossUsersFullPermission("revoke admin privileges");
synchronized (mPackagesLock) {
UserInfo info;
synchronized (mUsersLock) {
info = getUserInfoLU(userId);
}
if (info == null || !info.isAdmin()) {
// Exit if no user found with that id, or the user is not an Admin.
return;
}
info.flags ^= UserInfo.FLAG_ADMIN;
synchronized (mUsersLock) {
writeUserLP(getUserDataLU(info.id));
UserData user = getUserDataLU(userId);
if (user == null || !user.info.isAdmin()) {
// Exit if no user found with that id, or the user is not an Admin.
return;
}
user.info.flags ^= UserInfo.FLAG_ADMIN;
writeUserLP(user);
}
}
}