Program: 152437
Project: 152437
Buggy source:
protected Cursor queryLocal(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder,long directoryId){
  if (VERBOSE_LOGGING) {
    Log.v(TAG,"String_Node_Str" + uri);
  }
  if (mActiveDb.get() == null) {
    mActiveDb.set(mContactsHelper.getReadableDatabase());
  }
  SQLiteQueryBuilder qb=new SQLiteQueryBuilder();
  String groupBy=null;
  String limit=getLimit(uri);
  boolean snippetDeferred=false;
  String addressBookIndexerCountExpression=null;
  final int match=sUriMatcher.match(uri);
switch (match) {
case SYNCSTATE:
case PROFILE_SYNCSTATE:
    return mDbHelper.get().getSyncState().query(mActiveDb.get(),projection,selection,selectionArgs,sortOrder);
case CONTACTS:
{
    setTablesAndProjectionMapForContacts(qb,uri,projection);
    appendLocalDirectorySelectionIfNeeded(qb,directoryId);
    break;
  }
case CONTACTS_ID:
{
  long contactId=ContentUris.parseId(uri);
  setTablesAndProjectionMapForContacts(qb,uri,projection);
  selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
  qb.appendWhere(Contacts._ID + "String_Node_Str");
  break;
}
case CONTACTS_LOOKUP:
case CONTACTS_LOOKUP_ID:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 3) {
  throw new IllegalArgumentException(mDbHelper.get().exceptionMessage("String_Node_Str",uri));
}
String lookupKey=pathSegments.get(2);
if (segmentCount == 4) {
  long contactId=Long.parseLong(pathSegments.get(3));
  SQLiteQueryBuilder lookupQb=new SQLiteQueryBuilder();
  setTablesAndProjectionMapForContacts(lookupQb,uri,projection);
  Cursor c=queryWithContactIdAndLookupKey(lookupQb,mActiveDb.get(),uri,projection,selection,selectionArgs,sortOrder,groupBy,limit,Contacts._ID,contactId,Contacts.LOOKUP_KEY,lookupKey);
  if (c != null) {
    return c;
  }
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(mActiveDb.get(),lookupKey)));
qb.appendWhere(Contacts._ID + "String_Node_Str");
break;
}
case CONTACTS_LOOKUP_DATA:
case CONTACTS_LOOKUP_ID_DATA:
case CONTACTS_LOOKUP_PHOTO:
case CONTACTS_LOOKUP_ID_PHOTO:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 4) {
throw new IllegalArgumentException(mDbHelper.get().exceptionMessage("String_Node_Str",uri));
}
String lookupKey=pathSegments.get(2);
if (segmentCount == 5) {
long contactId=Long.parseLong(pathSegments.get(3));
SQLiteQueryBuilder lookupQb=new SQLiteQueryBuilder();
setTablesAndProjectionMapForData(lookupQb,uri,projection,false);
if (match == CONTACTS_LOOKUP_PHOTO || match == CONTACTS_LOOKUP_ID_PHOTO) {
  qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str"+ Contacts.PHOTO_ID);
}
lookupQb.appendWhere("String_Node_Str");
Cursor c=queryWithContactIdAndLookupKey(lookupQb,mActiveDb.get(),uri,projection,selection,selectionArgs,sortOrder,groupBy,limit,Data.CONTACT_ID,contactId,Data.LOOKUP_KEY,lookupKey);
if (c != null) {
  return c;
}
}
setTablesAndProjectionMapForData(qb,uri,projection,false);
long contactId=lookupContactIdByLookupKey(mActiveDb.get(),lookupKey);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
if (match == CONTACTS_LOOKUP_PHOTO || match == CONTACTS_LOOKUP_ID_PHOTO) {
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str"+ Contacts.PHOTO_ID);
}
qb.appendWhere("String_Node_Str" + Data.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_ID_STREAM_ITEMS:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForStreamItems(qb);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere(StreamItems.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_LOOKUP_STREAM_ITEMS:
case CONTACTS_LOOKUP_ID_STREAM_ITEMS:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 4) {
throw new IllegalArgumentException(mDbHelper.get().exceptionMessage("String_Node_Str",uri));
}
String lookupKey=pathSegments.get(2);
if (segmentCount == 5) {
long contactId=Long.parseLong(pathSegments.get(3));
SQLiteQueryBuilder lookupQb=new SQLiteQueryBuilder();
setTablesAndProjectionMapForStreamItems(lookupQb);
Cursor c=queryWithContactIdAndLookupKey(lookupQb,mActiveDb.get(),uri,projection,selection,selectionArgs,sortOrder,groupBy,limit,StreamItems.CONTACT_ID,contactId,StreamItems.CONTACT_LOOKUP_KEY,lookupKey);
if (c != null) {
return c;
}
}
setTablesAndProjectionMapForStreamItems(qb);
long contactId=lookupContactIdByLookupKey(mActiveDb.get(),lookupKey);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere(RawContacts.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_AS_VCARD:
{
final String lookupKey=Uri.encode(uri.getPathSegments().get(2));
long contactId=lookupContactIdByLookupKey(mActiveDb.get(),lookupKey);
qb.setTables(Views.CONTACTS);
qb.setProjectionMap(sContactsVCardProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere(Contacts._ID + "String_Node_Str");
break;
}
case CONTACTS_AS_MULTI_VCARD:
{
SimpleDateFormat dateFormat=new SimpleDateFormat("String_Node_Str");
String currentDateString=dateFormat.format(new Date()).toString();
return mActiveDb.get().rawQuery("String_Node_Str" + "String_Node_Str" + OpenableColumns.DISPLAY_NAME + "String_Node_Str"+ "String_Node_Str"+ OpenableColumns.SIZE,new String[]{currentDateString});
}
case CONTACTS_FILTER:
{
String filterParam="String_Node_Str";
boolean deferredSnipRequested=deferredSnippetingRequested(uri);
if (uri.getPathSegments().size() > 2) {
filterParam=uri.getLastPathSegment();
}
setTablesAndProjectionMapForContactsWithSnippet(qb,uri,projection,filterParam,directoryId,deferredSnipRequested);
snippetDeferred=isSingleWordQuery(filterParam) && deferredSnipRequested && snippetNeeded(projection);
break;
}
case CONTACTS_STREQUENT_FILTER:
case CONTACTS_STREQUENT:
{
final boolean phoneOnly=readBooleanQueryParameter(uri,ContactsContract.STREQUENT_PHONE_ONLY,false);
if (match == CONTACTS_STREQUENT_FILTER && uri.getPathSegments().size() > 3) {
String filterParam=uri.getLastPathSegment();
StringBuilder sb=new StringBuilder();
sb.append(Contacts._ID + "String_Node_Str");
appendContactFilterAsNestedQuery(sb,filterParam);
selection=DbQueryUtils.concatenateClauses(selection,sb.toString());
}
String[] subProjection=null;
if (projection != null) {
subProjection=appendProjectionArg(projection,TIMES_USED_SORT_COLUMN);
}
setTablesAndProjectionMapForContacts(qb,uri,projection,false);
qb.setProjectionMap(phoneOnly ? sStrequentPhoneOnlyStarredProjectionMap : sStrequentStarredProjectionMap);
if (phoneOnly) {
qb.appendWhere(DbQueryUtils.concatenateClauses(selection,Contacts.HAS_PHONE_NUMBER + "String_Node_Str"));
}
qb.setStrict(true);
final String starredInnerQuery=qb.buildQuery(subProjection,Contacts.STARRED + "String_Node_Str",Contacts._ID,null,Contacts.DISPLAY_NAME + "String_Node_Str",null);
qb=new SQLiteQueryBuilder();
qb.setStrict(true);
final String frequentInnerQuery;
if (phoneOnly) {
final StringBuilder tableBuilder=new StringBuilder();
tableBuilder.append(Tables.DATA_USAGE_STAT + "String_Node_Str" + Views.DATA+ "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ DataUsageStatColumns.CONCRETE_DATA_ID+ "String_Node_Str"+ DataColumns.CONCRETE_ID+ "String_Node_Str"+ DataUsageStatColumns.CONCRETE_USAGE_TYPE+ "String_Node_Str"+ DataUsageStatColumns.USAGE_TYPE_INT_CALL+ "String_Node_Str");
appendContactPresenceJoin(tableBuilder,projection,RawContacts.CONTACT_ID);
appendContactStatusUpdateJoin(tableBuilder,projection,ContactsColumns.LAST_STATUS_UPDATE_ID);
qb.setTables(tableBuilder.toString());
qb.setProjectionMap(sStrequentPhoneOnlyFrequentProjectionMap);
final long phoneMimeTypeId=mDbHelper.get().getMimeTypeId(Phone.CONTENT_ITEM_TYPE);
final long sipMimeTypeId=mDbHelper.get().getMimeTypeId(SipAddress.CONTENT_ITEM_TYPE);
qb.appendWhere(DbQueryUtils.concatenateClauses(selection,Contacts.STARRED + "String_Node_Str" + Contacts.STARRED+ "String_Node_Str",DataColumns.MIMETYPE_ID + "String_Node_Str" + phoneMimeTypeId+ "String_Node_Str"+ sipMimeTypeId+ "String_Node_Str"));
frequentInnerQuery=qb.buildQuery(subProjection,null,null,null,TIMES_USED_SORT_COLUMN + "String_Node_Str","String_Node_Str");
}
 else {
setTablesAndProjectionMapForContacts(qb,uri,projection,true);
qb.setProjectionMap(sStrequentFrequentProjectionMap);
qb.appendWhere(DbQueryUtils.concatenateClauses(selection,"String_Node_Str" + Contacts.STARRED + "String_Node_Str"+ Contacts.STARRED+ "String_Node_Str"));
frequentInnerQuery=qb.buildQuery(subProjection,null,Contacts._ID,null,null,"String_Node_Str");
}
final String frequentQuery="String_Node_Str" + frequentInnerQuery + "String_Node_Str";
final String starredQuery="String_Node_Str" + starredInnerQuery + "String_Node_Str";
final String unionQuery=qb.buildUnionQuery(new String[]{starredQuery,frequentQuery},null,null);
String[] doubledSelectionArgs=null;
if (selectionArgs != null) {
final int length=selectionArgs.length;
doubledSelectionArgs=new String[length * 2];
System.arraycopy(selectionArgs,0,doubledSelectionArgs,0,length);
System.arraycopy(selectionArgs,0,doubledSelectionArgs,length,length);
}
Cursor cursor=mActiveDb.get().rawQuery(unionQuery,doubledSelectionArgs);
if (cursor != null) {
cursor.setNotificationUri(getContext().getContentResolver(),ContactsContract.AUTHORITY_URI);
}
return cursor;
}
case CONTACTS_FREQUENT:
{
setTablesAndProjectionMapForContacts(qb,uri,projection,true);
qb.setProjectionMap(sStrequentFrequentProjectionMap);
groupBy=Contacts._ID;
if (!TextUtils.isEmpty(sortOrder)) {
sortOrder=FREQUENT_ORDER_BY + "String_Node_Str" + sortOrder;
}
 else {
sortOrder=FREQUENT_ORDER_BY;
}
break;
}
case CONTACTS_GROUP:
{
setTablesAndProjectionMapForContacts(qb,uri,projection);
if (uri.getPathSegments().size() > 2) {
qb.appendWhere(CONTACTS_IN_GROUP_SELECT);
String groupMimeTypeId=String.valueOf(mDbHelper.get().getMimeTypeId(GroupMembership.CONTENT_ITEM_TYPE));
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
selectionArgs=insertSelectionArg(selectionArgs,groupMimeTypeId);
}
break;
}
case PROFILE:
{
setTablesAndProjectionMapForContacts(qb,uri,projection);
break;
}
case PROFILE_ENTITIES:
{
setTablesAndProjectionMapForEntities(qb,uri,projection);
break;
}
case PROFILE_AS_VCARD:
{
qb.setTables(Views.CONTACTS);
qb.setProjectionMap(sContactsVCardProjectionMap);
break;
}
case CONTACTS_ID_DATA:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere("String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_ID_PHOTO:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere("String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str");
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str"+ Contacts.PHOTO_ID);
break;
}
case CONTACTS_ID_ENTITIES:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForEntities(qb,uri,projection);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere("String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_LOOKUP_ENTITIES:
case CONTACTS_LOOKUP_ID_ENTITIES:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 4) {
throw new IllegalArgumentException(mDbHelper.get().exceptionMessage("String_Node_Str",uri));
}
String lookupKey=pathSegments.get(2);
if (segmentCount == 5) {
long contactId=Long.parseLong(pathSegments.get(3));
SQLiteQueryBuilder lookupQb=new SQLiteQueryBuilder();
setTablesAndProjectionMapForEntities(lookupQb,uri,projection);
lookupQb.appendWhere("String_Node_Str");
Cursor c=queryWithContactIdAndLookupKey(lookupQb,mActiveDb.get(),uri,projection,selection,selectionArgs,sortOrder,groupBy,limit,Contacts.Entity.CONTACT_ID,contactId,Contacts.Entity.LOOKUP_KEY,lookupKey);
if (c != null) {
return c;
}
}
setTablesAndProjectionMapForEntities(qb,uri,projection);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(mActiveDb.get(),lookupKey)));
qb.appendWhere("String_Node_Str" + Contacts.Entity.CONTACT_ID + "String_Node_Str");
break;
}
case STREAM_ITEMS:
{
setTablesAndProjectionMapForStreamItems(qb);
break;
}
case STREAM_ITEMS_ID:
{
setTablesAndProjectionMapForStreamItems(qb);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere(StreamItems._ID + "String_Node_Str");
break;
}
case STREAM_ITEMS_LIMIT:
{
MatrixCursor cursor=new MatrixCursor(new String[]{StreamItems.MAX_ITEMS},1);
cursor.addRow(new Object[]{MAX_STREAM_ITEMS_PER_RAW_CONTACT});
return cursor;
}
case STREAM_ITEMS_PHOTOS:
{
setTablesAndProjectionMapForStreamItemPhotos(qb);
break;
}
case STREAM_ITEMS_ID_PHOTOS:
{
setTablesAndProjectionMapForStreamItemPhotos(qb);
String streamItemId=uri.getPathSegments().get(1);
selectionArgs=insertSelectionArg(selectionArgs,streamItemId);
qb.appendWhere(StreamItemPhotosColumns.CONCRETE_STREAM_ITEM_ID + "String_Node_Str");
break;
}
case STREAM_ITEMS_ID_PHOTOS_ID:
{
setTablesAndProjectionMapForStreamItemPhotos(qb);
String streamItemId=uri.getPathSegments().get(1);
String streamItemPhotoId=uri.getPathSegments().get(3);
selectionArgs=insertSelectionArg(selectionArgs,streamItemPhotoId);
selectionArgs=insertSelectionArg(selectionArgs,streamItemId);
qb.appendWhere(StreamItemPhotosColumns.CONCRETE_STREAM_ITEM_ID + "String_Node_Str" + StreamItemPhotosColumns.CONCRETE_ID+ "String_Node_Str");
break;
}
case PHOTO_DIMENSIONS:
{
MatrixCursor cursor=new MatrixCursor(new String[]{DisplayPhoto.DISPLAY_MAX_DIM,DisplayPhoto.THUMBNAIL_MAX_DIM},1);
cursor.addRow(new Object[]{mMaxDisplayPhotoDim,mMaxThumbnailPhotoDim});
return cursor;
}
case PHONES:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForPhone());
final boolean removeDuplicates=readBooleanQueryParameter(uri,ContactsContract.REMOVE_DUPLICATE_ENTRIES,false);
if (removeDuplicates) {
groupBy=RawContacts.CONTACT_ID + "String_Node_Str" + Data.DATA1;
addressBookIndexerCountExpression="String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str"+ Data.DATA1;
}
break;
}
case PHONES_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForPhone());
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case PHONES_FILTER:
{
String typeParam=uri.getQueryParameter(DataUsageFeedback.USAGE_TYPE);
Integer typeInt=sDataUsageTypeMap.get(typeParam);
if (typeInt == null) {
typeInt=DataUsageStatColumns.USAGE_TYPE_INT_CALL;
}
setTablesAndProjectionMapForData(qb,uri,projection,true,typeInt);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForPhone());
if (uri.getPathSegments().size() > 2) {
String filterParam=uri.getLastPathSegment();
StringBuilder sb=new StringBuilder();
sb.append("String_Node_Str");
boolean hasCondition=false;
boolean orNeeded=false;
final String ftsMatchQuery=SearchIndexManager.getFtsMatchQuery(filterParam,FtsQueryBuilder.UNSCOPED_NORMALIZING);
if (ftsMatchQuery.length() > 0) {
sb.append(Data.RAW_CONTACT_ID + "String_Node_Str" + "String_Node_Str"+ RawContactsColumns.CONCRETE_ID+ "String_Node_Str"+ Tables.SEARCH_INDEX+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ Tables.SEARCH_INDEX+ "String_Node_Str"+ SearchIndexColumns.CONTACT_ID+ "String_Node_Str"+ RawContactsColumns.CONCRETE_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ SearchIndexColumns.NAME+ "String_Node_Str");
sb.append(ftsMatchQuery);
sb.append("String_Node_Str");
orNeeded=true;
hasCondition=true;
}
String number=PhoneNumberUtils.normalizeNumber(filterParam);
if (!TextUtils.isEmpty(number)) {
if (orNeeded) {
sb.append("String_Node_Str");
}
sb.append(Data._ID + "String_Node_Str" + PhoneLookupColumns.DATA_ID+ "String_Node_Str"+ Tables.PHONE_LOOKUP+ "String_Node_Str"+ PhoneLookupColumns.NORMALIZED_NUMBER+ "String_Node_Str");
sb.append(number);
sb.append("String_Node_Str");
hasCondition=true;
}
if (!hasCondition) {
sb.append("String_Node_Str");
}
sb.append("String_Node_Str");
qb.appendWhere(sb);
}
groupBy="String_Node_Str" + PhoneColumns.NORMALIZED_NUMBER + "String_Node_Str"+ PhoneColumns.NORMALIZED_NUMBER+ "String_Node_Str"+ Phone.NUMBER+ "String_Node_Str"+ RawContacts.CONTACT_ID;
if (sortOrder == null) {
final String accountPromotionSortOrder=getAccountPromotionSortOrder(uri);
if (!TextUtils.isEmpty(accountPromotionSortOrder)) {
sortOrder=accountPromotionSortOrder + "String_Node_Str" + PHONE_FILTER_SORT_ORDER;
}
 else {
sortOrder=PHONE_FILTER_SORT_ORDER;
}
}
break;
}
case EMAILS:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForEmail());
final boolean removeDuplicates=readBooleanQueryParameter(uri,ContactsContract.REMOVE_DUPLICATE_ENTRIES,false);
if (removeDuplicates) {
groupBy=RawContacts.CONTACT_ID + "String_Node_Str" + Data.DATA1;
addressBookIndexerCountExpression="String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str"+ Data.DATA1;
}
break;
}
case EMAILS_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForEmail()+ "String_Node_Str"+ Data._ID+ "String_Node_Str");
break;
}
case EMAILS_LOOKUP:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForEmail());
if (uri.getPathSegments().size() > 2) {
String email=uri.getLastPathSegment();
String address=mDbHelper.get().extractAddressFromEmailAddress(email);
selectionArgs=insertSelectionArg(selectionArgs,address);
qb.appendWhere("String_Node_Str" + Email.DATA + "String_Node_Str");
}
if (sortOrder == null) {
sortOrder="String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str"+ Tables.DEFAULT_DIRECTORY+ "String_Node_Str";
}
break;
}
case EMAILS_FILTER:
{
String typeParam=uri.getQueryParameter(DataUsageFeedback.USAGE_TYPE);
Integer typeInt=sDataUsageTypeMap.get(typeParam);
if (typeInt == null) {
typeInt=DataUsageStatColumns.USAGE_TYPE_INT_LONG_TEXT;
}
setTablesAndProjectionMapForData(qb,uri,projection,true,typeInt);
String filterParam=null;
if (uri.getPathSegments().size() > 3) {
filterParam=uri.getLastPathSegment();
if (TextUtils.isEmpty(filterParam)) {
filterParam=null;
}
}
if (filterParam == null) {
qb.appendWhere("String_Node_Str");
}
 else {
StringBuilder sb=new StringBuilder();
sb.append("String_Node_Str" + Data._ID + "String_Node_Str");
sb.append("String_Node_Str" + Data._ID + "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str");
sb.append(mDbHelper.get().getMimeTypeIdForEmail());
sb.append("String_Node_Str" + Data.DATA1 + "String_Node_Str");
DatabaseUtils.appendEscapedSQLString(sb,filterParam + '%');
if (!filterParam.contains("String_Node_Str")) {
sb.append("String_Node_Str" + Data._ID + "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str");
sb.append(mDbHelper.get().getMimeTypeIdForEmail());
sb.append("String_Node_Str" + Data.RAW_CONTACT_ID + "String_Node_Str"+ "String_Node_Str"+ RawContactsColumns.CONCRETE_ID+ "String_Node_Str"+ Tables.SEARCH_INDEX+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ Tables.SEARCH_INDEX+ "String_Node_Str"+ SearchIndexColumns.CONTACT_ID+ "String_Node_Str"+ RawContactsColumns.CONCRETE_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ SearchIndexColumns.NAME+ "String_Node_Str");
final String ftsMatchQuery=SearchIndexManager.getFtsMatchQuery(filterParam,FtsQueryBuilder.UNSCOPED_NORMALIZING);
sb.append(ftsMatchQuery);
sb.append("String_Node_Str");
}
sb.append("String_Node_Str");
qb.appendWhere(sb);
}
groupBy=Email.DATA + "String_Node_Str" + RawContacts.CONTACT_ID;
if (sortOrder == null) {
final String accountPromotionSortOrder=getAccountPromotionSortOrder(uri);
if (!TextUtils.isEmpty(accountPromotionSortOrder)) {
sortOrder=accountPromotionSortOrder + "String_Node_Str" + EMAIL_FILTER_SORT_ORDER;
}
 else {
sortOrder=EMAIL_FILTER_SORT_ORDER;
}
}
break;
}
case POSTALS:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForStructuredPostal());
final boolean removeDuplicates=readBooleanQueryParameter(uri,ContactsContract.REMOVE_DUPLICATE_ENTRIES,false);
if (removeDuplicates) {
groupBy=RawContacts.CONTACT_ID + "String_Node_Str" + Data.DATA1;
addressBookIndexerCountExpression="String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str"+ Data.DATA1;
}
break;
}
case POSTALS_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForStructuredPostal());
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case RAW_CONTACTS:
case PROFILE_RAW_CONTACTS:
{
setTablesAndProjectionMapForRawContacts(qb,uri);
break;
}
case RAW_CONTACTS_ID:
case PROFILE_RAW_CONTACTS_ID:
{
long rawContactId=ContentUris.parseId(uri);
setTablesAndProjectionMapForRawContacts(qb,uri);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere("String_Node_Str" + RawContacts._ID + "String_Node_Str");
break;
}
case RAW_CONTACTS_DATA:
case PROFILE_RAW_CONTACTS_ID_DATA:
{
int segment=match == RAW_CONTACTS_DATA ? 1 : 2;
long rawContactId=Long.parseLong(uri.getPathSegments().get(segment));
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere("String_Node_Str" + Data.RAW_CONTACT_ID + "String_Node_Str");
break;
}
case RAW_CONTACTS_ID_STREAM_ITEMS:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForStreamItems(qb);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere(StreamItems.RAW_CONTACT_ID + "String_Node_Str");
break;
}
case RAW_CONTACTS_ID_STREAM_ITEMS_ID:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
long streamItemId=Long.parseLong(uri.getPathSegments().get(3));
setTablesAndProjectionMapForStreamItems(qb);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(streamItemId));
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere(StreamItems.RAW_CONTACT_ID + "String_Node_Str" + StreamItems._ID+ "String_Node_Str");
break;
}
case PROFILE_RAW_CONTACTS_ID_ENTITIES:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(2));
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
setTablesAndProjectionMapForRawEntities(qb,uri);
qb.appendWhere("String_Node_Str" + RawContacts._ID + "String_Node_Str");
break;
}
case DATA:
case PROFILE_DATA:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
break;
}
case DATA_ID:
case PROFILE_DATA_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case PROFILE_PHOTO:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str"+ Contacts.PHOTO_ID);
break;
}
case PHONE_LOOKUP:
{
selection=null;
selectionArgs=null;
if (uri.getBooleanQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS,false)) {
if (TextUtils.isEmpty(sortOrder)) {
sortOrder=Contacts.DISPLAY_NAME + "String_Node_Str";
}
String sipAddress=uri.getPathSegments().size() > 1 ? Uri.decode(uri.getLastPathSegment()) : "String_Node_Str";
setTablesAndProjectionMapForData(qb,uri,null,false,true);
StringBuilder sb=new StringBuilder();
selectionArgs=mDbHelper.get().buildSipContactQuery(sb,sipAddress);
selection=sb.toString();
}
 else {
if (TextUtils.isEmpty(sortOrder)) {
sortOrder="String_Node_Str";
}
String number=uri.getPathSegments().size() > 1 ? uri.getLastPathSegment() : "String_Node_Str";
String numberE164=PhoneNumberUtils.formatNumberToE164(number,mDbHelper.get().getCurrentCountryIso());
String normalizedNumber=PhoneNumberUtils.normalizeNumber(number);
mDbHelper.get().buildPhoneLookupAndContactQuery(qb,normalizedNumber,numberE164);
qb.setProjectionMap(sPhoneLookupProjectionMap);
}
break;
}
case GROUPS:
{
qb.setTables(Views.GROUPS);
qb.setProjectionMap(sGroupsProjectionMap);
appendAccountFromParameter(qb,uri);
break;
}
case GROUPS_ID:
{
qb.setTables(Views.GROUPS);
qb.setProjectionMap(sGroupsProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere(Groups._ID + "String_Node_Str");
break;
}
case GROUPS_SUMMARY:
{
final boolean returnGroupCountPerAccount=readBooleanQueryParameter(uri,Groups.PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT,false);
String tables=Views.GROUPS + "String_Node_Str" + Tables.GROUPS;
if (hasColumn(projection,Groups.SUMMARY_COUNT)) {
tables=tables + Joins.GROUP_MEMBER_COUNT;
}
qb.setTables(tables);
qb.setProjectionMap(returnGroupCountPerAccount ? sGroupsSummaryProjectionMapWithGroupCountPerAccount : sGroupsSummaryProjectionMap);
appendAccountFromParameter(qb,uri);
groupBy=GroupsColumns.CONCRETE_ID;
break;
}
case AGGREGATION_EXCEPTIONS:
{
qb.setTables(Tables.AGGREGATION_EXCEPTIONS);
qb.setProjectionMap(sAggregationExceptionsProjectionMap);
break;
}
case AGGREGATION_SUGGESTIONS:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
String filter=null;
if (uri.getPathSegments().size() > 3) {
filter=uri.getPathSegments().get(3);
}
final int maxSuggestions;
if (limit != null) {
maxSuggestions=Integer.parseInt(limit);
}
 else {
maxSuggestions=DEFAULT_MAX_SUGGESTIONS;
}
ArrayList<AggregationSuggestionParameter> parameters=null;
List<String> query=uri.getQueryParameters("String_Node_Str");
if (query != null && !query.isEmpty()) {
parameters=new ArrayList<AggregationSuggestionParameter>(query.size());
for (String parameter : query) {
int offset=parameter.indexOf(':');
parameters.add(offset == -1 ? new AggregationSuggestionParameter(AggregationSuggestions.PARAMETER_MATCH_NAME,parameter) : new AggregationSuggestionParameter(parameter.substring(0,offset),parameter.substring(offset + 1)));
}
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
return mAggregator.get().queryAggregationSuggestions(qb,projection,contactId,maxSuggestions,filter,parameters);
}
case SETTINGS:
{
qb.setTables(Tables.SETTINGS);
qb.setProjectionMap(sSettingsProjectionMap);
appendAccountFromParameter(qb,uri);
final String groupMembershipMimetypeId=Long.toString(mDbHelper.get().getMimeTypeId(GroupMembership.CONTENT_ITEM_TYPE));
if (projection != null && projection.length != 0 && mDbHelper.get().isInProjection(projection,Settings.UNGROUPED_COUNT)) {
selectionArgs=insertSelectionArg(selectionArgs,groupMembershipMimetypeId);
}
if (projection != null && projection.length != 0 && mDbHelper.get().isInProjection(projection,Settings.UNGROUPED_WITH_PHONES)) {
selectionArgs=insertSelectionArg(selectionArgs,groupMembershipMimetypeId);
}
break;
}
case STATUS_UPDATES:
case PROFILE_STATUS_UPDATES:
{
setTableAndProjectionMapForStatusUpdates(qb,projection);
break;
}
case STATUS_UPDATES_ID:
{
setTableAndProjectionMapForStatusUpdates(qb,projection);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere(DataColumns.CONCRETE_ID + "String_Node_Str");
break;
}
case SEARCH_SUGGESTIONS:
{
return mGlobalSearchSupport.handleSearchSuggestionsQuery(mActiveDb.get(),uri,projection,limit);
}
case SEARCH_SHORTCUT:
{
String lookupKey=uri.getLastPathSegment();
String filter=getQueryParameter(uri,SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);
return mGlobalSearchSupport.handleSearchShortcutRefresh(mActiveDb.get(),projection,lookupKey,filter);
}
case RAW_CONTACT_ENTITIES:
case PROFILE_RAW_CONTACT_ENTITIES:
{
setTablesAndProjectionMapForRawEntities(qb,uri);
break;
}
case RAW_CONTACT_ENTITY_ID:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForRawEntities(qb,uri);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere("String_Node_Str" + RawContacts._ID + "String_Node_Str");
break;
}
case PROVIDER_STATUS:
{
return queryProviderStatus(uri,projection);
}
case DIRECTORIES:
{
qb.setTables(Tables.DIRECTORIES);
qb.setProjectionMap(sDirectoryProjectionMap);
break;
}
case DIRECTORIES_ID:
{
long id=ContentUris.parseId(uri);
qb.setTables(Tables.DIRECTORIES);
qb.setProjectionMap(sDirectoryProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(id));
qb.appendWhere(Directory._ID + "String_Node_Str");
break;
}
case COMPLETE_NAME:
{
return completeName(uri,projection);
}
default :
return mLegacyApiSupport.query(uri,projection,selection,selectionArgs,sortOrder,limit);
}
qb.setStrict(true);
Cursor cursor=query(mActiveDb.get(),qb,projection,selection,selectionArgs,sortOrder,groupBy,limit);
if (readBooleanQueryParameter(uri,ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS,false)) {
cursor=bundleLetterCountExtras(cursor,mActiveDb.get(),qb,selection,selectionArgs,sortOrder,addressBookIndexerCountExpression);
}
if (snippetDeferred) {
cursor=addDeferredSnippetingExtra(cursor);
}
return cursor;
}

