Merge "Don't modify a list while iterating."
diff --git a/services/java/com/android/server/TelephonyRegistry.java b/services/java/com/android/server/TelephonyRegistry.java
index 8fc4d57..b1ca7852 100644
--- a/services/java/com/android/server/TelephonyRegistry.java
+++ b/services/java/com/android/server/TelephonyRegistry.java
@@ -233,6 +233,7 @@
         if (!checkNotifyPermission("notifyCallState()")) {
             return;
         }
+        ArrayList<IBinder> removeList = new ArrayList<IBinder>();
         synchronized (mRecords) {
             mCallState = state;
             mCallIncomingNumber = incomingNumber;
@@ -241,10 +242,11 @@
                     try {
                         r.callback.onCallStateChanged(state, incomingNumber);
                     } catch (RemoteException ex) {
-                        remove(r.binder);
+                        removeList.add(r.binder);
                     }
                 }
             }
+            for (IBinder b : removeList) remove(b);
         }
         broadcastCallStateChanged(state, incomingNumber);
     }
@@ -268,6 +270,7 @@
         if (!checkNotifyPermission("notifySignalStrength()")) {
             return;
         }
+        ArrayList<IBinder> removeList = new ArrayList<IBinder>();
         synchronized (mRecords) {
             mSignalStrength = signalStrength;
             for (Record r : mRecords) {
@@ -280,10 +283,11 @@
                         r.callback.onSignalStrengthChanged((gsmSignalStrength == 99 ? -1
                                 : gsmSignalStrength));
                     } catch (RemoteException ex) {
-                        remove(r.binder);
+                        removeList.add(r.binder);
                     }
                 }
             }
+            for (IBinder b : removeList) remove(b);
         }
         broadcastSignalStrengthChanged(signalStrength);
     }
@@ -292,6 +296,7 @@
         if (!checkNotifyPermission("notifyMessageWaitingChanged()")) {
             return;
         }
+        ArrayList<IBinder> removeList = new ArrayList<IBinder>();
         synchronized (mRecords) {
             mMessageWaiting = mwi;
             for (Record r : mRecords) {
@@ -299,10 +304,11 @@
                     try {
                         r.callback.onMessageWaitingIndicatorChanged(mwi);
                     } catch (RemoteException ex) {
-                        remove(r.binder);
+                        removeList.add(r.binder);
                     }
                 }
             }
+            for (IBinder b : removeList) remove(b);
         }
     }
 
@@ -310,6 +316,7 @@
         if (!checkNotifyPermission("notifyCallForwardingChanged()")) {
             return;
         }
+        ArrayList<IBinder> removeList = new ArrayList<IBinder>();
         synchronized (mRecords) {
             mCallForwarding = cfi;
             for (Record r : mRecords) {
@@ -317,10 +324,11 @@
                     try {
                         r.callback.onCallForwardingIndicatorChanged(cfi);
                     } catch (RemoteException ex) {
-                        remove(r.binder);
+                        removeList.add(r.binder);
                     }
                 }
             }
+            for (IBinder b : removeList) remove(b);
         }
     }
 
@@ -328,6 +336,7 @@
         if (!checkNotifyPermission("notifyDataActivity()" )) {
             return;
         }
+        ArrayList<IBinder> removeList = new ArrayList<IBinder>();
         synchronized (mRecords) {
             mDataActivity = state;
             for (Record r : mRecords) {
@@ -335,10 +344,11 @@
                     try {
                         r.callback.onDataActivity(state);
                     } catch (RemoteException ex) {
-                        remove(r.binder);
+                        removeList.add(r.binder);
                     }
                 }
             }
+            for (IBinder b : removeList) remove(b);
         }
     }
 
@@ -376,15 +386,17 @@
                 modified = true;
             }
             if (modified) {
+                ArrayList<IBinder> removeList = new ArrayList<IBinder>();
                 for (Record r : mRecords) {
                     if ((r.events & PhoneStateListener.LISTEN_DATA_CONNECTION_STATE) != 0) {
                         try {
                             r.callback.onDataConnectionStateChanged(state, networkType);
                         } catch (RemoteException ex) {
-                            remove(r.binder);
+                            removeList.add(r.binder);
                         }
                     }
                 }
+                for (IBinder b : removeList) remove(b);
             }
         }
         broadcastDataConnectionStateChanged(state, isDataConnectivityPossible, reason, apn,