Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae946847 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add a lock for call add/remove operations to avoid...

Merge "Add a lock for call add/remove operations to avoid ConcurrentModificationException." am: 584003dd am: cb477fc4 am: d6217b06

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

Change-Id: Ie4e5c752570ac7181b81a6d1d49e2cfbf2769b0f
parents 3fe8ec2b d6217b06
Loading
Loading
Loading
Loading
+12 −4
Original line number Original line Diff line number Diff line
@@ -139,6 +139,8 @@ public final class Phone {
     */
     */
    private final int mTargetSdkVersion;
    private final int mTargetSdkVersion;


    private final Object mLock = new Object();

    Phone(InCallAdapter adapter, String callingPackage, int targetSdkVersion) {
    Phone(InCallAdapter adapter, String callingPackage, int targetSdkVersion) {
        mInCallAdapter = adapter;
        mInCallAdapter = adapter;
        mCallingPackage = callingPackage;
        mCallingPackage = callingPackage;
@@ -156,8 +158,12 @@ public final class Phone {
        if (call == null) {
        if (call == null) {
            call = new Call(this, parcelableCall.getId(), mInCallAdapter,
            call = new Call(this, parcelableCall.getId(), mInCallAdapter,
                    parcelableCall.getState(), mCallingPackage, mTargetSdkVersion);
                    parcelableCall.getState(), mCallingPackage, mTargetSdkVersion);

            synchronized (mLock) {
                mCallByTelecomCallId.put(parcelableCall.getId(), call);
                mCallByTelecomCallId.put(parcelableCall.getId(), call);
                mCalls.add(call);
                mCalls.add(call);
            }

            checkCallTree(parcelableCall);
            checkCallTree(parcelableCall);
            call.internalUpdate(parcelableCall, mCallByTelecomCallId);
            call.internalUpdate(parcelableCall, mCallByTelecomCallId);
            fireCallAdded(call);
            fireCallAdded(call);
@@ -169,8 +175,10 @@ public final class Phone {
    }
    }


    final void internalRemoveCall(Call call) {
    final void internalRemoveCall(Call call) {
        synchronized (mLock) {
            mCallByTelecomCallId.remove(call.internalGetCallId());
            mCallByTelecomCallId.remove(call.internalGetCallId());
            mCalls.remove(call);
            mCalls.remove(call);
        }


        InCallService.VideoCall videoCall = call.getVideoCall();
        InCallService.VideoCall videoCall = call.getVideoCall();
        if (videoCall != null) {
        if (videoCall != null) {