Normalize the phone number before contact look up. DO NOT MERGE

The contact look-up request does not include a way to specify a
country which the number may correspond to. In the call log, we might
have calls that were placed or received while in one country and their
numbers will not match the contacts when the user is in a different
country.

To fix this issue, normalize the phone number using the country stored
in the call log together with the number itself and use that to look
up the contact.

Bug: 5252190
Change-Id: I55ca1c22bbfc2b59e279c7654ffa24a9c62367e6
diff --git a/src/com/android/contacts/calllog/ContactInfoHelper.java b/src/com/android/contacts/calllog/ContactInfoHelper.java
index c837c9a..e01ab47 100644
--- a/src/com/android/contacts/calllog/ContactInfoHelper.java
+++ b/src/com/android/contacts/calllog/ContactInfoHelper.java
@@ -185,13 +185,25 @@
     private ContactInfo queryContactInfoForPhoneNumber(String number, String countryIso) {
         final ContactInfo info;
 
-        // "number" is a regular phone number, so use the
+        String contactNumber = number;
+        if (!TextUtils.isEmpty(countryIso)) {
+            // Normalize the number: this is needed because the PhoneLookup query below does not
+            // accept a country code as an input.
+            String numberE164 = PhoneNumberUtils.formatNumberToE164(number, countryIso);
+            if (!TextUtils.isEmpty(numberE164)) {
+                // Only use it if the number could be formatted to E164.
+                contactNumber = numberE164;
+            }
+        }
+
+        // "contactNumber" is a regular phone number, so use the
         // PhoneLookup table:
         Cursor phonesCursor =
                 mContext.getContentResolver().query(
                     Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
-                            Uri.encode(number)),
+                            Uri.encode(contactNumber)),
                             PhoneQuery._PROJECTION, null, null, null);
+
         if (phonesCursor != null) {
             if (phonesCursor.moveToFirst()) {
                 info = new ContactInfo();