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

CallerInfoAsyncQuery

public class CallerInfoAsyncQuery extends Object
ASYNCHRONOUS QUERY API

Fields Summary
private static final boolean
DBG
private static final String
LOG_TAG
private static final int
EVENT_NEW_QUERY
private static final int
EVENT_ADD_LISTENER
private static final int
EVENT_END_OF_QUEUE
private static final int
EVENT_EMERGENCY_NUMBER
private static final int
EVENT_VOICEMAIL_NUMBER
private CallerInfoAsyncQueryHandler
mHandler
private static boolean
sSkipVmCheck
Constructors Summary
private CallerInfoAsyncQuery()
Private constructor for factory methods.

    
Methods Summary
public voidaddQueryListener(int token, com.android.internal.telephony.CallerInfoAsyncQuery$OnQueryCompleteListener listener, java.lang.Object cookie)
Method to add listeners to a currently running query


        if (DBG) log("adding listener to query: " + mHandler.mQueryUri + " handler: " + 
                mHandler.toString());
        
        //create cookieWrapper, add query request to end of queue.
        CookieWrapper cw = new CookieWrapper();
        cw.listener = listener;
        cw.cookie = cookie;
        cw.event = EVENT_ADD_LISTENER;
        
        mHandler.startQuery (token, cw, null, null, null, null, null);
    
private voidallocate(android.content.Context context, android.net.Uri contactRef)
Method to create a new CallerInfoAsyncQueryHandler object, ensuring correct state of context and uri.

        if ((context == null) || (contactRef == null)){
            throw new QueryPoolException("Bad context or query uri.");
        }
        mHandler = new CallerInfoAsyncQueryHandler(context);
        mHandler.mQueryContext = context;
        mHandler.mQueryUri = contactRef;
    
private static voidlog(java.lang.String msg)
static logging method

        Log.d(LOG_TAG, msg);
    
private voidrelease()
Releases the relevant data.

        mHandler.mQueryContext = null;
        mHandler.mQueryUri = null;
        mHandler.mCallerInfo = null;
        mHandler = null;
    
public static com.android.internal.telephony.CallerInfoAsyncQuerystartQuery(int token, android.content.Context context, android.net.Uri contactRef, com.android.internal.telephony.CallerInfoAsyncQuery$OnQueryCompleteListener listener, java.lang.Object cookie)
Factory method to start query with a Uri query spec

        
        CallerInfoAsyncQuery c = new CallerInfoAsyncQuery();
        c.allocate(context, contactRef);

        if (DBG) log("starting query for URI: " + contactRef + " handler: " + c.toString());
        
        //create cookieWrapper, start query
        CookieWrapper cw = new CookieWrapper();
        cw.listener = listener;
        cw.cookie = cookie;
        cw.event = EVENT_NEW_QUERY;
        
        c.mHandler.startQuery (token, cw, contactRef, null, null, null, null);
        
        return c;
    
public static com.android.internal.telephony.CallerInfoAsyncQuerystartQuery(int token, android.content.Context context, java.lang.String number, com.android.internal.telephony.CallerInfoAsyncQuery$OnQueryCompleteListener listener, java.lang.Object cookie)
Factory method to start query with a number

        //contruct the URI object and start Query.
        Uri contactRef = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL, number);
        
        CallerInfoAsyncQuery c = new CallerInfoAsyncQuery();
        c.allocate(context, contactRef);

        if (DBG) log("starting query for number: " + number + " handler: " + c.toString());
        
        //create cookieWrapper, start query
        CookieWrapper cw = new CookieWrapper();
        cw.listener = listener;
        cw.cookie = cookie;
        cw.number = number;

        // check to see if these are recognized numbers, and use shortcuts if we can. 
        if (PhoneNumberUtils.isEmergencyNumber(number)) {
            cw.event = EVENT_EMERGENCY_NUMBER;
        } else {
            String vmNumber = null;
            if (!sSkipVmCheck){
                try {
                    vmNumber = TelephonyManager.getDefault().getVoiceMailNumber();
                } 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;
                }
            }
            if (PhoneNumberUtils.compare(number, vmNumber)) { 
                cw.event = EVENT_VOICEMAIL_NUMBER;
            } else {
                cw.event = EVENT_NEW_QUERY;
            }
        }

        c.mHandler.startQuery (token, cw, contactRef, null, null, null, null);
        
        return c;