Fix looking up of contacts for SIP calls.

Currently, for a SIP call we only look up whether there is a matching
SIP address on one of the contacts.

However, it is also possible to receive calls from regular phone numbers
on a SIP account, e.g., if there is a incoming calls number associated
with the account.

In those cases, the SIP address of the caller is of the form
<number>@<domain>.

This commit changes the look-up code for SIP calls in the call log to
fall back to looking up the <number> part of a SIP address if there is
not a match within the SIP addresses of contacts.

This is in line with what is already done for incoming and outgoing
calls placed via SIP to regular phone number.

Bug: 5390366
Change-Id: I98b359eee08a943f9cef719390bb8dcb4da09b67
diff --git a/src/com/android/contacts/calllog/CallLogAdapter.java b/src/com/android/contacts/calllog/CallLogAdapter.java
index 0bbf53c..d54a47e 100644
--- a/src/com/android/contacts/calllog/CallLogAdapter.java
+++ b/src/com/android/contacts/calllog/CallLogAdapter.java
@@ -400,7 +400,15 @@
         // Determine the contact info.
         if (PhoneNumberUtils.isUriNumber(number)) {
             // This "number" is really a SIP address.
-            info = queryContactInfoForSipAddress(number);
+            ContactInfo sipInfo = queryContactInfoForSipAddress(number);
+            if (sipInfo == null || sipInfo == ContactInfo.EMPTY) {
+                // Check whether the username is actually a phone number of contact.
+                String username = number.substring(0, number.indexOf('@'));
+                if (PhoneNumberUtils.isGlobalPhoneNumber(username)) {
+                    sipInfo = queryContactInfoForPhoneNumber(username);
+                }
+            }
+            info = sipInfo;
         } else {
             info = queryContactInfoForPhoneNumber(number);
         }