/** Factory method to start query with a number */
  public static CallerInfoAsyncQuery startQuery(
      int token, Context context, String number, OnQueryCompleteListener listener, Object cookie) {
    // contruct the URI object and start Query.
    Uri contactRef = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(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 if (PhoneNumberUtils.isVoiceMailNumber(number)) {
      cw.event = EVENT_VOICEMAIL_NUMBER;
    } else {
      cw.event = EVENT_NEW_QUERY;
    }

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

    return c;
  }
  /** Method to add listeners to a currently running query */
  public void addQueryListener(int token, OnQueryCompleteListener listener, Object cookie) {

    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);
  }
  /** Factory method to start query with a Uri query spec */
  public static CallerInfoAsyncQuery startQuery(
      int token, Context context, Uri contactRef, OnQueryCompleteListener listener, Object cookie) {

    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;
  }