Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf37a029 authored by Andre Eisenbach's avatar Andre Eisenbach
Browse files

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
parent 9135d866
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -276,8 +276,8 @@ public class BluetoothPbapVcardManager {
                    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 @@ public class BluetoothPbapVcardManager {
     */
    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 @@ public class BluetoothPbapVcardManager {
    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;