Merge "Add a lock for call add/remove operations to avoid ConcurrentModificationException." am: 584003dd0d am: cb477fc498 am: d6217b06d8 am: ae946847f8

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1768612

Change-Id: I5751e51fabaace6826fbd4b48a70bcc7808bb54c
This commit is contained in:
Treehugger Robot
2021-07-16 13:08:45 +00:00
committed by Automerger Merge Worker

View File

@@ -139,6 +139,8 @@ public final class Phone {
*/
private final int mTargetSdkVersion;
private final Object mLock = new Object();
Phone(InCallAdapter adapter, String callingPackage, int targetSdkVersion) {
mInCallAdapter = adapter;
mCallingPackage = callingPackage;
@@ -156,8 +158,12 @@ public final class Phone {
if (call == null) {
call = new Call(this, parcelableCall.getId(), mInCallAdapter,
parcelableCall.getState(), mCallingPackage, mTargetSdkVersion);
mCallByTelecomCallId.put(parcelableCall.getId(), call);
mCalls.add(call);
synchronized (mLock) {
mCallByTelecomCallId.put(parcelableCall.getId(), call);
mCalls.add(call);
}
checkCallTree(parcelableCall);
call.internalUpdate(parcelableCall, mCallByTelecomCallId);
fireCallAdded(call);
@@ -169,8 +175,10 @@ public final class Phone {
}
final void internalRemoveCall(Call call) {
mCallByTelecomCallId.remove(call.internalGetCallId());
mCalls.remove(call);
synchronized (mLock) {
mCallByTelecomCallId.remove(call.internalGetCallId());
mCalls.remove(call);
}
InCallService.VideoCall videoCall = call.getVideoCall();
if (videoCall != null) {