From 2e27a0be78bd9510785789caa14baa029051ca20 Mon Sep 17 00:00:00 2001 From: Wink Saville Date: Thu, 7 Oct 2010 08:28:34 -0700 Subject: Changed handling of onQueryCompelete to not use mimeType. Using mimeType causes an IPC request to contacts which can be slow. This can cause an ANR of the Phone app. This change parses the URL and to decide which column to use for the person_id and thus should not cause an ANR. bug: 3060704 Change-Id: I750c72746c7269e162f0338c0a3e00230a600519 --- .../com/android/internal/telephony/CallerInfo.java | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java index cf89848d54c0..360d35e358b4 100644 --- a/telephony/java/com/android/internal/telephony/CallerInfo.java +++ b/telephony/java/com/android/internal/telephony/CallerInfo.java @@ -26,9 +26,9 @@ import static android.provider.ContactsContract.RawContacts; import android.text.TextUtils; import android.telephony.TelephonyManager; import android.telephony.PhoneNumberUtils; -import android.util.Config; import android.util.Log; + /** * Looks up caller information for the given phone number. * @@ -36,6 +36,7 @@ import android.util.Log; */ public class CallerInfo { private static final String TAG = "CallerInfo"; + private static final boolean VDBG = Log.isLoggable(TAG, Log.VERBOSE); public static final String UNKNOWN_NUMBER = "-1"; public static final String PRIVATE_NUMBER = "-2"; @@ -128,7 +129,7 @@ public class CallerInfo { info.isCachedPhotoCurrent = false; info.contactExists = false; - if (Config.LOGV) Log.v(TAG, "construct callerInfo from cursor"); + if (VDBG) Log.v(TAG, "construct callerInfo from cursor"); if (cursor != null) { if (cursor.moveToFirst()) { @@ -166,31 +167,30 @@ public class CallerInfo { // Look for the person ID. // TODO: This is pretty ugly now, see bug 2269240 for - // more details. With tel: URI the contact id is in - // col "_id" while when we use a - // content://contacts/data/phones URI, the contact id - // is col "contact_id". As a work around we use the - // type of the contact url to figure out which column - // we should look at to get the contact_id. - - final String mimeType = context.getContentResolver().getType(contactRef); + // more details. The column to use depends upon the type of URL, + // for content://com.android.contacts/data/phones the "contact_id" + // column is used. For content/com.andriod.contacts/phone_lookup" + // the "_ID" column is used. If it is neither we leave columnIndex + // at -1 and no person ID will be available. columnIndex = -1; - if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)) { - // content://com.android.contacts/data/phones URL + String url = contactRef.toString(); + if (url.startsWith("content://com.android.contacts/data/phones")) { + if (VDBG) Log.v(TAG, + "URL path starts with 'data/phones' using RawContacts.CONTACT_ID"); columnIndex = cursor.getColumnIndex(RawContacts.CONTACT_ID); - } else { - // content://com.android.contacts/phone_lookup URL - // TODO: mime type is null here so we cannot test - // if we have the right url type. phone_lookup URL - // should resolve to a mime type. + } else if (url.startsWith("content://com.android.contacts/phone_lookup")) { + if (VDBG) Log.v(TAG, + "URL path starts with 'phone_lookup' using PhoneLookup._ID"); columnIndex = cursor.getColumnIndex(PhoneLookup._ID); + } else { + Log.e(TAG, "Bad contact URL '" + url + "'"); } if (columnIndex != -1) { info.person_id = cursor.getLong(columnIndex); } else { - Log.e(TAG, "Column missing for " + contactRef); + Log.e(TAG, "person_id column missing for " + contactRef); } // look for the custom ringtone, create from the string stored -- cgit v1.2.3-59-g8ed1b