Program: 152483
Project: 152483
Buggy source:
public Cursor queryLocal(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder,boolean hiddenOnly){
  if (VERBOSE_LOGGING) {
    Log.v(TAG,"String_Node_Str" + uri);
  }
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  SQLiteQueryBuilder qb=new SQLiteQueryBuilder();
  String groupBy=null;
  String limit=getLimit(uri);
  final int match=sUriMatcher.match(uri);
switch (match) {
case SYNCSTATE:
    return mDbHelper.getSyncState().query(db,projection,selection,selectionArgs,sortOrder);
case CONTACTS:
{
    setTablesAndProjectionMapForContacts(qb,uri,projection);
    if (hiddenOnly) {
      qb.appendWhere(Contacts.IN_VISIBLE_GROUP + "String_Node_Str");
    }
    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.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);
  String[] args;
  if (selectionArgs == null) {
    args=new String[2];
  }
 else {
    args=new String[selectionArgs.length + 2];
    System.arraycopy(selectionArgs,0,args,2,selectionArgs.length);
  }
  args[0]=String.valueOf(contactId);
  args[1]=Uri.encode(lookupKey);
  lookupQb.appendWhere(Contacts._ID + "String_Node_Str" + Contacts.LOOKUP_KEY+ "String_Node_Str");
  Cursor c=query(db,lookupQb,projection,selection,args,sortOrder,groupBy,limit);
  if (c.getCount() != 0) {
    return c;
  }
  c.close();
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(db,lookupKey)));
qb.appendWhere(Contacts._ID + "String_Node_Str");
break;
}
case CONTACTS_LOOKUP_DATA:
case CONTACTS_LOOKUP_ID_DATA:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 4) {
throw new IllegalArgumentException(mDbHelper.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);
String[] args;
if (selectionArgs == null) {
  args=new String[2];
}
 else {
  args=new String[selectionArgs.length + 2];
  System.arraycopy(selectionArgs,0,args,2,selectionArgs.length);
}
args[0]=String.valueOf(contactId);
args[1]=Uri.encode(lookupKey);
lookupQb.appendWhere("String_Node_Str" + Data.CONTACT_ID + "String_Node_Str"+ "String_Node_Str"+ Data.LOOKUP_KEY+ "String_Node_Str");
Cursor c=query(db,lookupQb,projection,selection,args,sortOrder,groupBy,limit);
if (c.getCount() != 0) {
  return c;
}
c.close();
}
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(db,lookupKey)));
qb.appendWhere("String_Node_Str" + Data.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_AS_VCARD:
{
final String lookupKey=Uri.encode(uri.getPathSegments().get(2));
qb.setTables(mDbHelper.getContactView(true));
qb.setProjectionMap(sContactsVCardProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(db,lookupKey)));
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 db.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";
if (uri.getPathSegments().size() > 2) {
filterParam=uri.getLastPathSegment();
}
setTablesAndProjectionMapForContactsWithSnippet(qb,uri,projection,filterParam);
if (hiddenOnly) {
qb.appendWhere(Contacts.IN_VISIBLE_GROUP + "String_Node_Str");
}
break;
}
case CONTACTS_STREQUENT_FILTER:
case CONTACTS_STREQUENT:
{
String filterSql=null;
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);
filterSql=sb.toString();
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
String[] starredProjection=null;
String[] frequentProjection=null;
if (projection != null) {
starredProjection=appendProjectionArg(projection,TIMES_CONTACED_SORT_COLUMN);
frequentProjection=appendProjectionArg(projection,TIMES_CONTACED_SORT_COLUMN);
}
if (filterSql != null) {
qb.appendWhere(filterSql);
}
qb.setProjectionMap(sStrequentStarredProjectionMap);
final String starredQuery=qb.buildQuery(starredProjection,Contacts.STARRED + "String_Node_Str",null,Contacts._ID,null,null,null);
qb=new SQLiteQueryBuilder();
setTablesAndProjectionMapForContacts(qb,uri,projection);
if (filterSql != null) {
qb.appendWhere(filterSql);
}
qb.setProjectionMap(sStrequentFrequentProjectionMap);
final String frequentQuery=qb.buildQuery(frequentProjection,Contacts.TIMES_CONTACTED + "String_Node_Str" + Contacts.STARRED+ "String_Node_Str"+ Contacts.STARRED+ "String_Node_Str",null,Contacts._ID,null,null,null);
final String query=qb.buildUnionQuery(new String[]{starredQuery,frequentQuery},STREQUENT_ORDER_BY,STREQUENT_LIMIT);
Cursor c=db.rawQuery(query,null);
if (c != null) {
c.setNotificationUri(getContext().getContentResolver(),ContactsContract.AUTHORITY_URI);
}
return c;
}
case CONTACTS_GROUP:
{
setTablesAndProjectionMapForContacts(qb,uri,projection);
if (uri.getPathSegments().size() > 2) {
qb.appendWhere(CONTACTS_IN_GROUP_SELECT);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
}
break;
}
case CONTACTS_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_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 PHONES:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Phone.CONTENT_ITEM_TYPE+ "String_Node_Str");
break;
}
case PHONES_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Phone.CONTENT_ITEM_TYPE+ "String_Node_Str");
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case PHONES_FILTER:
{
setTablesAndProjectionMapForData(qb,uri,projection,true);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Phone.CONTENT_ITEM_TYPE+ "String_Node_Str");
if (uri.getPathSegments().size() > 2) {
String filterParam=uri.getLastPathSegment();
StringBuilder sb=new StringBuilder();
sb.append("String_Node_Str");
boolean hasCondition=false;
boolean orNeeded=false;
String normalizedName=NameNormalizer.normalize(filterParam);
if (normalizedName.length() > 0) {
sb.append(Data.RAW_CONTACT_ID + "String_Node_Str");
appendRawContactsByNormalizedNameFilter(sb,normalizedName,false);
orNeeded=true;
hasCondition=true;
}
if (isPhoneNumber(filterParam)) {
if (orNeeded) {
sb.append("String_Node_Str");
}
String number=PhoneNumberUtils.convertKeypadLettersToDigits(filterParam);
String reversed=PhoneNumberUtils.getStrippedReversed(number);
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(reversed);
sb.append("String_Node_Str");
hasCondition=true;
}
if (!hasCondition) {
sb.append("String_Node_Str");
}
sb.append("String_Node_Str");
qb.appendWhere(sb);
}
groupBy=PhoneColumns.NORMALIZED_NUMBER + "String_Node_Str" + RawContacts.CONTACT_ID;
if (sortOrder == null) {
sortOrder=Contacts.IN_VISIBLE_GROUP + "String_Node_Str" + RawContacts.CONTACT_ID;
}
break;
}
case EMAILS:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Email.CONTENT_ITEM_TYPE+ "String_Node_Str");
break;
}
case EMAILS_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Email.CONTENT_ITEM_TYPE+ "String_Node_Str"+ "String_Node_Str"+ Data._ID+ "String_Node_Str");
break;
}
case EMAILS_LOOKUP:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Email.CONTENT_ITEM_TYPE+ "String_Node_Str");
if (uri.getPathSegments().size() > 2) {
String email=uri.getLastPathSegment();
String address=mDbHelper.extractAddressFromEmailAddress(email);
selectionArgs=insertSelectionArg(selectionArgs,address);
qb.appendWhere("String_Node_Str" + Email.DATA + "String_Node_Str");
}
break;
}
case EMAILS_FILTER:
{
setTablesAndProjectionMapForData(qb,uri,projection,true);
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"+ mMimeTypeIdEmail+ "String_Node_Str"+ Data.DATA1+ "String_Node_Str");
DatabaseUtils.appendEscapedSQLString(sb,filterParam + '%');
if (!filterParam.contains("String_Node_Str")) {
String normalizedName=NameNormalizer.normalize(filterParam);
if (normalizedName.length() > 0) {
sb.append("String_Node_Str" + Data._ID + "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str"+ mMimeTypeIdEmail+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str");
appendRawContactsByNormalizedNameFilter(sb,normalizedName,false);
}
}
sb.append("String_Node_Str");
qb.appendWhere(sb);
}
groupBy=Email.DATA + "String_Node_Str" + RawContacts.CONTACT_ID;
if (sortOrder == null) {
sortOrder=Contacts.IN_VISIBLE_GROUP + "String_Node_Str" + RawContacts.CONTACT_ID;
}
break;
}
case POSTALS:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ StructuredPostal.CONTENT_ITEM_TYPE+ "String_Node_Str");
break;
}
case POSTALS_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ StructuredPostal.CONTENT_ITEM_TYPE+ "String_Node_Str");
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case RAW_CONTACTS:
{
setTablesAndProjectionMapForRawContacts(qb,uri);
break;
}
case 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:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
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 DATA:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
break;
}
case DATA_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case PHONE_LOOKUP:
{
if (TextUtils.isEmpty(sortOrder)) {
sortOrder=RawContactsColumns.CONCRETE_ID;
}
String number=uri.getPathSegments().size() > 1 ? uri.getLastPathSegment() : "String_Node_Str";
mDbHelper.buildPhoneLookupAndContactQuery(qb,number);
qb.setProjectionMap(sPhoneLookupProjectionMap);
selection=null;
selectionArgs=null;
break;
}
case GROUPS:
{
qb.setTables(mDbHelper.getGroupView());
qb.setProjectionMap(sGroupsProjectionMap);
appendAccountFromParameter(qb,uri);
break;
}
case GROUPS_ID:
{
qb.setTables(mDbHelper.getGroupView());
qb.setProjectionMap(sGroupsProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere(Groups._ID + "String_Node_Str");
break;
}
case GROUPS_SUMMARY:
{
qb.setTables(mDbHelper.getGroupView() + "String_Node_Str");
qb.setProjectionMap(sGroupsSummaryProjectionMap);
appendAccountFromParameter(qb,uri);
groupBy=Groups._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;
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
return mContactAggregator.queryAggregationSuggestions(qb,projection,contactId,maxSuggestions,filter);
}
case SETTINGS:
{
qb.setTables(Tables.SETTINGS);
qb.setProjectionMap(sSettingsProjectionMap);
appendAccountFromParameter(qb,uri);
final String groupMembershipMimetypeId=Long.toString(mDbHelper.getMimeTypeId(GroupMembership.CONTENT_ITEM_TYPE));
if (projection != null && projection.length != 0 && mDbHelper.isInProjection(projection,Settings.UNGROUPED_COUNT)) {
selectionArgs=insertSelectionArg(selectionArgs,groupMembershipMimetypeId);
}
if (projection != null && projection.length != 0 && mDbHelper.isInProjection(projection,Settings.UNGROUPED_WITH_PHONES)) {
selectionArgs=insertSelectionArg(selectionArgs,groupMembershipMimetypeId);
}
break;
}
case 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(db,uri,limit);
}
case SEARCH_SHORTCUT:
{
String lookupKey=uri.getLastPathSegment();
return mGlobalSearchSupport.handleSearchShortcutRefresh(db,lookupKey,projection);
}
case LIVE_FOLDERS_CONTACTS:
qb.setTables(mDbHelper.getContactView());
qb.setProjectionMap(sLiveFoldersProjectionMap);
break;
case LIVE_FOLDERS_CONTACTS_WITH_PHONES:
qb.setTables(mDbHelper.getContactView());
qb.setProjectionMap(sLiveFoldersProjectionMap);
qb.appendWhere(Contacts.HAS_PHONE_NUMBER + "String_Node_Str");
break;
case LIVE_FOLDERS_CONTACTS_FAVORITES:
qb.setTables(mDbHelper.getContactView());
qb.setProjectionMap(sLiveFoldersProjectionMap);
qb.appendWhere(Contacts.STARRED + "String_Node_Str");
break;
case LIVE_FOLDERS_CONTACTS_GROUP_NAME:
qb.setTables(mDbHelper.getContactView());
qb.setProjectionMap(sLiveFoldersProjectionMap);
qb.appendWhere(CONTACTS_IN_GROUP_SELECT);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
break;
case RAW_CONTACT_ENTITIES:
{
setTablesAndProjectionMapForRawContactsEntities(qb,uri);
break;
}
case RAW_CONTACT_ENTITY_ID:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForRawContactsEntities(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 directoryId=ContentUris.parseId(uri);
qb.setTables(Tables.DIRECTORIES);
qb.setProjectionMap(sDirectoryProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(directoryId));
qb.appendWhere(Directory._ID + "String_Node_Str");
break;
}
default :
return mLegacyApiSupport.query(uri,projection,selection,selectionArgs,sortOrder,limit);
}
qb.setStrictProjectionMap(true);
Cursor cursor=query(db,qb,projection,selection,selectionArgs,sortOrder,groupBy,limit);
if (readBooleanQueryParameter(uri,ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS,false)) {
cursor=bundleLetterCountExtras(cursor,db,qb,selection,selectionArgs,sortOrder);
}
return cursor;
}

