Merge "Add unit test for CEP at conference creation."
diff --git a/src/com/android/services/telephony/ImsConference.java b/src/com/android/services/telephony/ImsConference.java
index f7fcf64..73d6023 100644
--- a/src/com/android/services/telephony/ImsConference.java
+++ b/src/com/android/services/telephony/ImsConference.java
@@ -142,6 +142,14 @@
             }
         }
 
+        private boolean mIsMaximumConferenceSizeEnforced;
+
+        private int mMaximumConferenceSize;
+
+        private boolean mShouldLocalDisconnectEmptyConference;
+
+        private boolean mIsHoldAllowed;
+
         private CarrierConfiguration(boolean isMaximumConferenceSizeEnforced,
                 int maximumConferenceSize, boolean shouldLocalDisconnectEmptyConference,
                 boolean isHoldAllowed) {
@@ -151,14 +159,6 @@
             mIsHoldAllowed = isHoldAllowed;
         }
 
-        private boolean mIsMaximumConferenceSizeEnforced;
-
-        private int mMaximumConferenceSize;
-
-        private boolean mShouldLocalDisconnectEmptyConference;
-
-        private boolean mIsHoldAllowed;
-
         /**
          * Determines whether the {@link ImsConference} should enforce a size limit based on
          * {@link #getMaximumConferenceSize()}.
@@ -378,11 +378,10 @@
     private boolean mCouldManageConference;
     private FeatureFlagProxy mFeatureFlagProxy;
     private final CarrierConfiguration mCarrierConfig;
-    private boolean mIsEmulatingSinglePartyCall = false;
     private boolean mIsUsingSimCallManager = false;
 
     /**
-     * Where {@link #mIsEmulatingSinglePartyCall} is {@code true}, contains the
+     * Where {@link #isMultiparty()} is {@code false}, contains the
      * {@link ConferenceParticipantConnection#getUserEntity()} and
      * {@link ConferenceParticipantConnection#getEndpoint()} of the single participant which this
      * conference pretends to be.
@@ -808,7 +807,7 @@
         boolean couldManageConference =
                 (getConnectionCapabilities() & Connection.CAPABILITY_MANAGE_CONFERENCE) != 0;
         boolean canManageConference = mFeatureFlagProxy.isUsingSinglePartyCallEmulation()
-                && mIsEmulatingSinglePartyCall
+                && !isMultiparty()
                 ? mConferenceParticipantConnections.size() > 1
                 : mConferenceParticipantConnections.size() != 0;
         Log.v(this, "updateManageConference was :%s is:%s", couldManageConference ? "Y" : "N",
@@ -951,8 +950,8 @@
             // 1. We're not emulating a single party call.
             // 2. We're emulating a single party call and the CEP contains more than just the
             //    single party
-            if ((mIsEmulatingSinglePartyCall && !isSinglePartyConference) ||
-                !mIsEmulatingSinglePartyCall) {
+            if ((!isMultiparty() && !isSinglePartyConference)
+                    || isMultiparty()) {
                 // Add any new participants and update existing.
                 for (ConferenceParticipant participant : participants) {
                     Pair<Uri, Uri> userEntity = new Pair<>(participant.getHandle(),
@@ -1045,7 +1044,7 @@
                 if (oldParticipantCount != 1 && newParticipantCount == 1) {
                     // If number of participants goes to 1, emulate a single party call.
                     startEmulatingSinglePartyCall();
-                } else if (mIsEmulatingSinglePartyCall && !isSinglePartyConference) {
+                } else if (!isMultiparty() && !isSinglePartyConference) {
                     // Number of participants increased, so stop emulating a single party call.
                     stopEmulatingSinglePartyCall();
                 }
@@ -1087,7 +1086,6 @@
 
         Log.i(this, "stopEmulatingSinglePartyCall: conference now has more than one"
                 + " participant; make it look conference-like again.");
-        mIsEmulatingSinglePartyCall = false;
 
         if (mCouldManageConference) {
             int currentCapabilities = getConnectionCapabilities();
@@ -1137,7 +1135,6 @@
         Log.i(this, "startEmulatingSinglePartyCall: conference has a single "
                 + "participant; downgrade to single party call.");
 
-        mIsEmulatingSinglePartyCall = true;
         Iterator<ConferenceParticipantConnection> valueIterator =
                 mConferenceParticipantConnections.values().iterator();
         if (valueIterator.hasNext()) {
@@ -1493,14 +1490,6 @@
     }
 
     /**
-     * @return {@code True} if the ImsConference is emulating single party call.
-     */
-    @VisibleForTesting
-    public boolean isEmulatingSinglePartyCall() {
-        return mIsEmulatingSinglePartyCall;
-    }
-
-    /**
      * Handles destruction of a {@link ConferenceParticipantConnection}.
      * We remove the participant from the list of tracked participants in the conference and
      * update whether the conference can be managed.
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 19afe24..0c0cafa 100755
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -1981,7 +1981,7 @@
      */
     public List<ConferenceParticipant> getConferenceParticipants() {
         if (mOriginalConnection == null) {
-            Log.v(this, "Null mOriginalConnection, cannot get conf participants.");
+            Log.w(this, "Null mOriginalConnection, cannot get conf participants.");
             return null;
         }
         return mOriginalConnection.getConferenceParticipants();
diff --git a/tests/src/com/android/services/telephony/ImsConferenceTest.java b/tests/src/com/android/services/telephony/ImsConferenceTest.java
index b84aca1..f172d67 100644
--- a/tests/src/com/android/services/telephony/ImsConferenceTest.java
+++ b/tests/src/com/android/services/telephony/ImsConferenceTest.java
@@ -18,7 +18,6 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.never;
@@ -44,6 +43,7 @@
 
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.List;
 
 public class ImsConferenceTest {
     @Mock
@@ -373,7 +373,37 @@
                 Call.Details.DIRECTION_INCOMING);
         imsConference.handleConferenceParticipantsUpdate(mConferenceHost,
                 Arrays.asList(participant1));
-        assertTrue(imsConference.isEmulatingSinglePartyCall());
+        assertFalse(imsConference.isMultiparty());
+    }
+
+    /**
+     * Verify that the single party emulate correctly when the conference starts with a single
+     * party as part of the initial setup.  This mimics how an ImsCall can get CEP data prior to the
+     * ImsConference being created.
+     */
+    @Test
+    @SmallTest
+    public void testSinglePartyEmulationWithSinglePartyAtCreation() {
+        when(mMockTelecomAccountRegistry.isUsingSimCallManager(any(PhoneAccountHandle.class)))
+                .thenReturn(false);
+
+        ImsConference imsConference = new ImsConference(mMockTelecomAccountRegistry,
+                mMockTelephonyConnectionServiceProxy, mConferenceHost,
+                null /* phoneAccountHandle */, () -> true /* featureFlagProxy */,
+                new ImsConference.CarrierConfiguration.Builder().build());
+
+        ConferenceParticipant participant1 = new ConferenceParticipant(
+                Uri.parse("tel:6505551214"),
+                "A",
+                Uri.parse("sip:6505551214@testims.com"),
+                Connection.STATE_ACTIVE,
+                Call.Details.DIRECTION_INCOMING);
+        List<ConferenceParticipant> cps = Arrays.asList(participant1);
+        when(mConferenceHost.mMockRadioConnection.getConferenceParticipants())
+                .thenReturn(cps);
+        imsConference.updateConferenceParticipantsAfterCreation();
+
+        assertFalse(imsConference.isMultiparty());
     }
 
     /**
diff --git a/tests/src/com/android/services/telephony/TestTelephonyConnection.java b/tests/src/com/android/services/telephony/TestTelephonyConnection.java
index c36c405..09cec17 100644
--- a/tests/src/com/android/services/telephony/TestTelephonyConnection.java
+++ b/tests/src/com/android/services/telephony/TestTelephonyConnection.java
@@ -84,7 +84,7 @@
 
         mMockPhone = mock(Phone.class);
         mMockContext = mock(Context.class);
-        mOriginalConnection = mock(Connection.class);
+        mOriginalConnection = mMockRadioConnection;
         // Set up mMockRadioConnection and mMockPhone to contain an active call
         when(mMockRadioConnection.getState()).thenReturn(Call.State.ACTIVE);
         when(mOriginalConnection.getState()).thenReturn(Call.State.ACTIVE);