Set number presentation to restricted if CEP participant has invalid Uri.

Per RFC5767, a SIP uri can contain the hostname "anonymous.invalid" if
the identity of the caller is unknown (e.g. blocked caller ID).  Added
code to pick up on this and set the number presentation for CEP
participants matching this pattern.  This prevents the
anonymousA@anonymous.invalid participant names associated with caller ID
blocked numbers from showing up.

Bug: 23753757
Change-Id: I7765db66e7c881ec87a9fc74ba51172d763ae61b
diff --git a/src/com/android/services/telephony/ConferenceParticipantConnection.java b/src/com/android/services/telephony/ConferenceParticipantConnection.java
index 5406ab5..4e7546d 100644
--- a/src/com/android/services/telephony/ConferenceParticipantConnection.java
+++ b/src/com/android/services/telephony/ConferenceParticipantConnection.java
@@ -29,6 +29,11 @@
  * Represents a participant in a conference call.
  */
 public class ConferenceParticipantConnection extends Connection {
+    /**
+     * RFC5767 states that a SIP URI with an unknown number should use an address of
+     * {@code anonymous@anonymous.invalid}.  E.g. the host name is anonymous.invalid.
+     */
+    private static final String ANONYMOUS_INVALID_HOST = "anonymous.invalid";
 
     /**
      * The user entity URI For the conference participant.
@@ -55,11 +60,19 @@
             ConferenceParticipant participant) {
 
         mParentConnection = parentConnection;
-        setAddress(getParticipantAddress(participant), PhoneConstants.PRESENTATION_ALLOWED);
-        setCallerDisplayName(participant.getDisplayName(), PhoneConstants.PRESENTATION_ALLOWED);
+        int presentation = getParticipantPresentation(participant);
+        Uri address;
+        if (presentation != PhoneConstants.PRESENTATION_ALLOWED) {
+            address = null;
+        } else {
+            address = getParticipantAddress(participant);
+        }
+        setAddress(address, presentation);
+        setCallerDisplayName(participant.getDisplayName(), presentation);
 
         mUserEntity = participant.getHandle();
         mEndpoint = participant.getEndpoint();
+
         setCapabilities();
     }
 
@@ -142,6 +155,43 @@
     }
 
     /**
+     * Determines the number presentation for a conference participant.  Per RFC5767, if the host
+     * name contains {@code anonymous.invalid} we can assume that there is no valid caller ID
+     * information for the caller, otherwise we'll assume that the URI can be shown.
+     *
+     * @param participant The conference participant.
+     * @return The number presentation.
+     */
+    private int getParticipantPresentation(ConferenceParticipant participant) {
+        Uri address = participant.getHandle();
+        if (address == null) {
+            return PhoneConstants.PRESENTATION_RESTRICTED;
+        }
+
+        String number = address.getSchemeSpecificPart();
+        // If no number, bail early and set restricted presentation.
+        if (TextUtils.isEmpty(number)) {
+            return PhoneConstants.PRESENTATION_RESTRICTED;
+        }
+
+        String numberParts[] = number.split("[@]");
+        // If we can't parse the host name out of the URI, then there is probably other data
+        // present, and is likely a valid SIP URI.
+        if (numberParts.length != 2) {
+            return PhoneConstants.PRESENTATION_ALLOWED;
+        }
+        String hostName = numberParts[1];
+
+        // If the hostname portion of the SIP URI is the invalid host string, presentation is
+        // restricted.
+        if (hostName.equals(ANONYMOUS_INVALID_HOST)) {
+            return PhoneConstants.PRESENTATION_RESTRICTED;
+        }
+
+        return PhoneConstants.PRESENTATION_ALLOWED;
+    }
+
+    /**
      * Attempts to build a tel: style URI from a conference participant.
      * Conference event package data contains SIP URIs, so we try to extract the phone number and
      * format into a typical tel: style URI.