From c438463431b171a67b22b50886ef8dd737c44004 Mon Sep 17 00:00:00 2001 From: Andre Eisenbach Date: Fri, 25 Mar 2016 14:39:40 -0700 Subject: [PATCH] Fix more merge issues in BluetoothPbapVcardManager.java Change-Id: I901042e69b3beea93684fe1a194353664fabd0c2 --- .../bluetooth/pbap/BluetoothPbapVcardManager.java | 73 ++++++++-------------- 1 file changed, 26 insertions(+), 47 deletions(-) diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java b/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java index e150e8c4..f4280ae3 100644 --- a/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java +++ b/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java @@ -167,8 +167,7 @@ public class BluetoothPbapVcardManager { if (contactCursor == null) { return 0; } - return getDistinctContactIdSize(contactCursor, Phone.CONTACT_ID) - + 1; // always has the 0.vcf + return getDistinctContactIdSize(contactCursor) + 1; // always has the 0.vcf } catch (CursorWindowAllocationException e) { Log.e(TAG, "CursorWindowAllocationException while getting Contacts size"); } finally { @@ -269,15 +268,8 @@ public class BluetoothPbapVcardManager { CLAUSE_ONLY_VISIBLE, null, orderBy); if (contactCursor != null) { appendDistinctNameIdList(nameList, - mContext.getString(android.R.string.unknownName), contactCursor, - Phone.CONTACT_ID, Phone.DISPLAY_NAME); - if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_INDEXED) { - if (V) Log.v(TAG, "getPhonebookNameList, order by index"); - // Do not need to do anything, as we sort it by index already - } else if (orderByWhat == BluetoothPbapObexServer.ORDER_BY_ALPHABETICAL) { - if (V) Log.v(TAG, "getPhonebookNameList, order by alpha"); - Collections.sort(nameList); - } + mContext.getString(android.R.string.unknownName), + contactCursor); } } catch (CursorWindowAllocationException e) { Log.e(TAG, "CursorWindowAllocationException while getting phonebook name list"); @@ -297,28 +289,26 @@ public class BluetoothPbapVcardManager { ArrayList tempNameList = new ArrayList(); Cursor contactCursor = null; - Uri uri; - final String[] projection; - final String contactIdColumn, displayNameColumn; + Uri uri = null; + String[] projection = null; + if (TextUtils.isEmpty(phoneNumber)) { uri = DevicePolicyUtils.getEnterprisePhoneUri(mContext); - contactIdColumn = Phone.CONTACT_ID; - displayNameColumn = Phone.DISPLAY_NAME; + projection = PHONES_CONTACTS_PROJECTION; } else { - uri = Uri.withAppendedPath(getPhoneLookupFilterUri(), Uri.encode(phoneNumber)); - contactIdColumn = PhoneLookup._ID; - displayNameColumn = PhoneLookup.DISPLAY_NAME; + uri = Uri.withAppendedPath(getPhoneLookupFilterUri(), + Uri.encode(phoneNumber)); + projection = PHONE_LOOKUP_PROJECTION; } - projection = new String[]{contactIdColumn, displayNameColumn}; try { - contactCursor = mResolver - .query(uri, projection, CLAUSE_ONLY_VISIBLE, null, contactIdColumn); + contactCursor = mResolver.query(uri, projection, CLAUSE_ONLY_VISIBLE, null, + Phone.CONTACT_ID); if (contactCursor != null) { appendDistinctNameIdList(nameList, mContext.getString(android.R.string.unknownName), - contactCursor, contactIdColumn, displayNameColumn); + contactCursor); if (V) { for (String nameIdStr : nameList) { Log.v(TAG, "got name " + nameIdStr + " by number " + phoneNumber); @@ -846,23 +836,19 @@ public class BluetoothPbapVcardManager { private static final Uri getPhoneLookupFilterUri() { return PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI; } + /** * Get size of the cursor without duplicated contact id. This assumes the * given cursor is sorted by CONTACT_ID. */ - /** - * Count number of rows having distinct contact id. It assumes - * @param cursor cursor to be counted. - * @param contactIdColumn column name of contact id - * @return number of rows that have distinct contact id. - */ - private static final int getDistinctContactIdSize(Cursor cursor, String contactIdColumn) { - final int contactIdColumnIndex = cursor.getColumnIndexOrThrow(contactIdColumn); + private static final int getDistinctContactIdSize(Cursor cursor) { + final int contactIdColumn = cursor.getColumnIndex(Data.CONTACT_ID); + final int idColumn = cursor.getColumnIndex(Data._ID); long previousContactId = -1; int count = 0; cursor.moveToPosition(-1); while (cursor.moveToNext()) { - final long contactId = cursor.getLong(contactIdColumnIndex); + final long contactId = cursor.getLong(contactIdColumn != -1 ? contactIdColumn : idColumn); if (previousContactId != contactId) { count++; previousContactId = contactId; @@ -875,25 +861,18 @@ public class BluetoothPbapVcardManager { } /** - * Construct "display_name,contact_id" strings and insert into a arraylist. - * - * @param resultList list to be inserted. - * @param defaultName default name if the name of contact is empty. - * @param cursor a cursor containing contact id and display name. - * @param contactIdColumnName name of column that stores contact id. - * @param displayNameColumnName name of column that stores display name. + * Append "display_name,contact_id" string array from cursor to ArrayList. + * This assumes the given cursor is sorted by CONTACT_ID. */ private static void appendDistinctNameIdList(ArrayList resultList, - String defaultName, Cursor cursor, String contactIdColumnName, - String displayNameColumnName) { - final int contactIdColumnIndex = cursor.getColumnIndexOrThrow(contactIdColumnName); - final int displayNameColumnIndex = cursor.getColumnIndexOrThrow(displayNameColumnName); - - long previousContactId = -1; + String defaultName, Cursor cursor) { + final int contactIdColumn = cursor.getColumnIndex(Data.CONTACT_ID); + final int idColumn = cursor.getColumnIndex(Data._ID); + final int nameColumn = cursor.getColumnIndex(Data.DISPLAY_NAME); cursor.moveToPosition(-1); while (cursor.moveToNext()) { - final long contactId = cursor.getLong(contactIdColumnIndex); - String displayName = cursor.getString(displayNameColumnIndex); + final long contactId = cursor.getLong(contactIdColumn != -1 ? contactIdColumn : idColumn); + String displayName = nameColumn != -1 ? cursor.getString(nameColumn) : defaultName; if (TextUtils.isEmpty(displayName)) { displayName = defaultName; } -- 2.11.0