Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 57eb705e authored by Rubin Xu's avatar Rubin Xu
Browse files

Fix iterator misuse

Fix a bug where we iterate through a map with an iterator while deleting
some elements (on the map directly, not using the iterator) at the same time.

Bug: 112982695
Test: atest com.android.cts.devicepolicy.MixedProfileOwnerTest#testDelegation
Change-Id: Id46701791d9666ed653683f41e82e3b1d2288432
parent f2aff2c4
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -5925,9 +5925,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            // If set, remove exclusive scopes from all other delegates
            if (exclusiveScopes != null && !exclusiveScopes.isEmpty()) {
                for (Map.Entry<String, List<String>> entry : policy.mDelegationMap.entrySet()) {
                    final String currentPackage = entry.getKey();
                    final List<String> currentScopes = entry.getValue();
                for (int i = policy.mDelegationMap.size() - 1; i >= 0; --i) {
                    final String currentPackage = policy.mDelegationMap.keyAt(i);
                    final List<String> currentScopes = policy.mDelegationMap.valueAt(i);
                    if (!currentPackage.equals(delegatePackage)) {
                        // Iterate through all other delegates
@@ -5935,7 +5935,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                            // And if this delegate had some exclusive scopes which are now moved
                            // to the new delegate, notify about its delegation changes.
                            if (currentScopes.isEmpty()) {
                                policy.mDelegationMap.remove(currentPackage);
                                policy.mDelegationMap.removeAt(i);
                            }
                            sendDelegationChangedBroadcast(currentPackage,
                                    new ArrayList<>(currentScopes), userId);