From 76855c20de037a38b02716642cd27be674772f2d Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Tue, 8 Jul 2014 17:56:03 -0700 Subject: Use enterprise caller-id in incall. - Use PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI for caller-id. - Removed a bunch of unused code. - Renamed fields that will have different semantics. e.g. contactId now will be 0 and lookupUri null for corp contacts. - Simplify the sip caller-id lookup. The regular caller-id lookup can also do SIP. The original code (http://ag/70555) was written before CP2 supported it (http://ag/147367). This needs QAing. - Instead of passing around a contact-id to later load a contact picture, use the picture URI returned from the API. Bug 15779911 Change-Id: Ia755b9079d03d9236f824c2f1102a6fa902b2097 --- InCallUI/src/com/android/incallui/CallerInfo.java | 112 ++++++---------------- 1 file changed, 27 insertions(+), 85 deletions(-) (limited to 'InCallUI/src/com/android/incallui/CallerInfo.java') diff --git a/InCallUI/src/com/android/incallui/CallerInfo.java b/InCallUI/src/com/android/incallui/CallerInfo.java index 1650fbb05..a5ab07c64 100644 --- a/InCallUI/src/com/android/incallui/CallerInfo.java +++ b/InCallUI/src/com/android/incallui/CallerInfo.java @@ -90,11 +90,19 @@ public class CallerInfo { public String numberLabel; public int photoResource; - public long person_id; - public String lookupKey; + + // Contact ID, which will be 0 if a contact comes from the corp CP2. + public long contactIdOrZero; + public String lookupKeyOrNull; public boolean needUpdate; public Uri contactRefUri; + /** + * Contact display photo URI. If a contact has no display photo but a thumbnail, it'll be + * the thumbnail URI instead. + */ + public Uri contactDisplayPhotoUri; + // fields to hold individual contact preference data, // including the send to voicemail flag and the ringtone // uri reference. @@ -204,15 +212,13 @@ public class CallerInfo { // Look for the person_id. columnIndex = getColumnIndexForPersonId(contactRef, cursor); if (columnIndex != -1) { - info.person_id = cursor.getLong(columnIndex); - Log.v(TAG, "==> got info.person_id: " + info.person_id); + info.contactIdOrZero = cursor.getLong(columnIndex); + Log.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero); // cache the lookup key for later use with person_id to create lookup URIs columnIndex = cursor.getColumnIndex(PhoneLookup.LOOKUP_KEY); - if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) { - info.lookupKey = cursor.getString(columnIndex); - } else { - info.lookupKey = null; + if (columnIndex != -1) { + info.lookupKeyOrNull = cursor.getString(columnIndex); } } else { // No valid columnIndex, so we can't look up person_id. @@ -222,6 +228,14 @@ public class CallerInfo { // the in-call UI, for example.) } + // Display photo URI. + columnIndex = cursor.getColumnIndex(PhoneLookup.PHOTO_URI); + if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) { + info.contactDisplayPhotoUri = Uri.parse(cursor.getString(columnIndex)); + } else { + info.contactDisplayPhotoUri = null; + } + // look for the custom ringtone, create from the string stored // in the database. columnIndex = cursor.getColumnIndex(PhoneLookup.CUSTOM_RINGTONE); @@ -256,52 +270,12 @@ public class CallerInfo { * @return the CallerInfo which contains the caller id for the given * number. The returned CallerInfo is null if no number is supplied. */ - public static CallerInfo getCallerInfo(Context context, Uri contactRef) { + private static CallerInfo getCallerInfo(Context context, Uri contactRef) { return getCallerInfo(context, contactRef, context.getContentResolver().query(contactRef, null, null, null, null)); } - /** - * getCallerInfo given a phone number, look up in the call-log database - * for the matching caller id info. - * @param context the context used to get the ContentResolver - * @param number the phone number used to lookup caller id - * @return the CallerInfo which contains the caller id for the given - * number. The returned CallerInfo is null if no number is supplied. If - * a matching number is not found, then a generic caller info is returned, - * with all relevant fields empty or null. - */ - public static CallerInfo getCallerInfo(Context context, String number) { - Log.v(TAG, "getCallerInfo() based on number..."); - - if (TextUtils.isEmpty(number)) { - return null; - } - - // Change the callerInfo number ONLY if it is an emergency number - // or if it is the voicemail number. If it is either, take a - // shortcut and skip the query. - if (PhoneNumberHelper.isLocalEmergencyNumber(number, context)) { - return new CallerInfo().markAsEmergency(context); - } else if (PhoneNumberUtils.isVoiceMailNumber(number)) { - return new CallerInfo().markAsVoiceMail(context); - } - - Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); - - CallerInfo info = getCallerInfo(context, contactUri); - info = doSecondaryLookupIfNecessary(context, number, info); - - // if no query results were returned with a viable number, - // fill in the original number value we used to query with. - if (TextUtils.isEmpty(info.phoneNumber)) { - info.phoneNumber = number; - } - - return info; - } - /** * Performs another lookup if previous lookup fails and it's a SIP call * and the peer's username is all numeric. Look up the username as it @@ -319,46 +293,13 @@ public class CallerInfo { String username = PhoneNumberHelper.getUsernameFromUriNumber(number); if (PhoneNumberUtils.isGlobalPhoneNumber(username)) { previousResult = getCallerInfo(context, - Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, + Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, Uri.encode(username))); } } return previousResult; } - /** - * getCallerId: a convenience method to get the caller id for a given - * number. - * - * @param context the context used to get the ContentResolver. - * @param number a phone number. - * @return if the number belongs to a contact, the contact's name is - * returned; otherwise, the number itself is returned. - * - * TODO NOTE: This MAY need to refer to the Asynchronous Query API - * [startQuery()], instead of getCallerInfo, but since it looks like - * it is only being used by the provider calls in the messaging app: - * 1. android.provider.Telephony.Mms.getDisplayAddress() - * 2. android.provider.Telephony.Sms.getDisplayAddress() - * We may not need to make the change. - */ - public static String getCallerId(Context context, String number) { - CallerInfo info = getCallerInfo(context, number); - String callerID = null; - - if (info != null) { - String name = info.name; - - if (!TextUtils.isEmpty(name)) { - callerID = name; - } else { - callerID = number; - } - } - - return callerID; - } - // Accessors /** @@ -589,10 +530,11 @@ public class CallerInfo { .append("\nnumberType: " + numberType) .append("\nnumberLabel: " + numberLabel) .append("\nphotoResource: " + photoResource) - .append("\nperson_id: " + person_id) + .append("\ncontactIdOrZero: " + contactIdOrZero) .append("\nneedUpdate: " + needUpdate) .append("\ncontactRefUri: " + contactRefUri) - .append("\ncontactRingtoneUri: " + contactRefUri) + .append("\ncontactRingtoneUri: " + contactRingtoneUri) + .append("\ncontactDisplayPhotoUri: " + contactDisplayPhotoUri) .append("\nshouldSendToVoicemail: " + shouldSendToVoicemail) .append("\ncachedPhoto: " + cachedPhoto) .append("\nisCachedPhotoCurrent: " + isCachedPhotoCurrent) -- cgit v1.2.3