From 1d15dd7d273cbc4e8485af7fb02bc0564c6c0a8a Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Mon, 21 Jun 2010 12:15:26 -0700 Subject: [PATCH] Don't modify a list while iterating. Remember who we want to remove instead. Fixes concurrent modification exception. bug:2778958 Change-Id: If8827955e6a716fe39cc31fe5a092c613a6786d4 --- .../com/android/server/TelephonyRegistry.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/services/java/com/android/server/TelephonyRegistry.java b/services/java/com/android/server/TelephonyRegistry.java index 8fc4d570400f6..b1ca78525baa7 100644 --- a/services/java/com/android/server/TelephonyRegistry.java +++ b/services/java/com/android/server/TelephonyRegistry.java @@ -233,6 +233,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { if (!checkNotifyPermission("notifyCallState()")) { return; } + ArrayList removeList = new ArrayList(); synchronized (mRecords) { mCallState = state; mCallIncomingNumber = incomingNumber; @@ -241,10 +242,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { if (!checkNotifyPermission("notifySignalStrength()")) { return; } + ArrayList removeList = new ArrayList(); synchronized (mRecords) { mSignalStrength = signalStrength; for (Record r : mRecords) { @@ -280,10 +283,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { if (!checkNotifyPermission("notifyMessageWaitingChanged()")) { return; } + ArrayList removeList = new ArrayList(); synchronized (mRecords) { mMessageWaiting = mwi; for (Record r : mRecords) { @@ -299,10 +304,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { if (!checkNotifyPermission("notifyCallForwardingChanged()")) { return; } + ArrayList removeList = new ArrayList(); synchronized (mRecords) { mCallForwarding = cfi; for (Record r : mRecords) { @@ -317,10 +324,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { if (!checkNotifyPermission("notifyDataActivity()" )) { return; } + ArrayList removeList = new ArrayList(); synchronized (mRecords) { mDataActivity = state; for (Record r : mRecords) { @@ -335,10 +344,11 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { 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 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub { modified = true; } if (modified) { + ArrayList removeList = new ArrayList(); 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,