Protect add connections in CdmaConferenceController by a synchronized
pending set.

It's possible that we add same connections to CdmaConferenceController
for multiple times. Some of them can pass the duplication check and
cause unexpected conference connection creation. Protect the addInternal
with a synchronized set, only connections can be successfully added to
this set can be added to the controller.

Bug: 185315467
Test: Manually emergency call test
Change-Id: I669632ce3cce7b381ded6fd1f56c882bdbc35cba
diff --git a/src/com/android/services/telephony/CdmaConferenceController.java b/src/com/android/services/telephony/CdmaConferenceController.java
index 8523a5f..a076ec8 100644
--- a/src/com/android/services/telephony/CdmaConferenceController.java
+++ b/src/com/android/services/telephony/CdmaConferenceController.java
@@ -20,11 +20,14 @@
 import android.telecom.Connection;
 import android.telecom.DisconnectCause;
 import android.telecom.PhoneAccountHandle;
+import android.util.ArraySet;
 
 import com.android.phone.PhoneUtils;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
+import java.util.Set;
 
 /**
  * Manages CDMA conference calls. CDMA conference calls are much more limited than GSM conference
@@ -83,6 +86,9 @@
 
     private final Handler mHandler = new Handler();
 
+    private final Set<CdmaConnection> mPendingAddConnections = Collections.synchronizedSet(
+            new ArraySet<>());
+
     public CdmaConferenceController(TelephonyConnectionService connectionService) {
         mConnectionService = connectionService;
     }
@@ -91,7 +97,7 @@
     private CdmaConference mConference;
 
     void add(final CdmaConnection connection) {
-        if (mCdmaConnections.contains(connection)) {
+        if (mCdmaConnections.contains(connection) || !mPendingAddConnections.add(connection)) {
             // Adding a duplicate realistically shouldn't happen.
             Log.w(this, "add - connection already tracked; connection=%s", connection);
             return;
@@ -140,6 +146,7 @@
 
     private void addInternal(CdmaConnection connection) {
         mCdmaConnections.add(connection);
+        mPendingAddConnections.remove(connection);
         connection.addTelephonyConnectionListener(mTelephonyConnectionListener);
         recalculateConference();
     }