FileDocCategorySizeDatePackage
CallerInfoAsyncQuery.javaAPI DocAndroid 5.1 API20819Thu Mar 12 22:22:42 GMT 2015com.android.internal.telephony

CallerInfoAsyncQuery

public class CallerInfoAsyncQuery extends Object
Helper class to make it easier to run asynchronous caller-id lookup queries.
see
CallerInfo {@hide}

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 final boolean
ENABLE_UNKNOWN_NUMBER_GEO_DESCRIPTION
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) Rlog.d(LOG_TAG, "adding listener to query: " + sanitizeUriToString(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.mQueryUri = contactRef;
    
static android.content.ContentResolvergetCurrentProfileContentResolver(android.content.Context context)

return
{@link ContentResolver} for the "current" user.


        if (DBG) Rlog.d(LOG_TAG, "Trying to get current content resolver...");

        final int currentUser = ActivityManager.getCurrentUser();
        final int myUser = UserManager.get(context).getUserHandle();

        if (DBG) Rlog.d(LOG_TAG, "myUser=" + myUser + "currentUser=" + currentUser);

        if (myUser != currentUser) {
            final Context otherContext;
            try {
                otherContext = context.createPackageContextAsUser(context.getPackageName(),
                        /* flags =*/ 0, new UserHandle(currentUser));
                return otherContext.getContentResolver();
            } catch (NameNotFoundException e) {
                Rlog.e(LOG_TAG, "Can't find self package", e);
                // Fall back to the primary user.
            }
        }
        return context.getContentResolver();
    
private voidrelease()
Releases the relevant data.

        mHandler.mContext = null;
        mHandler.mQueryUri = null;
        mHandler.mCallerInfo = null;
        mHandler = null;
    
private static java.lang.StringsanitizeUriToString(android.net.Uri uri)

        if (uri != null) {
            String uriString = uri.toString();
            int indexOfLastSlash = uriString.lastIndexOf('/");
            if (indexOfLastSlash > 0) {
                return uriString.substring(0, indexOfLastSlash) + "/xxxxxxx";
            } else {
                return uriString;
            }
        } else {
            return "";
        }
    
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) Rlog.d(LOG_TAG, "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 the query based on a number. Note: if the number contains an "@" character we treat it as a SIP address, and look it up directly in the Data table rather than using the PhoneLookup table. TODO: But eventually we should expose two separate methods, one for numbers and one for SIP addresses, and then have PhoneUtils.startGetCallerInfo() decide which one to call based on the phone type of the incoming connection.


        int subId = SubscriptionManager.getDefaultSubId();
        return startQuery(token, context, number, listener, cookie, subId);
    
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, int subId)
Factory method to start the query based on a number with specific subscription. Note: if the number contains an "@" character we treat it as a SIP address, and look it up directly in the Data table rather than using the PhoneLookup table. TODO: But eventually we should expose two separate methods, one for numbers and one for SIP addresses, and then have PhoneUtils.startGetCallerInfo() decide which one to call based on the phone type of the incoming connection.


        if (DBG) {
            Rlog.d(LOG_TAG, "##### CallerInfoAsyncQuery startQuery()... #####");
            Rlog.d(LOG_TAG, "- number: " + /*number*/ "xxxxxxx");
            Rlog.d(LOG_TAG, "- cookie: " + cookie);
        }

        // Construct the URI object and query params, and start the query.

        final Uri contactRef = PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI.buildUpon()
                .appendPath(number)
                .appendQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS,
                        String.valueOf(PhoneNumberUtils.isUriNumber(number)))
                .build();

        if (DBG) {
            Rlog.d(LOG_TAG, "==> contactRef: " + sanitizeUriToString(contactRef));
        }

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

        //create cookieWrapper, start query
        CookieWrapper cw = new CookieWrapper();
        cw.listener = listener;
        cw.cookie = cookie;
        cw.number = number;
        cw.subId = subId;

        // check to see if these are recognized numbers, and use shortcuts if we can.
        if (PhoneNumberUtils.isLocalEmergencyNumber(context, number)) {
            cw.event = EVENT_EMERGENCY_NUMBER;
        } else if (PhoneNumberUtils.isVoiceMailNumber(subId, number)) {
            cw.event = EVENT_VOICEMAIL_NUMBER;
        } else {
            cw.event = EVENT_NEW_QUERY;
        }

        c.mHandler.startQuery(token,
                              cw,  // cookie
                              contactRef,  // uri
                              null,  // projection
                              null,  // selection
                              null,  // selectionArgs
                              null);  // orderBy
        return c;