bug 2384418: fix bug in mms contact lookup.

- a portion of the mms contact lookup wasn't protected by the synchronization block, and that portion used a member variable 'mSelectionArgs[]', which contains the number to be looked up. If this code is accessed by different threads at the same time, mSelectionArgs[] could be overridden by a wrong number, causing the resulting contact info be bad. With the bad contact cache, future lookups by phone number would result in the wrong contact.

While I didn't reproduce this with release builds, I was able to write a test that looks up a bunch of numbers in thread 1, and another bunch in thread 2. I observed thread #2 overwritting mSelectionArgs[] for thread 1, causing contact lookup to create bad contact cache. I believe in practice this can happen as the MMS code does look up and create contact cache entries from different threads.

This problem should be in builds before ERE19. In ERE19, Dmitri added an optimization in the ContactInfoCache's contact lookup, which should result in contact lookup to fail (zero cursor) when mSelectionArgs[] is overwritten by a bad phone number. It'd be nice to confirm that, but bug 2384418 doesn't contain a bug report, and we don't know for sure which build it was found in.

In any case, this fix is straight forward and should fix the contact lookup.

Change-Id: I516ff7039bec47c1b7bdc7dd5e52347c004a5a13
diff --git a/src/com/android/mms/util/ContactInfoCache.java b/src/com/android/mms/util/ContactInfoCache.java
index 72a21c6..fa7d495 100644
--- a/src/com/android/mms/util/ContactInfoCache.java
+++ b/src/com/android/mms/util/ContactInfoCache.java
@@ -106,17 +106,9 @@
 
     private final Context mContext;
 
-    private String[] mContactInfoSelectionArgs = new String[1];
-
     // cached contact info
     private final HashMap<String, CacheEntry> mCache = new HashMap<String, CacheEntry>();
 
-    // for background cache rebuilding
-    private Thread mCacheRebuilder = null;
-    private Object mCacheRebuildLock = new Object();
-    private boolean mPhoneCacheInvalidated = false;
-    private boolean mEmailCacheInvalidated = false;
-
     /**
      * CacheEntry stores the caller id or email lookup info.
      */
@@ -294,7 +286,8 @@
 
         //if (LOCAL_DEBUG) log("queryContactInfoByNumber: number=" + number);
 
-        mContactInfoSelectionArgs[0] = number;
+        String contactInfoSelectionArgs[] = new String[1];
+        contactInfoSelectionArgs[0] = number;
 
         // We need to include the phone number in the selection string itself rather then
         // selection arguments, because SQLite needs to see the exact pattern of GLOB
@@ -305,7 +298,7 @@
                 PHONES_WITH_PRESENCE_URI,
                 CALLER_ID_PROJECTION,
                 selection,
-                mContactInfoSelectionArgs,
+                contactInfoSelectionArgs,
                 null);
 
         if (cursor == null) {
@@ -476,13 +469,14 @@
     private CacheEntry queryEmailDisplayName(String email) {
         CacheEntry entry = new CacheEntry();
 
-        mContactInfoSelectionArgs[0] = email;
+        String contactInfoSelectionArgs[] = new String[1];
+        contactInfoSelectionArgs[0] = email;
 
         Cursor cursor = SqliteWrapper.query(mContext, mContext.getContentResolver(),
                 EMAIL_WITH_PRESENCE_URI,
                 EMAIL_PROJECTION,
                 EMAIL_SELECTION,
-                mContactInfoSelectionArgs,
+                contactInfoSelectionArgs,
                 null);
 
         if (cursor != null) {