Don't modify a list while iterating.

Remember who we want to remove instead.  Fixes concurrent modification
exception.

bug:2778958
Change-Id: If8827955e6a716fe39cc31fe5a092c613a6786d4
This commit is contained in:
Robert Greenwalt
2010-06-21 12:15:26 -07:00
parent aba8d30225
commit 1d15dd7d27

View File

@ -233,6 +233,7 @@ class TelephonyRegistry extends ITelephonyRegistry.Stub {
if (!checkNotifyPermission("notifyCallState()")) {
return;
}
ArrayList<IBinder> removeList = new ArrayList<IBinder>();
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<IBinder> removeList = new ArrayList<IBinder>();
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<IBinder> removeList = new ArrayList<IBinder>();
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<IBinder> removeList = new ArrayList<IBinder>();
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<IBinder> removeList = new ArrayList<IBinder>();
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<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,