Fix column ID for PBAP name lookup
When a phonebook lookup is performed to resolve a phone number into a
name, the wrong column ID is used to retrieve the value from the cursor,
causing an un-caught exception and a failed lookup.
Bug: 22953958
Change-Id: I1f826412916012382903fdf30d43d5cb3516432c
diff --git a/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java b/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java
index e4dae03..de8275e 100644
--- a/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java
+++ b/src/com/android/bluetooth/pbap/BluetoothPbapVcardManager.java
@@ -276,8 +276,8 @@
Collections.sort(nameList);
}
}
- } catch (CursorWindowAllocationException e) {
- Log.e(TAG, "CursorWindowAllocationException while getting Phonebook name list");
+ } catch (Exception e) {
+ Log.e(TAG, "Exception while getting Phonebook name list", e);
} finally {
if (contactCursor != null) {
contactCursor.close();
@@ -838,11 +838,12 @@
*/
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(contactIdColumn);
+ final long contactId = cursor.getLong(contactIdColumn != -1 ? contactIdColumn : idColumn);
if (previousContactId != contactId) {
count++;
previousContactId = contactId;
@@ -861,11 +862,12 @@
private static void appendDistinctNameIdList(ArrayList<String> resultList,
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);
long previousContactId = -1;
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
- final long contactId = cursor.getLong(contactIdColumn);
+ final long contactId = cursor.getLong(contactIdColumn != -1 ? contactIdColumn : idColumn);
String displayName = nameColumn != -1 ? cursor.getString(nameColumn) : defaultName;
if (TextUtils.isEmpty(displayName)) {
displayName = defaultName;