Merge "Adjust testapps for API changes"
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index de60c61..2c4ebee 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -3239,6 +3239,21 @@
         return mPhone.isImsRegistered();
     }
 
+    /**
+     * {@hide}
+     * Returns the IMS Registration Status on a particular subid
+     *
+     * @param subId
+     */
+    public boolean isImsRegisteredForSubscriber(int subId) {
+        Phone phone = getPhone(subId);
+        if (phone != null) {
+            return phone.isImsRegistered();
+        } else {
+            return false;
+        }
+    }
+
     @Override
     public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) {
         return PhoneUtils.getSubIdForPhoneAccount(phoneAccount);
diff --git a/src/com/android/services/telephony/PstnIncomingCallNotifier.java b/src/com/android/services/telephony/PstnIncomingCallNotifier.java
index afb2cf6..c0ccc3a 100644
--- a/src/com/android/services/telephony/PstnIncomingCallNotifier.java
+++ b/src/com/android/services/telephony/PstnIncomingCallNotifier.java
@@ -141,8 +141,24 @@
             Connection connection = call.getLatestConnection();
             if (connection != null) {
                 String number = connection.getAddress();
-                if (!TextUtils.isEmpty(number) && Objects.equals(number, ccwi.number)) {
+                int presentation = connection.getNumberPresentation();
+
+                if (presentation != PhoneConstants.PRESENTATION_ALLOWED
+                        && presentation == ccwi.numberPresentation) {
+                    // Presentation of number not allowed, but the presentation of the Connection
+                    // and the call waiting presentation match.
+                    Log.i(this, "handleCdmaCallWaiting: inform telecom of waiting call; "
+                                    + "presentation = %d", presentation);
                     sendIncomingCallIntent(connection);
+                } else if (!TextUtils.isEmpty(number) && Objects.equals(number, ccwi.number)) {
+                    // Presentation of the number is allowed, so we ensure the number matches the
+                    // one in the call waiting information.
+                    Log.i(this, "handleCdmaCallWaiting: inform telecom of waiting call; "
+                            + "number = %s", Log.pii(number));
+                    sendIncomingCallIntent(connection);
+                } else {
+                    Log.w(this, "handleCdmaCallWaiting: presentation or number do not match, not"
+                            + " informing telecom of call: %s", ccwi);
                 }
             }
         }
diff --git a/src/com/android/services/telephony/TelephonyConferenceController.java b/src/com/android/services/telephony/TelephonyConferenceController.java
index 1386e19..acb41f6 100644
--- a/src/com/android/services/telephony/TelephonyConferenceController.java
+++ b/src/com/android/services/telephony/TelephonyConferenceController.java
@@ -161,14 +161,20 @@
 
         // Set the conference as conferenceable with all of the connections that are not in the
         // conference.
-        if (mTelephonyConference != null && !isFullConference(mTelephonyConference)) {
-            List<Connection> nonConferencedConnections = mTelephonyConnections
-                    .stream()
-                    // Only retrieve Connections that are not in a conference (but support
-                    // conferences).
-                    .filter(c -> c.isConferenceSupported() && c.getConference() == null)
-                    .collect(Collectors.toList());
-            mTelephonyConference.setConferenceableConnections(nonConferencedConnections);
+        if (mTelephonyConference != null) {
+            if (!isFullConference(mTelephonyConference)) {
+                List<Connection> nonConferencedConnections = mTelephonyConnections
+                        .stream()
+                        // Only retrieve Connections that are not in a conference (but support
+                        // conferences).
+                        .filter(c -> c.isConferenceSupported() && c.getConference() == null)
+                        .collect(Collectors.toList());
+                mTelephonyConference.setConferenceableConnections(nonConferencedConnections);
+            } else {
+                Log.d(this, "cannot merge anymore due it is full");
+                mTelephonyConference
+                        .setConferenceableConnections(Collections.<Connection>emptyList());
+            }
         }
         // TODO: Do not allow conferencing of already conferenced connections.
     }