Merge "Move the downgraded conference property" am: f8ac8e9b02 am: 5e119ff2ba

Original change: https://android-review.googlesource.com/c/platform/packages/services/Telephony/+/1329327

Change-Id: I8b81a611faa07278ba57cee7e42162d1dd04fcf2
diff --git a/src/com/android/services/telephony/TelephonyConferenceController.java b/src/com/android/services/telephony/TelephonyConferenceController.java
index fd16d4b..228541a 100644
--- a/src/com/android/services/telephony/TelephonyConferenceController.java
+++ b/src/com/android/services/telephony/TelephonyConferenceController.java
@@ -177,7 +177,7 @@
     }
 
     private void recalculateConference() {
-        Set<Connection> conferencedConnections = new HashSet<>();
+        Set<TelephonyConnection> conferencedConnections = new HashSet<>();
         int numGsmConnections = 0;
 
         for (TelephonyConnection connection : mTelephonyConnections) {
@@ -254,7 +254,7 @@
                     PhoneAccountHandle phoneAccountHandle = null;
                     if (!conferencedConnections.isEmpty()) {
                         TelephonyConnection telephonyConnection =
-                                (TelephonyConnection) conferencedConnections.iterator().next();
+                                conferencedConnections.iterator().next();
                         phoneAccountHandle = PhoneUtils.makePstnPhoneAccountHandle(
                                 telephonyConnection.getPhone());
                     }
@@ -262,11 +262,31 @@
                     mTelephonyConference = new TelephonyConference(phoneAccountHandle);
                     Log.i(this, "Creating new TelephonyConference to hold conferenced connections."
                             + " conference=" + mTelephonyConference);
-                    for (Connection connection : conferencedConnections) {
+                    boolean isDowngradedConference = false;
+                    for (TelephonyConnection connection : conferencedConnections) {
                         Log.d(this, "Adding a connection to a conference call: %s %s",
                                 mTelephonyConference, connection);
+                        if ((connection.getConnectionProperties()
+                                & Connection.PROPERTY_IS_DOWNGRADED_CONFERENCE) != 0) {
+                            // Remove all instances of PROPERTY_IS_DOWNGRADED_CONFERENCE. This
+                            // property should only be set on the parent call (i.e. the newly
+                            // created TelephonyConference.
+                            Log.d(this, "Removing PROPERTY_IS_DOWNGRADED_CONFERENCE from connection"
+                                    + " %s", connection);
+                            int newProperties = connection.getConnectionProperties()
+                                    & ~Connection.PROPERTY_IS_DOWNGRADED_CONFERENCE;
+                            connection.setTelephonyConnectionProperties(newProperties);
+                            isDowngradedConference = true;
+                        }
                         mTelephonyConference.addTelephonyConnection(connection);
                     }
+                    // Reapply the downgraded-conference flag to the parent conference if it was on
+                    // one of the children.
+                    if (isDowngradedConference) {
+                        mTelephonyConference.setConnectionProperties(
+                                mTelephonyConference.getConnectionProperties()
+                                        | Connection.PROPERTY_IS_DOWNGRADED_CONFERENCE);
+                    }
                     mTelephonyConference.updateCallRadioTechAfterCreation();
                     mConnectionService.addConference(mTelephonyConference);
                 } else {