No longer update nor use the cached contact info.

This commit stops using and updating the cache contact info that is
stored in the call log. Since we need more and more details about the
contact, it does not make sense to keep on adding those in two places.

Change-Id: Ia9435a2fb0bc3dba0df710319709cca9b9bc97df
diff --git a/src/com/android/contacts/calllog/CallLogFragment.java b/src/com/android/contacts/calllog/CallLogFragment.java
index 331bb1f..7e0eac7 100644
--- a/src/com/android/contacts/calllog/CallLogFragment.java
+++ b/src/com/android/contacts/calllog/CallLogFragment.java
@@ -92,9 +92,6 @@
                 Calls.DATE,
                 Calls.DURATION,
                 Calls.TYPE,
-                Calls.CACHED_NAME,
-                Calls.CACHED_NUMBER_TYPE,
-                Calls.CACHED_NUMBER_LABEL,
                 Calls.COUNTRY_ISO};
 
         public static final int ID = 0;
@@ -102,10 +99,7 @@
         public static final int DATE = 2;
         public static final int DURATION = 3;
         public static final int CALL_TYPE = 4;
-        public static final int CALLER_NAME = 5;
-        public static final int CALLER_NUMBERTYPE = 6;
-        public static final int CALLER_NUMBERLABEL = 7;
-        public static final int COUNTRY_ISO = 8;
+        public static final int COUNTRY_ISO = 5;
     }
 
     /** The query to use for the phones table */
@@ -342,32 +336,6 @@
             mContactInfoCache.expireAll();
         }
 
-        private void updateCallLog(CallerInfoQuery ciq, ContactInfo ci) {
-            // Check if they are different. If not, don't update.
-            if (TextUtils.equals(ciq.name, ci.name)
-                    && TextUtils.equals(ciq.numberLabel, ci.label)
-                    && ciq.numberType == ci.type
-                    && ciq.photoId == ci.photoId
-                    && ciq.lookupKey == ci.lookupKey) {
-                return;
-            }
-            ContentValues values = new ContentValues(3);
-            values.put(Calls.CACHED_NAME, ci.name);
-            values.put(Calls.CACHED_NUMBER_TYPE, ci.type);
-            values.put(Calls.CACHED_NUMBER_LABEL, ci.label);
-
-            try {
-                getActivity().getContentResolver().update(Calls.CONTENT_URI_WITH_VOICEMAIL, values,
-                        Calls.NUMBER + "='" + ciq.number + "'", null);
-            } catch (SQLiteDiskIOException e) {
-                Log.w(TAG, "Exception while updating call info", e);
-            } catch (SQLiteFullException e) {
-                Log.w(TAG, "Exception while updating call info", e);
-            } catch (SQLiteDatabaseCorruptException e) {
-                Log.w(TAG, "Exception while updating call info", e);
-            }
-        }
-
         private void enqueueRequest(String number, boolean immediate, int position,
                 String name, int numberType, String numberLabel, long photoId, String lookupKey) {
             CallerInfoQuery ciq = new CallerInfoQuery();
@@ -505,9 +473,6 @@
                     needNotify = true;
                 }
             }
-            if (info != null) {
-                updateCallLog(ciq, info);
-            }
             return needNotify;
         }
 
@@ -672,9 +637,6 @@
             long date = c.getLong(CallLogQuery.DATE);
             int callType = c.getInt(CallLogQuery.CALL_TYPE);
             final String formattedNumber;
