Don't remove elements while using foreach
We were using a foreach in reuseOutgoingCall and removing an element if
it meets a certain criteria. This is incorrect in Java. Switching to an
iterator.
Bug: 31102577
Change-Id: I086a53a732ee5ab8f6ccea60fec9745ce6821f24
diff --git a/src/com/android/server/telecom/CallsManager.java b/src/com/android/server/telecom/CallsManager.java
index 08f2a98..d7961b8 100644
--- a/src/com/android/server/telecom/CallsManager.java
+++ b/src/com/android/server/telecom/CallsManager.java
@@ -69,6 +69,7 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -741,9 +742,10 @@
// Check to see if we can reuse any of the calls that are waiting to disconnect.
// See {@link Call#abort} and {@link #onCanceledViaNewOutgoingCall} for more information.
Call reusedCall = null;
- for (Call pendingCall : mPendingCallsToDisconnect) {
+ for (Iterator<Call> callIter = mPendingCallsToDisconnect.iterator(); callIter.hasNext();) {
+ Call pendingCall = callIter.next();
if (reusedCall == null && areHandlesEqual(pendingCall.getHandle(), handle)) {
- mPendingCallsToDisconnect.remove(pendingCall);
+ callIter.remove();
Log.i(this, "Reusing disconnected call %s", pendingCall);
reusedCall = pendingCall;
} else {