FileDocCategorySizeDatePackage
CallerInfo.javaAPI DocAndroid 1.5 API12300Wed May 06 22:42:00 BST 2009com.android.internal.telephony

CallerInfo

public class CallerInfo extends Object
Looks up caller information for the given phone number. {@hide}

Fields Summary
private static final String
TAG
public static final String
UNKNOWN_NUMBER
public static final String
PRIVATE_NUMBER
public static final String
PAYPHONE_NUMBER
public String
name
Please note that, any one of these member variables can be null, and any accesses to them should be prepared to handle such a case. Also, it is implied that phoneNumber is more often populated than name is, (think of calls being dialed/received using numbers where names are not known to the device), so phoneNumber should serve as a dependable fallback when name is unavailable. One other detail here is that this CallerInfo object reflects information found on a connection, it is an OUTPUT that serves mainly to display information to the user. In no way is this object used as input to make a connection, so we can choose to display whatever human-readable text makes sense to the user for a connection. This is especially relevant for the phone number field, since it is the one field that is most likely exposed to the user. As an example: 1. User dials "911" 2. Device recognizes that this is an emergency number 3. We use the "Emergency Number" string instead of "911" in the phoneNumber field. What we're really doing here is treating phoneNumber as an essential field here, NOT name. We're NOT always guaranteed to have a name for a connection, but the number should be displayable.
public String
phoneNumber
public String
phoneLabel
public int
numberType
public String
numberLabel
public int
photoResource
public long
person_id
public boolean
needUpdate
public android.net.Uri
contactRefUri
public android.net.Uri
contactRingtoneUri
public boolean
shouldSendToVoicemail
public android.graphics.drawable.Drawable
cachedPhoto
Drawable representing the caller image. This is essentially a cache for the image data tied into the connection / callerinfo object. The isCachedPhotoCurrent flag indicates if the image data needs to be reloaded.
public boolean
isCachedPhotoCurrent
private static boolean
sSkipVmCheck
Constructors Summary
public CallerInfo()


      
    
Methods Summary
public static java.lang.StringgetCallerId(android.content.Context context, java.lang.String number)
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.

        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;
    
public static com.android.internal.telephony.CallerInfogetCallerInfo(android.content.Context context, android.net.Uri contactRef, android.database.Cursor cursor)
getCallerInfo given a Cursor.

param
context the context used to retrieve string constants
param
contactRef the URI to attach to this CallerInfo object
param
cursor the first object in the cursor is used to build the CallerInfo object.
return
the CallerInfo which contains the caller id for the given number. The returned CallerInfo is null if no number is supplied.

        
        CallerInfo info = new CallerInfo();
        info.photoResource = 0;
        info.phoneLabel = null;
        info.numberType = 0;
        info.numberLabel = null;
        info.cachedPhoto = null;
        info.isCachedPhotoCurrent = false;
        
        if (Config.LOGV) Log.v(TAG, "construct callerInfo from cursor");
        
        if (cursor != null) {
            if (cursor.moveToFirst()) {

                int columnIndex;

                // Look for the name
                columnIndex = cursor.getColumnIndex(People.NAME);
                if (columnIndex != -1) {
                    info.name = cursor.getString(columnIndex);
                }

                // Look for the number
                columnIndex = cursor.getColumnIndex(Phones.NUMBER);
                if (columnIndex != -1) {
                    info.phoneNumber = cursor.getString(columnIndex);
                }
                
                // Look for the label/type combo
                columnIndex = cursor.getColumnIndex(Phones.LABEL);
                if (columnIndex != -1) {
                    int typeColumnIndex = cursor.getColumnIndex(Phones.TYPE);
                    if (typeColumnIndex != -1) {
                        info.numberType = cursor.getInt(typeColumnIndex);
                        info.numberLabel = cursor.getString(columnIndex);
                        info.phoneLabel = Contacts.Phones.getDisplayLabel(context,
                                info.numberType, info.numberLabel)
                                .toString();
                    }
                }

                // Look for the person ID
                columnIndex = cursor.getColumnIndex(Phones.PERSON_ID);
                if (columnIndex != -1) {
                    info.person_id = cursor.getLong(columnIndex);
                } else {
                    columnIndex = cursor.getColumnIndex(People._ID);
                    if (columnIndex != -1) {
                        info.person_id = cursor.getLong(columnIndex);
                    }
                }
                
                // look for the custom ringtone, create from the string stored
                // in the database.
                columnIndex = cursor.getColumnIndex(People.CUSTOM_RINGTONE);
                if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) {
                    info.contactRingtoneUri = Uri.parse(cursor.getString(columnIndex));
                } else {
                    info.contactRingtoneUri = null;
                }

                // look for the send to voicemail flag, set it to true only
                // under certain circumstances.
                columnIndex = cursor.getColumnIndex(People.SEND_TO_VOICEMAIL);
                info.shouldSendToVoicemail = (columnIndex != -1) && 
                        ((cursor.getInt(columnIndex)) == 1);
            }
            cursor.close();
        }

        info.needUpdate = false;
        info.name = normalize(info.name);
        info.contactRefUri = contactRef;

        return info;
    
public static com.android.internal.telephony.CallerInfogetCallerInfo(android.content.Context context, android.net.Uri contactRef)
getCallerInfo given a URI, look up in the call-log database for the uri unique key.

param
context the context used to get the ContentResolver
param
contactRef the URI 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.

        
        return getCallerInfo(context, contactRef, 
                context.getContentResolver().query(contactRef, null, null, null, null));
    
public static com.android.internal.telephony.CallerInfogetCallerInfo(android.content.Context context, java.lang.String number)
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.

        if (TextUtils.isEmpty(number)) {
            return null;
        } else {
            // 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 (PhoneNumberUtils.isEmergencyNumber(number)) {
                CallerInfo ci = new CallerInfo();

                // Note we're setting the phone number here (refer to javadoc
                // comments at the top of CallerInfo class). 
                ci.phoneNumber = context.getString(
                        com.android.internal.R.string.emergency_call_dialog_number_for_display);
                return ci;
            } else {
                try {
                    if (!sSkipVmCheck && PhoneNumberUtils.compare(number,
                                TelephonyManager.getDefault().getVoiceMailNumber())) {
                        CallerInfo ci = new CallerInfo();

                        // Note we're setting the phone number here (refer to javadoc
                        // comments at the top of CallerInfo class). 
                        ci.phoneNumber = TelephonyManager.getDefault().getVoiceMailAlphaTag();
                        // TODO: FIND ANOTHER ICON
                        //info.photoResource = android.R.drawable.badge_voicemail;
                        return ci;
                    }
                } catch (SecurityException ex) {
                    // Don't crash if this process doesn't have permission to 
                    // retrieve VM number.  It's still allowed to look up caller info.
                    // But don't try it again.
                    sSkipVmCheck = true;
                }
            }
        }

        Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL,
                                              Uri.encode(number)); 
        
        CallerInfo info = getCallerInfo(context, contactUri);

        // 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;
    
private static java.lang.Stringnormalize(java.lang.String s)

        if (s == null || s.length() > 0) {
            return s;
        } else {
            return null;
        }