Fixed version (ground truth):
public Cursor queryLocal(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder,boolean hiddenOnly){
  if (VERBOSE_LOGGING) {
    Log.v(TAG,"String_Node_Str" + uri);
  }
  final SQLiteDatabase db=mDbHelper.getReadableDatabase();
  SQLiteQueryBuilder qb=new SQLiteQueryBuilder();
  String groupBy=null;
  String limit=getLimit(uri);
  final int match=sUriMatcher.match(uri);
switch (match) {
case SYNCSTATE:
    return mDbHelper.getSyncState().query(db,projection,selection,selectionArgs,sortOrder);
case CONTACTS:
{
    setTablesAndProjectionMapForContacts(qb,uri,projection);
    if (hiddenOnly) {
      qb.appendWhere(Contacts.IN_VISIBLE_GROUP + "String_Node_Str");
    }
    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.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);
  String[] args;
  if (selectionArgs == null) {
    args=new String[2];
  }
 else {
    args=new String[selectionArgs.length + 2];
    System.arraycopy(selectionArgs,0,args,2,selectionArgs.length);
  }
  args[0]=String.valueOf(contactId);
  args[1]=Uri.encode(lookupKey);
  lookupQb.appendWhere(Contacts._ID + "String_Node_Str" + Contacts.LOOKUP_KEY+ "String_Node_Str");
  Cursor c=query(db,lookupQb,projection,selection,args,sortOrder,groupBy,limit);
  if (c.getCount() != 0) {
    return c;
  }
  c.close();
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(db,lookupKey)));
qb.appendWhere(Contacts._ID + "String_Node_Str");
break;
}
case CONTACTS_LOOKUP_DATA:
case CONTACTS_LOOKUP_ID_DATA:
{
List<String> pathSegments=uri.getPathSegments();
int segmentCount=pathSegments.size();
if (segmentCount < 4) {
throw new IllegalArgumentException(mDbHelper.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);
String[] args;
if (selectionArgs == null) {
  args=new String[2];
}
 else {
  args=new String[selectionArgs.length + 2];
  System.arraycopy(selectionArgs,0,args,2,selectionArgs.length);
}
args[0]=String.valueOf(contactId);
args[1]=Uri.encode(lookupKey);
lookupQb.appendWhere("String_Node_Str" + Data.CONTACT_ID + "String_Node_Str"+ "String_Node_Str"+ Data.LOOKUP_KEY+ "String_Node_Str");
Cursor c=query(db,lookupQb,projection,selection,args,sortOrder,groupBy,limit);
if (c.getCount() != 0) {
  return c;
}
c.close();
}
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(db,lookupKey)));
qb.appendWhere("String_Node_Str" + Data.CONTACT_ID + "String_Node_Str");
break;
}
case CONTACTS_AS_VCARD:
{
final String lookupKey=Uri.encode(uri.getPathSegments().get(2));
qb.setTables(mDbHelper.getContactView(true));
qb.setProjectionMap(sContactsVCardProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(lookupContactIdByLookupKey(db,lookupKey)));
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 db.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";
if (uri.getPathSegments().size() > 2) {
filterParam=uri.getLastPathSegment();
}
setTablesAndProjectionMapForContactsWithSnippet(qb,uri,projection,filterParam);
if (hiddenOnly) {
qb.appendWhere(Contacts.IN_VISIBLE_GROUP + "String_Node_Str");
}
break;
}
case CONTACTS_STREQUENT_FILTER:
case CONTACTS_STREQUENT:
{
String filterSql=null;
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);
filterSql=sb.toString();
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
String[] starredProjection=null;
String[] frequentProjection=null;
if (projection != null) {
starredProjection=appendProjectionArg(projection,TIMES_CONTACTED_SORT_COLUMN);
frequentProjection=appendProjectionArg(projection,TIMES_CONTACTED_SORT_COLUMN);
}
if (filterSql != null) {
qb.appendWhere(filterSql);
}
qb.setProjectionMap(sStrequentStarredProjectionMap);
final String starredQuery=qb.buildQuery(starredProjection,Contacts.STARRED + "String_Node_Str",null,Contacts._ID,null,null,null);
qb=new SQLiteQueryBuilder();
setTablesAndProjectionMapForContacts(qb,uri,projection);
if (filterSql != null) {
qb.appendWhere(filterSql);
}
qb.setProjectionMap(sStrequentFrequentProjectionMap);
final String frequentQuery=qb.buildQuery(frequentProjection,Contacts.TIMES_CONTACTED + "String_Node_Str" + Contacts.STARRED+ "String_Node_Str"+ Contacts.STARRED+ "String_Node_Str",null,Contacts._ID,null,null,null);
final String query=qb.buildUnionQuery(new String[]{starredQuery,frequentQuery},STREQUENT_ORDER_BY,STREQUENT_LIMIT);
Cursor c=db.rawQuery(query,null);
if (c != null) {
c.setNotificationUri(getContext().getContentResolver(),ContactsContract.AUTHORITY_URI);
}
return c;
}
case CONTACTS_GROUP:
{
setTablesAndProjectionMapForContacts(qb,uri,projection);
if (uri.getPathSegments().size() > 2) {
qb.appendWhere(CONTACTS_IN_GROUP_SELECT);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
}
break;
}
case CONTACTS_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_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 PHONES:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Phone.CONTENT_ITEM_TYPE+ "String_Node_Str");
break;
}
case PHONES_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Phone.CONTENT_ITEM_TYPE+ "String_Node_Str");
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case PHONES_FILTER:
{
setTablesAndProjectionMapForData(qb,uri,projection,true);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Phone.CONTENT_ITEM_TYPE+ "String_Node_Str");
if (uri.getPathSegments().size() > 2) {
String filterParam=uri.getLastPathSegment();
StringBuilder sb=new StringBuilder();
sb.append("String_Node_Str");
boolean hasCondition=false;
boolean orNeeded=false;
String normalizedName=NameNormalizer.normalize(filterParam);
if (normalizedName.length() > 0) {
sb.append(Data.RAW_CONTACT_ID + "String_Node_Str");
appendRawContactsByNormalizedNameFilter(sb,normalizedName,false);
orNeeded=true;
hasCondition=true;
}
if (isPhoneNumber(filterParam)) {
if (orNeeded) {
sb.append("String_Node_Str");
}
String number=PhoneNumberUtils.convertKeypadLettersToDigits(filterParam);
String reversed=PhoneNumberUtils.getStrippedReversed(number);
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(reversed);
sb.append("String_Node_Str");
hasCondition=true;
}
if (!hasCondition) {
sb.append("String_Node_Str");
}
sb.append("String_Node_Str");
qb.appendWhere(sb);
}
groupBy=PhoneColumns.NORMALIZED_NUMBER + "String_Node_Str" + RawContacts.CONTACT_ID;
if (sortOrder == null) {
sortOrder=Contacts.IN_VISIBLE_GROUP + "String_Node_Str" + RawContacts.CONTACT_ID;
}
break;
}
case EMAILS:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Email.CONTENT_ITEM_TYPE+ "String_Node_Str");
break;
}
case EMAILS_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Email.CONTENT_ITEM_TYPE+ "String_Node_Str"+ "String_Node_Str"+ Data._ID+ "String_Node_Str");
break;
}
case EMAILS_LOOKUP:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ Email.CONTENT_ITEM_TYPE+ "String_Node_Str");
if (uri.getPathSegments().size() > 2) {
String email=uri.getLastPathSegment();
String address=mDbHelper.extractAddressFromEmailAddress(email);
selectionArgs=insertSelectionArg(selectionArgs,address);
qb.appendWhere("String_Node_Str" + Email.DATA + "String_Node_Str");
}
break;
}
case EMAILS_FILTER:
{
setTablesAndProjectionMapForData(qb,uri,projection,true);
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"+ mMimeTypeIdEmail+ "String_Node_Str"+ Data.DATA1+ "String_Node_Str");
DatabaseUtils.appendEscapedSQLString(sb,filterParam + '%');
if (!filterParam.contains("String_Node_Str")) {
String normalizedName=NameNormalizer.normalize(filterParam);
if (normalizedName.length() > 0) {
sb.append("String_Node_Str" + Data._ID + "String_Node_Str"+ Tables.DATA+ "String_Node_Str"+ DataColumns.MIMETYPE_ID+ "String_Node_Str"+ mMimeTypeIdEmail+ "String_Node_Str"+ Data.RAW_CONTACT_ID+ "String_Node_Str");
appendRawContactsByNormalizedNameFilter(sb,normalizedName,false);
}
}
sb.append("String_Node_Str");
qb.appendWhere(sb);
}
groupBy=Email.DATA + "String_Node_Str" + RawContacts.CONTACT_ID;
if (sortOrder == null) {
sortOrder=Contacts.IN_VISIBLE_GROUP + "String_Node_Str" + RawContacts.CONTACT_ID;
}
break;
}
case POSTALS:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ StructuredPostal.CONTENT_ITEM_TYPE+ "String_Node_Str");
break;
}
case POSTALS_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data.MIMETYPE + "String_Node_Str"+ StructuredPostal.CONTENT_ITEM_TYPE+ "String_Node_Str");
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case RAW_CONTACTS:
{
setTablesAndProjectionMapForRawContacts(qb,uri);
break;
}
case 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:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
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 DATA:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
break;
}
case DATA_ID:
{
setTablesAndProjectionMapForData(qb,uri,projection,false);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere("String_Node_Str" + Data._ID + "String_Node_Str");
break;
}
case PHONE_LOOKUP:
{
if (TextUtils.isEmpty(sortOrder)) {
sortOrder=RawContactsColumns.CONCRETE_ID;
}
String number=uri.getPathSegments().size() > 1 ? uri.getLastPathSegment() : "String_Node_Str";
mDbHelper.buildPhoneLookupAndContactQuery(qb,number);
qb.setProjectionMap(sPhoneLookupProjectionMap);
selection=null;
selectionArgs=null;
break;
}
case GROUPS:
{
qb.setTables(mDbHelper.getGroupView());
qb.setProjectionMap(sGroupsProjectionMap);
appendAccountFromParameter(qb,uri);
break;
}
case GROUPS_ID:
{
qb.setTables(mDbHelper.getGroupView());
qb.setProjectionMap(sGroupsProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
qb.appendWhere(Groups._ID + "String_Node_Str");
break;
}
case GROUPS_SUMMARY:
{
qb.setTables(mDbHelper.getGroupView() + "String_Node_Str");
qb.setProjectionMap(sGroupsSummaryProjectionMap);
appendAccountFromParameter(qb,uri);
groupBy=Groups._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;
}
setTablesAndProjectionMapForContacts(qb,uri,projection);
return mContactAggregator.queryAggregationSuggestions(qb,projection,contactId,maxSuggestions,filter);
}
case SETTINGS:
{
qb.setTables(Tables.SETTINGS);
qb.setProjectionMap(sSettingsProjectionMap);
appendAccountFromParameter(qb,uri);
final String groupMembershipMimetypeId=Long.toString(mDbHelper.getMimeTypeId(GroupMembership.CONTENT_ITEM_TYPE));
if (projection != null && projection.length != 0 && mDbHelper.isInProjection(projection,Settings.UNGROUPED_COUNT)) {
selectionArgs=insertSelectionArg(selectionArgs,groupMembershipMimetypeId);
}
if (projection != null && projection.length != 0 && mDbHelper.isInProjection(projection,Settings.UNGROUPED_WITH_PHONES)) {
selectionArgs=insertSelectionArg(selectionArgs,groupMembershipMimetypeId);
}
break;
}
case 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(db,uri,limit);
}
case SEARCH_SHORTCUT:
{
String lookupKey=uri.getLastPathSegment();
return mGlobalSearchSupport.handleSearchShortcutRefresh(db,lookupKey,projection);
}
case LIVE_FOLDERS_CONTACTS:
qb.setTables(mDbHelper.getContactView());
qb.setProjectionMap(sLiveFoldersProjectionMap);
break;
case LIVE_FOLDERS_CONTACTS_WITH_PHONES:
qb.setTables(mDbHelper.getContactView());
qb.setProjectionMap(sLiveFoldersProjectionMap);
qb.appendWhere(Contacts.HAS_PHONE_NUMBER + "String_Node_Str");
break;
case LIVE_FOLDERS_CONTACTS_FAVORITES:
qb.setTables(mDbHelper.getContactView());
qb.setProjectionMap(sLiveFoldersProjectionMap);
qb.appendWhere(Contacts.STARRED + "String_Node_Str");
break;
case LIVE_FOLDERS_CONTACTS_GROUP_NAME:
qb.setTables(mDbHelper.getContactView());
qb.setProjectionMap(sLiveFoldersProjectionMap);
qb.appendWhere(CONTACTS_IN_GROUP_SELECT);
selectionArgs=insertSelectionArg(selectionArgs,uri.getLastPathSegment());
break;
case RAW_CONTACT_ENTITIES:
{
setTablesAndProjectionMapForRawContactsEntities(qb,uri);
break;
}
case RAW_CONTACT_ENTITY_ID:
{
long rawContactId=Long.parseLong(uri.getPathSegments().get(1));
setTablesAndProjectionMapForRawContactsEntities(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 directoryId=ContentUris.parseId(uri);
qb.setTables(Tables.DIRECTORIES);
qb.setProjectionMap(sDirectoryProjectionMap);
selectionArgs=insertSelectionArg(selectionArgs,String.valueOf(directoryId));
qb.appendWhere(Directory._ID + "String_Node_Str");
break;
}
default :
return mLegacyApiSupport.query(uri,projection,selection,selectionArgs,sortOrder,limit);
}
qb.setStrictProjectionMap(true);
Cursor cursor=query(db,qb,projection,selection,selectionArgs,sortOrder,groupBy,limit);
if (readBooleanQueryParameter(uri,ContactCounts.ADDRESS_BOOK_INDEX_EXTRAS,false)) {
cursor=bundleLetterCountExtras(cursor,db,qb,selection,selectionArgs,sortOrder);
}
return cursor;
}