Fixed version (ground truth):
protected Cursor queryLocal(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder,long directoryId){
  if (VERBOSE_LOGGING) {
    Log.v(TAG,"String_Node_Str" + uri);
  }
  if (mActiveDb.get() == null) {
    mActiveDb.set(mContactsHelper.getReadableDatabase());
  }
  SQLiteQueryBuilder qb=new SQLiteQueryBuilder();
  String groupBy=null;
  String limit=getLimit(uri);
  boolean snippetDeferred=false;
  String addressBookIndexerCountExpression=null;
  final int match=sUriMatcher.match(uri);
switch (match) {
case SYNCSTATE:
case PROFILE_SYNCSTATE:
    return mDbHelper.get().getSyncState().query(mActiveDb.get(),projection,selection,selectionArgs,sortOrder);
case CONTACTS:
{
    setTablesAndProjectionMapForContacts(qb,uri,projection);
    appendLocalDirectorySelectionIfNeeded(qb,directoryId);
    break;
  }
case CONTACTS_ID:
{
  long contactId=ContentUris.parseId(uri);
  setTablesAndProjectionMapForContacts(qb,uri,projection);
  selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
  qb.appendWhere(Contacts._ID + "String_Node_Str");
  break;
}
case CONTACTS_LOOKUP:
case CONTACTS_LOOKUP_ID:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 3) {
  throw new IllegalArgumentException(mDbHelper.get().exceptionMessage("String_Node_Str",uri));
}
String lookupKey=pathSegments.get(2);
if (segmentCount == 4) {
  long contactId=Long.parseLong(pathSegments.get(3));
  SQLiteQueryBuilder lookupQb=new SQLiteQueryBuilder();
  setTablesAndProjectionMapForContacts(lookupQb,uri,projection);
  Cursor c=queryWithContactIdAndLookupKey(lookupQb,mActiveDb.get(),uri,projection,selection,selectionArgs,sortOrder,groupBy,limit,Contacts._ID,contactId,Contacts.LOOKUP_KEY,lookupKey);
  if (c != null) {
    return c;
  }
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(mActiveDb.get(),lookupKey)));
qb.appendWhere(Contacts._ID + "String_Node_Str");
break;
}
case CONTACTS_LOOKUP_DATA:
case CONTACTS_LOOKUP_ID_DATA:
case CONTACTS_LOOKUP_PHOTO:
case CONTACTS_LOOKUP_ID_PHOTO:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 4) {
throw new IllegalArgumentException(mDbHelper.get().exceptionMessage("String_Node_Str",uri));
}
String lookupKey=pathSegments.get(2);
if (segmentCount == 5) {
long contactId=Long.parseLong(pathSegments.get(3));
SQLiteQueryBuilder lookupQb=new SQLiteQueryBuilder();
setTablesAndProjectionMapForData(lookupQb,uri,projection,false);
if (match == CONTACTS_LOOKUP_PHOTO || match == CONTACTS_LOOKUP_ID_PHOTO) {
  qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str"+ Contacts.PHOTO_ID);
}
lookupQb.appendWhere("String_Node_Str");
Cursor c=queryWithContactIdAndLookupKey(lookupQb,mActiveDb.get(),uri,projection,selection,selectionArgs,sortOrder,groupBy,limit,Data.CONTACT_ID,contactId,Data.LOOKUP_KEY,lookupKey);
if (c != null) {
  return c;
}
}
setTablesAndProjectionMapForData(qb,uri,projection,false);
long contactId=lookupContactIdByLookupKey(mActiveDb.get(),lookupKey);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
if (match == CONTACTS_LOOKUP_PHOTO || match == CONTACTS_LOOKUP_ID_PHOTO) {
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str"+ Contacts.PHOTO_ID);
}
qb.appendWhere("String_Node_Str" + Data.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_ID_STREAM_ITEMS:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForStreamItems(qb);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere(StreamItems.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_LOOKUP_STREAM_ITEMS:
case CONTACTS_LOOKUP_ID_STREAM_ITEMS:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 4) {
throw new IllegalArgumentException(mDbHelper.get().exceptionMessage("String_Node_Str",uri));
}
String lookupKey=pathSegments.get(2);
if (segmentCount == 5) {
long contactId=Long.parseLong(pathSegments.get(3));
SQLiteQueryBuilder lookupQb=new SQLiteQueryBuilder();
setTablesAndProjectionMapForStreamItems(lookupQb);
Cursor c=queryWithContactIdAndLookupKey(lookupQb,mActiveDb.get(),uri,projection,selection,selectionArgs,sortOrder,groupBy,limit,StreamItems.CONTACT_ID,contactId,StreamItems.CONTACT_LOOKUP_KEY,lookupKey);
if (c != null) {
return c;
}
}
setTablesAndProjectionMapForStreamItems(qb);
long contactId=lookupContactIdByLookupKey(mActiveDb.get(),lookupKey);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere(RawContacts.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_AS_VCARD:
{
final String lookupKey=Uri.encode(uri.getPathSegments().get(2));
long contactId=lookupContactIdByLookupKey(mActiveDb.get(),lookupKey);
qb.setTables(Views.CONTACTS);
qb.setProjectionMap(sContactsVCardProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere(Contacts._ID + "String_Node_Str");
break;
}
case CONTACTS_AS_MULTI_VCARD:
{
SimpleDateFormat dateFormat=new SimpleDateFormat("String_Node_Str");
String currentDateString=dateFormat.format(new Date()).toString();
return mActiveDb.get().rawQuery("String_Node_Str" + "String_Node_Str" + OpenableColumns.DISPLAY_NAME + "String_Node_Str"+ "String_Node_Str"+ OpenableColumns.SIZE,new String[]{currentDateString});
}
case CONTACTS_FILTER:
{
String filterParam="String_Node_Str";
boolean deferredSnipRequested=deferredSnippetingRequested(uri);
if (uri.getPathSegments().size() > 2) {
filterParam=uri.getLastPathSegment();
}
setTablesAndProjectionMapForContactsWithSnippet(qb,uri,projection,filterParam,directoryId,deferredSnipRequested);
snippetDeferred=isSingleWordQuery(filterParam) && deferredSnipRequested && snippetNeeded(projection);
break;
}
case CONTACTS_STREQUENT_FILTER:
case CONTACTS_STREQUENT:
{
final boolean phoneOnly=readBooleanQueryParameter(uri,ContactsContract.STREQUENT_PHONE_ONLY,false);
if (match == CONTACTS_STREQUENT_FILTER && uri.getPathSegments().size() > 3) {
String filterParam=uri.getLastPathSegment();
StringBuilder sb=new StringBuilder();
sb.append(Contacts._ID + "String_Node_Str");
appendContactFilterAsNestedQuery(sb,filterParam);
selection=DbQueryUtils.concatenateClauses(selection,sb.toString());
}
String[] subProjection=null;
if (projection != null) {
subProjection=appendProjectionArg(projection,TIMES_USED_SORT_COLUMN);
}
setTablesAndProjectionMapForContacts(qb,uri,projection,false);
qb.setProjectionMap(phoneOnly ? sStrequentPhoneOnlyStarredProjectionMap : sStrequentStarredProjectionMap);
if (phoneOnly) {
qb.appendWhere(DbQueryUtils.concatenateClauses(selection,Contacts.HAS_PHONE_NUMBER + "String_Node_Str"));
}
qb.setStrict(true);
final String starredInnerQuery=qb.buildQuery(subProjection,Contacts.STARRED + "String_Node_Str",Contacts._ID,null,Contacts.DISPLAY_NAME + "String_Node_Str",null);
qb=new SQLiteQueryBuilder();
qb.setStrict(true);
final String frequentInnerQuery;
if (phoneOnly) {
final StringBuilder tableBuilder=new StringBuilder();
tableBuilder.append(Tables.DATA_USAGE_STAT + "String_Node_Str" + Views.DATA+ "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ DataUsageStatColumns.CONCRETE_DATA_ID+ "String_Node_Str"+ DataColumns.CONCRETE_ID+ "String_Node_Str"+ DataUsageStatColumns.CONCRETE_USAGE_TYPE+ "String_Node_Str"+ DataUsageStatColumns.USAGE_TYPE_INT_CALL+ "String_Node_Str");
appendContactPresenceJoin(tableBuilder,projection,RawContacts.CONTACT_ID);
appendContactStatusUpdateJoin(tableBuilder,projection,ContactsColumns.LAST_STATUS_UPDATE_ID);
qb.setTables(tableBuilder.toString());
qb.setProjectionMap(sStrequentPhoneOnlyFrequentProjectionMap);
final long phoneMimeTypeId=mDbHelper.get().getMimeTypeId(Phone.CONTENT_ITEM_TYPE);
final long sipMimeTypeId=mDbHelper.get().getMimeTypeId(SipAddress.CONTENT_ITEM_TYPE);
qb.appendWhere(DbQueryUtils.concatenateClauses(selection,Contacts.STARRED + "String_Node_Str" + Contacts.STARRED+ "String_Node_Str",DataColumns.MIMETYPE_ID + "String_Node_Str" + phoneMimeTypeId+ "String_Node_Str"+ sipMimeTypeId+ "String_Node_Str"));
frequentInnerQuery=qb.buildQuery(subProjection,null,null,null,TIMES_USED_SORT_COLUMN + "String_Node_Str","String_Node_Str");
}
 else {
setTablesAndProjectionMapForContacts(qb,uri,projection,true);
qb.setProjectionMap(sStrequentFrequentProjectionMap);
qb.appendWhere(DbQueryUtils.concatenateClauses(selection,"String_Node_Str" + Contacts.STARRED + "String_Node_Str"+ Contacts.STARRED+ "String_Node_Str"));
frequentInnerQuery=qb.buildQuery(subProjection,null,Contacts._ID,null,null,"String_Node_Str");
}
final String frequentQuery="String_Node_Str" + frequentInnerQuery + "String_Node_Str";
final String starredQuery="String_Node_Str" + starredInnerQuery + "String_Node_Str";
final String unionQuery=qb.buildUnionQuery(new String[]{starredQuery,frequentQuery},null,null);
String[] doubledSelectionArgs=null;
if (selectionArgs != null) {
final int length=selectionArgs.length;
doubledSelectionArgs=new String[length * 2];
System.arraycopy(selectionArgs,0,doubledSelectionArgs,0,length);
System.arraycopy(selectionArgs,0,doubledSelectionArgs,length,length);
}
Cursor cursor=mActiveDb.get().rawQuery(unionQuery,doubledSelectionArgs);
if (cursor != null) {
cursor.setNotificationUri(getContext().getContentResolver(),ContactsContract.AUTHORITY_URI);
}
return cursor;
}
case CONTACTS_FREQUENT:
{
setTablesAndProjectionMapForContacts(qb,uri,projection,true);
qb.setProjectionMap(sStrequentFrequentProjectionMap);
groupBy=Contacts._ID;
if (!TextUtils.isEmpty(sortOrder)) {
sortOrder=FREQUENT_ORDER_BY + "String_Node_Str" + sortOrder;
}
 else {
sortOrder=FREQUENT_ORDER_BY;
}
break;
}
case CONTACTS_GROUP:
{
setTablesAndProjectionMapForContacts(qb,uri,projection);
if (uri.getPathSegments().size() > 2) {
qb.appendWhere(CONTACTS_IN_GROUP_SELECT);
String groupMimeTypeId=String.valueOf(mDbHelper.get().getMimeTypeId(GroupMembership.CONTENT_ITEM_TYPE));
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
selectionArgs=insertSelectionArg(selectionArgs,groupMimeTypeId);
}
break;
}
case PROFILE:
{
setTablesAndProjectionMapForContacts(qb,uri,projection);
break;
}
case PROFILE_ENTITIES:
{
setTablesAndProjectionMapForEntities(qb,uri,projection);
break;
}
case PROFILE_AS_VCARD:
{
qb.setTables(Views.CONTACTS);
qb.setProjectionMap(sContactsVCardProjectionMap);
break;
}
case CONTACTS_ID_DATA:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere("String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_ID_PHOTO:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere("String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str");
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str"+ Contacts.PHOTO_ID);
break;
}
case CONTACTS_ID_ENTITIES:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForEntities(qb,uri,projection);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(contactId));
qb.appendWhere("String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_LOOKUP_ENTITIES:
case CONTACTS_LOOKUP_ID_ENTITIES:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 4) {
throw new IllegalArgumentException(mDbHelper.get().exceptionMessage("String_Node_Str",uri));
}
String lookupKey=pathSegments.get(2);
if (segmentCount == 5) {
long contactId=Long.parseLong(pathSegments.get(3));
SQLiteQueryBuilder lookupQb=new SQLiteQueryBuilder();
setTablesAndProjectionMapForEntities(lookupQb,uri,projection);
lookupQb.appendWhere("String_Node_Str");
Cursor c=queryWithContactIdAndLookupKey(lookupQb,mActiveDb.get(),uri,projection,selection,selectionArgs,sortOrder,groupBy,limit,Contacts.Entity.CONTACT_ID,contactId,Contacts.Entity.LOOKUP_KEY,lookupKey);
if (c != null) {
return c;
}
}
setTablesAndProjectionMapForEntities(qb,uri,projection);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(mActiveDb.get(),lookupKey)));
qb.appendWhere("String_Node_Str" + Contacts.Entity.CONTACT_ID + "String_Node_Str");
break;
}
case STREAM_ITEMS:
{
setTablesAndProjectionMapForStreamItems(qb);
break;
}
case STREAM_ITEMS_ID:
{
setTablesAndProjectionMapForStreamItems(qb);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere(StreamItems._ID + "String_Node_Str");
break;
}
case STREAM_ITEMS_LIMIT:
{
MatrixCursor cursor=new MatrixCursor(new String[]{StreamItems.MAX_ITEMS},1);
cursor.addRow(new Object[]{MAX_STREAM_ITEMS_PER_RAW_CONTACT});
return cursor;
}
case STREAM_ITEMS_PHOTOS:
{
setTablesAndProjectionMapForStreamItemPhotos(qb);
break;
}
case STREAM_ITEMS_ID_PHOTOS:
{
setTablesAndProjectionMapForStreamItemPhotos(qb);
String streamItemId=uri.getPathSegments().get(1);
selectionArgs=insertSelectionArg(selectionArgs,streamItemId);
qb.appendWhere(StreamItemPhotosColumns.CONCRETE_STREAM_ITEM_ID + "String_Node_Str");
break;
}
case STREAM_ITEMS_ID_PHOTOS_ID:
{
setTablesAndProjectionMapForStreamItemPhotos(qb);
String streamItemId=uri.getPathSegments().get(1);
String streamItemPhotoId=uri.getPathSegments().get(3);
selectionArgs=insertSelectionArg(selectionArgs,streamItemPhotoId);
selectionArgs=insertSelectionArg(selectionArgs,streamItemId);
qb.appendWhere(StreamItemPhotosColumns.CONCRETE_STREAM_ITEM_ID + "String_Node_Str" + StreamItemPhotosColumns.CONCRETE_ID+ "String_Node_Str");
break;
}
case PHOTO_DIMENSIONS:
{
MatrixCursor cursor=new MatrixCursor(new String[]{DisplayPhoto.DISPLAY_MAX_DIM,DisplayPhoto.THUMBNAIL_MAX_DIM},1);
cursor.addRow(new Object[]{mMaxDisplayPhotoDim,mMaxThumbnailPhotoDim});
return cursor;
}
case PHONES:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForPhone());
final boolean removeDuplicates=readBooleanQueryParameter(uri,ContactsContract.REMOVE_DUPLICATE_ENTRIES,false);
if (removeDuplicates) {
groupBy=RawContacts.CONTACT_ID + "String_Node_Str" + Data.DATA1;
addressBookIndexerCountExpression="String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str"+ Data.DATA1;
}
break;
}
case PHONES_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForPhone());
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case PHONES_FILTER:
{
String typeParam=uri.getQueryParameter(DataUsageFeedback.USAGE_TYPE);
Integer typeInt=sDataUsageTypeMap.get(typeParam);
if (typeInt == null) {
typeInt=DataUsageStatColumns.USAGE_TYPE_INT_CALL;
}
setTablesAndProjectionMapForData(qb,uri,projection,true,typeInt);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForPhone());
if (uri.getPathSegments().size() > 2) {
String filterParam=uri.getLastPathSegment();
StringBuilder sb=new StringBuilder();
sb.append("String_Node_Str");
boolean hasCondition=false;
boolean orNeeded=false;
final String ftsMatchQuery=SearchIndexManager.getFtsMatchQuery(filterParam,FtsQueryBuilder.UNSCOPED_NORMALIZING);
if (ftsMatchQuery.length() > 0) {
sb.append(Data.RAW_CONTACT_ID + "String_Node_Str" + "String_Node_Str"+ RawContactsColumns.CONCRETE_ID+ "String_Node_Str"+ Tables.SEARCH_INDEX+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ Tables.SEARCH_INDEX+ "String_Node_Str"+ SearchIndexColumns.CONTACT_ID+ "String_Node_Str"+ RawContactsColumns.CONCRETE_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ SearchIndexColumns.NAME+ "String_Node_Str");
sb.append(ftsMatchQuery);
sb.append("String_Node_Str");
orNeeded=true;
hasCondition=true;
}
String number=PhoneNumberUtils.normalizeNumber(filterParam);
if (!TextUtils.isEmpty(number)) {
if (orNeeded) {
sb.append("String_Node_Str");
}
sb.append(Data._ID + "String_Node_Str" + PhoneLookupColumns.DATA_ID+ "String_Node_Str"+ Tables.PHONE_LOOKUP+ "String_Node_Str"+ PhoneLookupColumns.NORMALIZED_NUMBER+ "String_Node_Str");
sb.append(number);
sb.append("String_Node_Str");
hasCondition=true;
}
if (!hasCondition) {
sb.append("String_Node_Str");
}
sb.append("String_Node_Str");
qb.appendWhere(sb);
}
groupBy="String_Node_Str" + PhoneColumns.NORMALIZED_NUMBER + "String_Node_Str"+ PhoneColumns.NORMALIZED_NUMBER+ "String_Node_Str"+ Phone.NUMBER+ "String_Node_Str"+ RawContacts.CONTACT_ID;
if (sortOrder == null) {
final String accountPromotionSortOrder=getAccountPromotionSortOrder(uri);
if (!TextUtils.isEmpty(accountPromotionSortOrder)) {
sortOrder=accountPromotionSortOrder + "String_Node_Str" + PHONE_FILTER_SORT_ORDER;
}
 else {
sortOrder=PHONE_FILTER_SORT_ORDER;
}
}
break;
}
case EMAILS:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForEmail());
final boolean removeDuplicates=readBooleanQueryParameter(uri,ContactsContract.REMOVE_DUPLICATE_ENTRIES,false);
if (removeDuplicates) {
groupBy=RawContacts.CONTACT_ID + "String_Node_Str" + Data.DATA1;
addressBookIndexerCountExpression="String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str"+ Data.DATA1;
}
break;
}
case EMAILS_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForEmail()+ "String_Node_Str"+ Data._ID+ "String_Node_Str");
break;
}
case EMAILS_LOOKUP:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForEmail());
if (uri.getPathSegments().size() > 2) {
String email=uri.getLastPathSegment();
String address=mDbHelper.get().extractAddressFromEmailAddress(email);
selectionArgs=insertSelectionArg(selectionArgs,address);
qb.appendWhere("String_Node_Str" + Email.DATA + "String_Node_Str");
}
if (sortOrder == null) {
sortOrder="String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str"+ Tables.DEFAULT_DIRECTORY+ "String_Node_Str";
}
break;
}
case EMAILS_FILTER:
{
String typeParam=uri.getQueryParameter(DataUsageFeedback.USAGE_TYPE);
Integer typeInt=sDataUsageTypeMap.get(typeParam);
if (typeInt == null) {
typeInt=DataUsageStatColumns.USAGE_TYPE_INT_LONG_TEXT;
}
setTablesAndProjectionMapForData(qb,uri,projection,true,typeInt);
String filterParam=null;
if (uri.getPathSegments().size() > 3) {
filterParam=uri.getLastPathSegment();
if (TextUtils.isEmpty(filterParam)) {
filterParam=null;
}
}
if (filterParam == null) {
qb.appendWhere("String_Node_Str");
}
 else {
StringBuilder sb=new StringBuilder();
sb.append("String_Node_Str" + Data._ID + "String_Node_Str");
sb.append("String_Node_Str" + Data._ID + "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str");
sb.append(mDbHelper.get().getMimeTypeIdForEmail());
sb.append("String_Node_Str" + Data.DATA1 + "String_Node_Str");
DatabaseUtils.appendEscapedSQLString(sb,filterParam + '%');
if (!filterParam.contains("String_Node_Str")) {
sb.append("String_Node_Str" + Data._ID + "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str");
sb.append(mDbHelper.get().getMimeTypeIdForEmail());
sb.append("String_Node_Str" + Data.RAW_CONTACT_ID + "String_Node_Str"+ "String_Node_Str"+ RawContactsColumns.CONCRETE_ID+ "String_Node_Str"+ Tables.SEARCH_INDEX+ "String_Node_Str"+ Tables.RAW_CONTACTS+ "String_Node_Str"+ Tables.SEARCH_INDEX+ "String_Node_Str"+ SearchIndexColumns.CONTACT_ID+ "String_Node_Str"+ RawContactsColumns.CONCRETE_CONTACT_ID+ "String_Node_Str"+ "String_Node_Str"+ SearchIndexColumns.NAME+ "String_Node_Str");
final String ftsMatchQuery=SearchIndexManager.getFtsMatchQuery(filterParam,FtsQueryBuilder.UNSCOPED_NORMALIZING);
sb.append(ftsMatchQuery);
sb.append("String_Node_Str");
}
sb.append("String_Node_Str");
qb.appendWhere(sb);
}
groupBy=Email.DATA + "String_Node_Str" + RawContacts.CONTACT_ID;
if (sortOrder == null) {
final String accountPromotionSortOrder=getAccountPromotionSortOrder(uri);
if (!TextUtils.isEmpty(accountPromotionSortOrder)) {
sortOrder=accountPromotionSortOrder + "String_Node_Str" + EMAIL_FILTER_SORT_ORDER;
}
 else {
sortOrder=EMAIL_FILTER_SORT_ORDER;
}
}
break;
}
case POSTALS:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForStructuredPostal());
final boolean removeDuplicates=readBooleanQueryParameter(uri,ContactsContract.REMOVE_DUPLICATE_ENTRIES,false);
if (removeDuplicates) {
groupBy=RawContacts.CONTACT_ID + "String_Node_Str" + Data.DATA1;
addressBookIndexerCountExpression="String_Node_Str" + RawContacts.CONTACT_ID + "String_Node_Str"+ Data.DATA1;
}
break;
}
case POSTALS_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + DataColumns.MIMETYPE_ID + "String_Node_Str"+ mDbHelper.get().getMimeTypeIdForStructuredPostal());
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case RAW_CONTACTS:
case PROFILE_RAW_CONTACTS:
{
setTablesAndProjectionMapForRawContacts(qb,uri);
break;
}
case RAW_CONTACTS_ID:
case PROFILE_RAW_CONTACTS_ID:
{
long rawContactId=ContentUris.parseId(uri);
setTablesAndProjectionMapForRawContacts(qb,uri);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere("String_Node_Str" + RawContacts._ID + "String_Node_Str");
break;
}
case RAW_CONTACTS_DATA:
case PROFILE_RAW_CONTACTS_ID_DATA:
{
int segment=match == RAW_CONTACTS_DATA ? 1 : 2;
long rawContactId=Long.parseLong(uri.getPathSegments().get(segment));
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere("String_Node_Str" + Data.RAW_CONTACT_ID + "String_Node_Str");
break;
}
case RAW_CONTACTS_ID_STREAM_ITEMS:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForStreamItems(qb);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere(StreamItems.RAW_CONTACT_ID + "String_Node_Str");
break;
}
case RAW_CONTACTS_ID_STREAM_ITEMS_ID:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
long streamItemId=Long.parseLong(uri.getPathSegments().get(3));
setTablesAndProjectionMapForStreamItems(qb);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(streamItemId));
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere(StreamItems.RAW_CONTACT_ID + "String_Node_Str" + StreamItems._ID+ "String_Node_Str");
break;
}
case PROFILE_RAW_CONTACTS_ID_ENTITIES:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(2));
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
setTablesAndProjectionMapForRawEntities(qb,uri);
qb.appendWhere("String_Node_Str" + RawContacts._ID + "String_Node_Str");
break;
}
case DATA:
case PROFILE_DATA:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
break;
}
case DATA_ID:
case PROFILE_DATA_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case PROFILE_PHOTO:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str"+ Contacts.PHOTO_ID);
break;
}
case PHONE_LOOKUP:
{
selection=null;
selectionArgs=null;
if (uri.getBooleanQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS,false)) {
if (TextUtils.isEmpty(sortOrder)) {
sortOrder=Contacts.DISPLAY_NAME + "String_Node_Str";
}
String sipAddress=uri.getPathSegments().size() > 1 ? Uri.decode(uri.getLastPathSegment()) : "String_Node_Str";
setTablesAndProjectionMapForData(qb,uri,null,false,true);
StringBuilder sb=new StringBuilder();
selectionArgs=mDbHelper.get().buildSipContactQuery(sb,sipAddress);
selection=sb.toString();
}
 else {
if (TextUtils.isEmpty(sortOrder)) {
sortOrder="String_Node_Str";
}
String number=uri.getPathSegments().size() > 1 ? uri.getLastPathSegment() : "String_Node_Str";
String numberE164=PhoneNumberUtils.formatNumberToE164(number,mDbHelper.get().getCurrentCountryIso());
String normalizedNumber=PhoneNumberUtils.normalizeNumber(number);
mDbHelper.get().buildPhoneLookupAndContactQuery(qb,normalizedNumber,numberE164);
qb.setProjectionMap(sPhoneLookupProjectionMap);
qb.setStrict(true);
boolean foundResult=false;
Cursor cursor=query(mActiveDb.get(),qb,projection,selection,selectionArgs,sortOrder,groupBy,limit);
try {
if (cursor.getCount() > 0) {
foundResult=true;
return cursor;
}
 else {
qb=new SQLiteQueryBuilder();
mDbHelper.get().buildMinimalPhoneLookupAndContactQuery(qb,normalizedNumber);
qb.setProjectionMap(sPhoneLookupProjectionMap);
}
}
  finally {
if (!foundResult) {
cursor.close();
}
}
}
break;
}
case GROUPS:
{
qb.setTables(Views.GROUPS);
qb.setProjectionMap(sGroupsProjectionMap);
appendAccountFromParameter(qb,uri);
break;
}
case GROUPS_ID:
{
qb.setTables(Views.GROUPS);
qb.setProjectionMap(sGroupsProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere(Groups._ID + "String_Node_Str");
break;
}
case GROUPS_SUMMARY:
{
final boolean returnGroupCountPerAccount=readBooleanQueryParameter(uri,Groups.PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT,false);
String tables=Views.GROUPS + "String_Node_Str" + Tables.GROUPS;
if (hasColumn(projection,Groups.SUMMARY_COUNT)) {
tables=tables + Joins.GROUP_MEMBER_COUNT;
}
qb.setTables(tables);
qb.setProjectionMap(returnGroupCountPerAccount ? sGroupsSummaryProjectionMapWithGroupCountPerAccount : sGroupsSummaryProjectionMap);
appendAccountFromParameter(qb,uri);
groupBy=GroupsColumns.CONCRETE_ID;
break;
}
case AGGREGATION_EXCEPTIONS:
{
qb.setTables(Tables.AGGREGATION_EXCEPTIONS);
qb.setProjectionMap(sAggregationExceptionsProjectionMap);
break;
}
case AGGREGATION_SUGGESTIONS:
{
long contactId=Long.parseLong(uri.getPathSegments().get(1));
String filter=null;
if (uri.getPathSegments().size() > 3) {
filter=uri.getPathSegments().get(3);
}
final int maxSuggestions;
if (limit != null) {
maxSuggestions=Integer.parseInt(limit);
}
 else {
maxSuggestions=DEFAULT_MAX_SUGGESTIONS;
}
ArrayList<AggregationSuggestionParameter> parameters=null;
List<String> query=uri.getQueryParameters("String_Node_Str");
if (query != null && !query.isEmpty()) {
parameters=new ArrayList<AggregationSuggestionParameter>(query.size());
for (String parameter : query) {
int offset=parameter.indexOf(':');
parameters.add(offset == -1 ? new AggregationSuggestionParameter(AggregationSuggestions.PARAMETER_MATCH_NAME,parameter) : new AggregationSuggestionParameter(parameter.substring(0,offset),parameter.substring(offset + 1)));
}
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
return mAggregator.get().queryAggregationSuggestions(qb,projection,contactId,maxSuggestions,filter,parameters);
}
case SETTINGS:
{
qb.setTables(Tables.SETTINGS);
qb.setProjectionMap(sSettingsProjectionMap);
appendAccountFromParameter(qb,uri);
final String groupMembershipMimetypeId=Long.toString(mDbHelper.get().getMimeTypeId(GroupMembership.CONTENT_ITEM_TYPE));
if (projection != null && projection.length != 0 && mDbHelper.get().isInProjection(projection,Settings.UNGROUPED_COUNT)) {
selectionArgs=insertSelectionArg(selectionArgs,groupMembershipMimetypeId);
}
if (projection != null && projection.length != 0 && mDbHelper.get().isInProjection(projection,Settings.UNGROUPED_WITH_PHONES)) {
selectionArgs=insertSelectionArg(selectionArgs,groupMembershipMimetypeId);
}
break;
}
case STATUS_UPDATES:
case PROFILE_STATUS_UPDATES:
{
setTableAndProjectionMapForStatusUpdates(qb,projection);
break;
}
case STATUS_UPDATES_ID:
{
setTableAndProjectionMapForStatusUpdates(qb,projection);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere(DataColumns.CONCRETE_ID + "String_Node_Str");
break;
}
case SEARCH_SUGGESTIONS:
{
return mGlobalSearchSupport.handleSearchSuggestionsQuery(mActiveDb.get(),uri,projection,limit);
}
case SEARCH_SHORTCUT:
{
String lookupKey=uri.getLastPathSegment();
String filter=getQueryParameter(uri,SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);
return mGlobalSearchSupport.handleSearchShortcutRefresh(mActiveDb.get(),projection,lookupKey,filter);
}
case RAW_CONTACT_ENTITIES:
case PROFILE_RAW_CONTACT_ENTITIES:
{
setTablesAndProjectionMapForRawEntities(qb,uri);
break;
}
case RAW_CONTACT_ENTITY_ID:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForRawEntities(qb,uri);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(rawContactId));
qb.appendWhere("String_Node_Str" + RawContacts._ID + "String_Node_Str");
break;
}
case PROVIDER_STATUS:
{
return queryProviderStatus(uri,projection);
}
case DIRECTORIES:
{
qb.setTables(Tables.DIRECTORIES);
qb.setProjectionMap(sDirectoryProjectionMap);
break;
}
case DIRECTORIES_ID:
{
long id=ContentUris.parseId(uri);
qb.setTables(Tables.DIRECTORIES);
qb.setProjectionMap(sDirectoryProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(id));
qb.appendWhere(Directory._ID + "String_Node_Str");
break;
}
case COMPLETE_NAME:
{
return completeName(uri,projection);
}
default :
return mLegacyApiSupport.query(uri,projection,selection,selectionArgs,sortOrder,limit);
}
qb.setStrict(true);
Cursor cursor=query(mActiveDb.get(),qb,projection,selection,selectionArgs,sortOrder,groupBy,limit);
if (readBooleanQueryParameter(uri,ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS,false)) {
cursor=bundleLetterCountExtras(cursor,mActiveDb.get(),qb,selection,selectionArgs,sortOrder,addressBookIndexerCountExpression);
}
if (snippetDeferred) {
cursor=addDeferredSnippetingExtra(cursor);
}
return cursor;
}