Not trying to remove admins already being removed

If someone calls removeActiveAdminLocked more than once, it is possible
for the device policy data to end up with more than one copy of an admin
in the list mRemovingAdmins. Due to extra entries, once the admin
component is removed, it is not being allowed to be set as an admin again,
until the device reboots or mRemovingAdmins is cleared from the memory
due to some other reason. Fixing this by making sure we do not add
duplicate entries to mRemovingAdmins

Bug: 30369197
Change-Id: I1d53c41312171425bbd6e6e4153148276f1b098d
This commit is contained in:
Suprabh Shukla
2016-08-04 16:24:45 -07:00
parent 29cc1b6939
commit 9704e409df

View File

@@ -2093,8 +2093,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
void removeActiveAdminLocked(final ComponentName adminReceiver, final int userHandle) {
final ActiveAdmin admin = getActiveAdminUncheckedLocked(adminReceiver, userHandle);
if (admin != null) {
getUserData(userHandle).mRemovingAdmins.add(adminReceiver);
DevicePolicyData policy = getUserData(userHandle);
if (admin != null && !policy.mRemovingAdmins.contains(adminReceiver)) {
policy.mRemovingAdmins.add(adminReceiver);
sendAdminCommandLocked(admin,
DeviceAdminReceiver.ACTION_DEVICE_ADMIN_DISABLED,
new BroadcastReceiver() {
@@ -5706,7 +5707,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
}
synchronized (this) {
enforceCanSetDeviceOwnerLocked(userId);
if (getActiveAdminUncheckedLocked(admin, userId) == null) {
if (getActiveAdminUncheckedLocked(admin, userId) == null
|| getUserData(userId).mRemovingAdmins.contains(admin)) {
throw new IllegalArgumentException("Not active admin: " + admin);
}
@@ -5894,7 +5896,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
synchronized (this) {
enforceCanSetProfileOwnerLocked(userHandle);
if (getActiveAdminUncheckedLocked(who, userHandle) == null) {
if (getActiveAdminUncheckedLocked(who, userHandle) == null
|| getUserData(userHandle).mRemovingAdmins.contains(who)) {
throw new IllegalArgumentException("Not active admin: " + who);
}