diff options
author | Wei Huang <weih@google.com> | 2010-04-08 11:33:26 -0700 |
---|---|---|
committer | Wei Huang <weih@google.com> | 2010-04-08 11:53:25 -0700 |
commit | 14595cbe9045755a5aa2bd28989c147c4709268c (patch) | |
tree | 63e894859b2335a5ae5a146a909fc86ec8d19c8f | |
parent | a882662df39eb5af84cc386fc09df4636166f48f (diff) | |
download | android_packages_providers_TelephonyProvider-14595cbe9045755a5aa2bd28989c147c4709268c.tar.gz android_packages_providers_TelephonyProvider-14595cbe9045755a5aa2bd28989c147c4709268c.tar.bz2 android_packages_providers_TelephonyProvider-14595cbe9045755a5aa2bd28989c147c4709268c.zip |
bug #2438230: add more logging for catching the bug.
- added some optimization for the single recipient case.
- more logging for creating new recipient id and thread id.
Change-Id: Idb46c550179afab5e00b62c53bd04ac77763797b
-rw-r--r-- | src/com/android/providers/telephony/MmsSmsProvider.java | 64 |
1 files changed, 44 insertions, 20 deletions
diff --git a/src/com/android/providers/telephony/MmsSmsProvider.java b/src/com/android/providers/telephony/MmsSmsProvider.java index bfe41ab..93668c1 100644 --- a/src/com/android/providers/telephony/MmsSmsProvider.java +++ b/src/com/android/providers/telephony/MmsSmsProvider.java @@ -456,6 +456,7 @@ public class MmsSmsProvider extends ContentProvider { String refinedAddress = isEmail ? address.toLowerCase() : address; String selection = "address=?"; String[] selectionArgs; + long retVal = -1L; if (isEmail) { selectionArgs = new String[] { refinedAddress }; @@ -478,12 +479,17 @@ public class MmsSmsProvider extends ContentProvider { contentValues.put(CanonicalAddressesColumns.ADDRESS, refinedAddress); db = mOpenHelper.getWritableDatabase(); - return db.insert("canonical_addresses", + retVal = db.insert("canonical_addresses", CanonicalAddressesColumns.ADDRESS, contentValues); + + Log.d(LOG_TAG, "getSingleAddressId: insert new canonical_address for " + address + + ", _id=" + retVal); + + return retVal; } if (cursor.moveToFirst()) { - return cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID)); + retVal = cursor.getLong(cursor.getColumnIndexOrThrow(BaseColumns._ID)); } } finally { if (cursor != null) { @@ -491,7 +497,7 @@ public class MmsSmsProvider extends ContentProvider { } } - return -1L; + return retVal; } /** @@ -506,7 +512,7 @@ public class MmsSmsProvider extends ContentProvider { if (id != -1L) { result.add(id); } else { - Log.e(LOG_TAG, "Address ID not found for: " + address); + Log.e(LOG_TAG, "getAddressIds: address ID not found for " + address); } } } @@ -524,7 +530,11 @@ public class MmsSmsProvider extends ContentProvider { for (Long number : numbers) { result[i++] = number; } - Arrays.sort(result); + + if (size > 1) { + Arrays.sort(result); + } + return result; } @@ -559,10 +569,16 @@ public class MmsSmsProvider extends ContentProvider { } values.put(ThreadsColumns.MESSAGE_COUNT, 0); - mOpenHelper.getWritableDatabase().insert("threads", null, values); + long result = mOpenHelper.getWritableDatabase().insert("threads", null, values); + Log.d(LOG_TAG, "insertThread: created new thread_id " + result + + " for recipientIds " + recipientIds); + getContext().getContentResolver().notifyChange(MmsSms.CONTENT_URI, null); } + private static final String THREAD_QUERY = + "SELECT _id FROM threads " + "WHERE recipient_ids=?"; + /** * Return the thread ID for this list of * recipients IDs. If no thread exists with this ID, create @@ -570,30 +586,38 @@ public class MmsSmsProvider extends ContentProvider { * Threads.getThreadId to access this information. */ private synchronized Cursor getThreadId(List<String> recipients) { - String recipientIds = - getSpaceSeparatedNumbers( - getSortedSet(getAddressIds(recipients))); + Set<Long> addressIds = getAddressIds(recipients); + String recipientIds = ""; - String THREAD_QUERY = "SELECT _id FROM threads " + "WHERE recipient_ids = ?"; + // optimize for size==1, which should be most of the cases + if (addressIds.size() == 1) { + for (Long addressId : addressIds) { + recipientIds = Long.toString(addressId); + } + } else { + recipientIds = getSpaceSeparatedNumbers(getSortedSet(addressIds)); + } - if (DEBUG) { - Log.v(LOG_TAG, "getThreadId THREAD_QUERY: " + THREAD_QUERY + - ", recipientIds=" + recipientIds); + if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { + Log.d(LOG_TAG, "getThreadId: recipientIds (selectionArgs) =" + recipientIds); } + + String[] selectionArgs = new String[] { recipientIds }; SQLiteDatabase db = mOpenHelper.getReadableDatabase(); - Cursor cursor = db.rawQuery(THREAD_QUERY, new String[] { recipientIds }); + Cursor cursor = db.rawQuery(THREAD_QUERY, selectionArgs); if (cursor.getCount() == 0) { cursor.close(); - if (DEBUG) { - Log.v(LOG_TAG, "getThreadId cursor zero, creating new threadid"); - } + + Log.d(LOG_TAG, "getThreadId: create new thread_id for recipients " + recipients); insertThread(recipientIds, recipients.size()); + db = mOpenHelper.getReadableDatabase(); // In case insertThread closed it - cursor = db.rawQuery(THREAD_QUERY, new String[] { recipientIds }); + cursor = db.rawQuery(THREAD_QUERY, selectionArgs); } - if (DEBUG) { - Log.v(LOG_TAG, "getThreadId cursor count: " + cursor.getCount()); + + if (cursor.getCount() > 1) { + Log.w(LOG_TAG, "getThreadId: why is cursorCount=" + cursor.getCount()); } return cursor; |