-            String callerName = c.getString(CallLogQuery.CALLER_NAME);
-            int callerNumberType = c.getInt(CallLogQuery.CALLER_NUMBERTYPE);
-            String callerNumberLabel = c.getString(CallLogQuery.CALLER_NUMBERLABEL);
             String countryIso = c.getString(CallLogQuery.COUNTRY_ISO);
             // Store away the number so we can call it directly if you click on the call icon
             if (views.callView != null) {
@@ -694,22 +656,9 @@
                 mContactInfoCache.put(number, info);
                 Log.d(TAG, "Contact info missing: " + number);
                 // Request the contact details immediately since they are currently missing.
-                enqueueRequest(number, true, c.getPosition(),
-                        callerName, callerNumberType, callerNumberLabel, 0L, "");
+                enqueueRequest(number, true, c.getPosition(), "", 0, "", 0L, "");
             } else if (info != ContactInfo.EMPTY) { // Has been queried
-                // Check if any data is different from the data cached in the
-                // calls db. If so, queue the request so that we can update
-                // the calls db.
-                if (!TextUtils.equals(info.name, callerName)
-                        || info.type != callerNumberType
-                        || !TextUtils.equals(info.label, callerNumberLabel)) {
-                    // Something is amiss, so sync up.
-                    Log.w(TAG, "Contact info inconsistent: " + number);
-                    // Request the contact details immediately since they are probably wrong.
-                    enqueueRequest(number, true, c.getPosition(),
-                            callerName, callerNumberType, callerNumberLabel, info.photoId,
-                            info.lookupKey);
-                } else if (cachedInfo.isExpired()) {
+                if (cachedInfo.isExpired()) {
                     Log.d(TAG, "Contact info expired: " + number);
                     // Put it back in the cache, therefore marking it as not expired, so that other
                     // entries with the same number will not re-request it.
@@ -737,15 +686,6 @@
             String label = info.label;
             long photoId = info.photoId;
             String lookupKey = info.lookupKey;
-            // If there's no name cached in our hashmap, but there's one in the
-            // calls db, use the one in the calls db. Otherwise the name in our
-            // hashmap is more recent, so it has precedence.
-            if (TextUtils.isEmpty(name) && !TextUtils.isEmpty(callerName)) {
-                name = callerName;
-                ntype = callerNumberType;
-                label = callerNumberLabel;
-            }
-
             // Assumes the call back feature is on most of the
             // time. For private and unknown numbers: hide it.
             if (views.callView != null) {
@@ -792,6 +732,10 @@
         public void disableRequestProcessingForTest() {
             mRequestProcessingDisabled = true;
         }
+
+        public void injectContactInfoForTest(String number, ContactInfo contactInfo) {
+            mContactInfoCache.put(number, contactInfo);
+        }
     }
 
     private static final class QueryHandler extends AsyncQueryHandler {
diff --git a/tests/src/com/android/contacts/activities/CallLogActivityTests.java b/tests/src/com/android/contacts/activities/CallLogActivityTests.java
index 2eac88e..8db291d 100644
--- a/tests/src/com/android/contacts/activities/CallLogActivityTests.java
+++ b/tests/src/com/android/contacts/activities/CallLogActivityTests.java
@@ -18,6 +18,7 @@
 
 import com.android.contacts.R;
 import com.android.contacts.calllog.CallLogFragment;
+import com.android.contacts.calllog.CallLogFragment.ContactInfo;
 import com.android.contacts.calllog.CallLogListItemViews;
 import com.android.internal.telephony.CallerInfo;
 
@@ -27,6 +28,7 @@
 import android.graphics.drawable.BitmapDrawable;
 import android.provider.CallLog.Calls;
 import android.provider.ContactsContract.CommonDataKinds.Phone;
+import android.telephony.PhoneNumberUtils;
 import android.test.ActivityInstrumentationTestCase2;
 import android.test.suitebuilder.annotation.LargeTest;
 import android.test.suitebuilder.annotation.MediumTest;
@@ -51,21 +53,27 @@
 @LargeTest
 public class CallLogActivityTests
         extends ActivityInstrumentationTestCase2<CallLogActivity> {
-    static private final String TAG = "CallLogActivityTests";
-    static private final String[] CALL_LOG_PROJECTION = new String[] {
+    private static final String TAG = "CallLogActivityTests";
+
+    private static final String[] CALL_LOG_PROJECTION = new String[] {
             Calls._ID,
             Calls.NUMBER,
             Calls.DATE,
             Calls.DURATION,
             Calls.TYPE,
-            Calls.CACHED_NAME,
-            Calls.CACHED_NUMBER_TYPE,
-            Calls.CACHED_NUMBER_LABEL,
             Calls.COUNTRY_ISO,
     };
-    static private final int RAND_DURATION = -1;
-    static private final long NOW = -1L;
+    private static final int RAND_DURATION = -1;
+    private static final long NOW = -1L;
 
+    /** A test value for the person id of a contact. */
+    private static final long TEST_PERSON_ID = 1;
+    /** A test value for the photo id of a contact. */
+    private static final long TEST_PHOTO_ID = 2;
+    /** A test value for the lookup key for contacts. */
+    private static final String TEST_LOOKUP_KEY = "contact_id";
+    /** A test value for the country ISO of the phone number in the call log. */
+    private static final String TEST_COUNTRY_ISO = "US";
     /** A phone number to be used in tests. */
     private static final String TEST_NUMBER = "12125551000";
     /** The formatted version of {@link #TEST_NUMBER}. */
@@ -380,6 +388,32 @@
      */
     private void insertWithCachedValues(String number, long date, int duration, int type,
             String cachedName, int cachedNumberType, String cachedNumberLabel) {
+        insert(number, date, duration, type);
+        ContactInfo contactInfo = new ContactInfo();
+        contactInfo.personId = TEST_PERSON_ID;
+        contactInfo.name = cachedName;
+        contactInfo.type = cachedNumberType;
+        contactInfo.label = cachedNumberLabel;
+        String formattedNumber = PhoneNumberUtils.formatNumber(number, TEST_COUNTRY_ISO);
+        if (formattedNumber == null) {
+            formattedNumber = number;
+        }
+        contactInfo.formattedNumber = formattedNumber;
+        contactInfo.normalizedNumber = number;
+        contactInfo.photoId = TEST_PHOTO_ID;
+        contactInfo.lookupKey = TEST_LOOKUP_KEY;
+        mAdapter.injectContactInfoForTest(number, contactInfo);
+    }
+
+    /**
+     * Insert a new call entry in the test DB.
+     * @param number The phone number. For unknown and private numbers,
+     *               use CallerInfo.UNKNOWN_NUMBER or CallerInfo.PRIVATE_NUMBER.
+     * @param date In millisec since epoch. Use NOW to use the current time.
+     * @param duration In seconds of the call. Use RAND_DURATION to pick a random one.
+     * @param type Either Call.OUTGOING_TYPE or Call.INCOMING_TYPE or Call.MISSED_TYPE.
+     */
+    private void insert(String number, long date, int duration, int type) {
         MatrixCursor.RowBuilder row = mCursor.newRow();
         row.add(mIndex);
         mIndex ++;
@@ -397,22 +431,7 @@
             assertEquals(Calls.OUTGOING_TYPE, type);
         }
         row.add(type);  // type
-        row.add(cachedName);  // cached name
-        row.add(cachedNumberType);  // cached number type
-        row.add(cachedNumberLabel);  // cached number label
-        row.add("US");  // country ISO
-    }
-
-    /**
-     * Insert a new call entry in the test DB.
-     * @param number The phone number. For unknown and private numbers,
-     *               use CallerInfo.UNKNOWN_NUMBER or CallerInfo.PRIVATE_NUMBER.
-     * @param date In millisec since epoch. Use NOW to use the current time.
-     * @param duration In seconds of the call. Use RAND_DURATION to pick a random one.
-     * @param type Either Call.OUTGOING_TYPE or Call.INCOMING_TYPE or Call.MISSED_TYPE.
-     */
-    private void insert(String number, long date, int duration, int type) {
-        insertWithCachedValues(number, date, duration, type, "", Phone.TYPE_HOME, "");
+        row.add(TEST_COUNTRY_ISO);  // country ISO
     }
 
     /**