Merge "Delay computing of PhoneNumber as much as possible."
diff --git a/src/com/android/contacts/CallDetailActivity.java b/src/com/android/contacts/CallDetailActivity.java
index d2c193e..3189b2d 100644
--- a/src/com/android/contacts/CallDetailActivity.java
+++ b/src/com/android/contacts/CallDetailActivity.java
@@ -419,8 +419,7 @@
                     numberText = candidateNumberText;
                 }
             }
-            return new PhoneCallDetails(number, numberText,
-                    mPhoneNumberHelper.parsePhoneNumber(number, countryIso),
+            return new PhoneCallDetails(number, numberText, countryIso,
                     new int[]{ callType }, date, duration,
                     nameText, numberType, numberLabel, personId, photoUri);
         } finally {
diff --git a/src/com/android/contacts/PhoneCallDetails.java b/src/com/android/contacts/PhoneCallDetails.java
index 0672673..347a303 100644
--- a/src/com/android/contacts/PhoneCallDetails.java
+++ b/src/com/android/contacts/PhoneCallDetails.java
@@ -16,8 +16,6 @@
 
 package com.android.contacts;
 
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
-
 import android.net.Uri;
 import android.provider.CallLog.Calls;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -30,8 +28,8 @@
     public final CharSequence number;
     /** The formatted version of {@link #number}. */
     public final CharSequence formattedNumber;
-    /** The structured phone number corresponding to {@link #number}. */
-    public final PhoneNumber structuredPhoneNumber;
+    /** The country corresponding with the phone number. */
+    public final String countryIso;
     /**
      * The type of calls, as defined in the call log table, e.g., {@link Calls#INCOMING_TYPE}.
      * <p>
@@ -58,19 +56,18 @@
 
     /** Create the details for a call with a number not associated with a contact. */
     public PhoneCallDetails(CharSequence number, CharSequence formattedNumber,
-            PhoneNumber structuredPhoneNumber, int[] callTypes, long date, long duration) {
-        this(number, formattedNumber, structuredPhoneNumber, callTypes, date, duration,
-                "", 0, "", -1L, null);
+            String countryIso, int[] callTypes, long date, long duration) {
+        this(number, formattedNumber, countryIso, callTypes, date, duration, "", 0, "", -1L, null);
     }
 
     /** Create the details for a call with a number associated with a contact. */
     public PhoneCallDetails(CharSequence number, CharSequence formattedNumber,
-            PhoneNumber structuredPhoneNumber, int[] callTypes, long date, long duration,
+            String countryIso, int[] callTypes, long date, long duration,
             CharSequence name, int numberType, CharSequence numberLabel, long personId,
             Uri photoUri) {
         this.number = number;
         this.formattedNumber = formattedNumber;
-        this.structuredPhoneNumber = structuredPhoneNumber;
+        this.countryIso = countryIso;
         this.callTypes = callTypes;
         this.date = date;
         this.duration = duration;
diff --git a/src/com/android/contacts/PhoneCallDetailsHelper.java b/src/com/android/contacts/PhoneCallDetailsHelper.java
index db3928e..2c36cec 100644
--- a/src/com/android/contacts/PhoneCallDetailsHelper.java
+++ b/src/com/android/contacts/PhoneCallDetailsHelper.java
@@ -118,7 +118,9 @@
             mPhoneNumberHelper.getDisplayNumber(details.number, details.formattedNumber);
         if (TextUtils.isEmpty(details.name)) {
             nameText = displayNumber;
-            numberText = mPhoneNumberHelper.getGeocodeForNumber(details.structuredPhoneNumber);
+            numberText = mPhoneNumberHelper.getGeocodeForNumber(
+                    mPhoneNumberHelper.parsePhoneNumber(
+                            details.number.toString(), details.countryIso));
         } else {
             nameText = details.name;
             if (numberFormattedLabel != null) {
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 1aa4d3d..32cc412 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -29,7 +29,6 @@
 import com.android.contacts.util.ExpirableCache;
 import com.android.internal.telephony.CallerInfo;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
 
 import android.app.ListFragment;
 import android.content.ContentUris;
@@ -669,13 +668,11 @@
             final String lookupKey = info.lookupKey;
             final int[] callTypes = getCallTypes(c, count);
             final PhoneCallDetails details;
-            PhoneNumber structuredPhoneNumber =
-                    mPhoneNumberHelper.parsePhoneNumber(number, countryIso);
             if (TextUtils.isEmpty(name)) {
-                details = new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber,
+                details = new PhoneCallDetails(number, formattedNumber, countryIso,
                         callTypes, date, duration);
             } else {
-                details = new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber,
+                details = new PhoneCallDetails(number, formattedNumber, countryIso,
                         callTypes, date, duration, name, ntype, label, personId, thumbnailUri);
             }
 
diff --git a/tests/src/com/android/contacts/PhoneCallDetailsHelperTest.java b/tests/src/com/android/contacts/PhoneCallDetailsHelperTest.java
index e228c3b..f02e7b0 100644
--- a/tests/src/com/android/contacts/PhoneCallDetailsHelperTest.java
+++ b/tests/src/com/android/contacts/PhoneCallDetailsHelperTest.java
@@ -20,7 +20,6 @@
 import com.android.contacts.calllog.PhoneNumberHelper;
 import com.android.contacts.util.LocaleTestUtils;
 import com.android.internal.telephony.CallerInfo;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
 
 import android.content.Context;
 import android.content.res.Resources;
@@ -231,20 +230,16 @@
 
     /** Sets the phone call details with default values and the given number. */
     private void setPhoneCallDetailsWithNumber(String number, String formattedNumber) {
-        PhoneNumber structuredPhoneNumber =
-                mPhoneNumberHelper.parsePhoneNumber(number, TEST_COUNTRY_ISO);
         mHelper.setPhoneCallDetails(mViews,
-                new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber,
+                new PhoneCallDetails(number, formattedNumber, TEST_COUNTRY_ISO,
                         new int[]{ Calls.INCOMING_TYPE }, TEST_DATE, TEST_DURATION),
                 false, false);
     }
 
     /** Sets the phone call details with default values and the given date. */
     private void setPhoneCallDetailsWithDate(long date) {
-        PhoneNumber structuredPhoneNumber =
-                mPhoneNumberHelper.parsePhoneNumber(TEST_NUMBER, TEST_COUNTRY_ISO);
         mHelper.setPhoneCallDetails(mViews,
-                new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, structuredPhoneNumber,
+                new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO,
                         new int[]{ Calls.INCOMING_TYPE }, date, TEST_DURATION),
                 false, false);
     }
@@ -260,10 +255,8 @@
     }
 
     private void setPhoneCallDetailsWithCallTypes(boolean useIcons, int... callTypes) {
-        PhoneNumber structuredPhoneNumber =
-                mPhoneNumberHelper.parsePhoneNumber(TEST_NUMBER, TEST_COUNTRY_ISO);
         mHelper.setPhoneCallDetails(mViews,
-                new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, structuredPhoneNumber,
+                new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO,
                         callTypes, TEST_DATE, TEST_DURATION),
                 useIcons, false);
     }
diff --git a/tests/src/com/android/contacts/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/contacts/calllog/CallLogListItemHelperTest.java
index 08d1e03..c56041e 100644
--- a/tests/src/com/android/contacts/calllog/CallLogListItemHelperTest.java
+++ b/tests/src/com/android/contacts/calllog/CallLogListItemHelperTest.java
@@ -21,7 +21,6 @@
 import com.android.contacts.PhoneCallDetailsViews;
 import com.android.contacts.R;
 import com.android.internal.telephony.CallerInfo;
-import com.google.i18n.phonenumbers.Phonenumber.PhoneNumber;
 
 import android.content.Context;
 import android.content.res.Resources;
@@ -124,20 +123,16 @@
 
     /** Sets the details of a phone call using the specified phone number. */
     private void setPhoneCallDetailsWithNumber(String number, String formattedNumber) {
-        PhoneNumber structuredPhoneNumber =
-                mPhoneNumberHelper.parsePhoneNumber(number, TEST_COUNTRY_ISO);
         mHelper.setPhoneCallDetails(mViews,
-                new PhoneCallDetails(number, formattedNumber, structuredPhoneNumber,
+                new PhoneCallDetails(number, formattedNumber, TEST_COUNTRY_ISO,
                         new int[]{ Calls.INCOMING_TYPE }, TEST_DATE, TEST_DURATION),
                 true, false);
     }
 
     /** Sets the details of a phone call using the specified call type. */
     private void setPhoneCallDetailsWithTypes(int... types) {
-        PhoneNumber structuredPhoneNumber =
-                mPhoneNumberHelper.parsePhoneNumber(TEST_NUMBER, TEST_COUNTRY_ISO);
         mHelper.setPhoneCallDetails(mViews,
-                new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, structuredPhoneNumber,
+                new PhoneCallDetails(TEST_NUMBER, TEST_FORMATTED_NUMBER, TEST_COUNTRY_ISO,
                         types, TEST_DATE, TEST_DURATION),
                 true, false);
     }