diff options
author | Nicolas Catania <niko@google.com> | 2010-01-05 16:03:08 -0800 |
---|---|---|
committer | Nicolas Catania <niko@google.com> | 2010-01-11 15:58:10 -0800 |
commit | c72509b4d815e23bfa563cfe96e04f54f2a221fe (patch) | |
tree | f1bcd22758e154f0d497076040433832a2ac3ff8 /telephony/java | |
parent | 0f5525ad3b9b341a6c288ded8a8a08572fc657c6 (diff) | |
download | frameworks_base-c72509b4d815e23bfa563cfe96e04f54f2a221fe.zip frameworks_base-c72509b4d815e23bfa563cfe96e04f54f2a221fe.tar.gz frameworks_base-c72509b4d815e23bfa563cfe96e04f54f2a221fe.tar.bz2 |
Fix the CallerInfo lookup when a phone URL is used.
Typically the CallerInfo is looked up based on a phone number, in which case the '_id' column
contains the contact id.
However when the lookup is based on a phone row, the '_id' column is the row number we queried.
The contact id is stored somewhere else in a 'contact_id' column.
The current fix, checks the mime type of the contactRef URL to find out which column contains
the contact id.
I think the contact DB should be more consistent and always return the contact id AS contact_id even
in the phone number scenario.
Bug:2269240
Diffstat (limited to 'telephony/java')
-rw-r--r-- | telephony/java/com/android/internal/telephony/CallerInfo.java | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/telephony/java/com/android/internal/telephony/CallerInfo.java b/telephony/java/com/android/internal/telephony/CallerInfo.java index 01b1746..cf89848 100644 --- a/telephony/java/com/android/internal/telephony/CallerInfo.java +++ b/telephony/java/com/android/internal/telephony/CallerInfo.java @@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.provider.ContactsContract.PhoneLookup; import android.provider.ContactsContract.CommonDataKinds.Phone; +import static android.provider.ContactsContract.RawContacts; import android.text.TextUtils; import android.telephony.TelephonyManager; import android.telephony.PhoneNumberUtils; @@ -118,7 +119,6 @@ public class CallerInfo { * number. The returned CallerInfo is null if no number is supplied. */ public static CallerInfo getCallerInfo(Context context, Uri contactRef, Cursor cursor) { - CallerInfo info = new CallerInfo(); info.photoResource = 0; info.phoneLabel = null; @@ -132,6 +132,9 @@ public class CallerInfo { if (cursor != null) { if (cursor.moveToFirst()) { + // TODO: photo_id is always available but not taken + // care of here. Maybe we should store it in the + // CallerInfo object as well. int columnIndex; @@ -160,10 +163,34 @@ public class CallerInfo { } } - // Look for the person ID - columnIndex = cursor.getColumnIndex(PhoneLookup._ID); + // 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); + + columnIndex = -1; + if (Phone.CONTENT_ITEM_TYPE.equals(mimeType)) { + // content://com.android.contacts/data/phones URL + 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. + columnIndex = cursor.getColumnIndex(PhoneLookup._ID); + } + if (columnIndex != -1) { info.person_id = cursor.getLong(columnIndex); + } else { + Log.e(TAG, "Column missing for " + contactRef); } // look for the custom ringtone, create from the string stored |