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

Commit 0956d359 authored by zachh's avatar zachh Committed by Copybara-Service
Browse files

Append the directory ID when building contact lookup URIs in CP2 lookups.

Before, when tapping the icon in the call log for a call made to a remote contact, I would get a "Contact doesn't exist" message because CP2 couldn't find the contact due to:

05-18 22:28:48.750 E/DatabaseUtils(26187): java.lang.IllegalArgumentException: Invalid lookup id: people-v2:114584120460114609902
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at com.android.providers.contacts.ContactLookupKey.parse(ContactLookupKey.java:157)
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at com.android.providers.contacts.ContactsProvider2.lookupContactIdByLookupKey(ContactsProvider2.java:7766)
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at com.android.providers.contacts.ContactsProvider2.queryLocal(ContactsProvider2.java:6248)
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at com.android.providers.contacts.ContactsProvider2.queryDirectoryIfNecessary(ContactsProvider2.java:5565)
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at com.android.providers.contacts.ContactsProvider2.query(ContactsProvider2.java:5544)
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at android.content.ContentProvider.query(ContentProvider.java:1147)
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at android.content.ContentProvider$Transport.query(ContentProvider.java:240)
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:102)
05-18 22:28:48.750 E/DatabaseUtils(26187): 	at android.os.Binder.execTransact(Binder.java:697)

When we construct the contact URI in Cp2ExtendedDirectoryPhoneLookup, we should include the directory ID so that CP2 knows where to look when the user taps the icon in the call log.

TEST=unit, manual
Bug: 80008014
Test: unit, manual
PiperOrigin-RevId: 197600727
Change-Id: Ib262ca4b7e605c3e94ea683289f62c727389b32f
parent e10f20f6
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.DeletedContacts;
import android.provider.ContactsContract.Directory;
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
import android.support.v4.util.ArraySet;
@@ -134,7 +135,8 @@ public final class Cp2DefaultDirectoryPhoneLookup implements PhoneLookup<Cp2Info
        return Cp2Info.getDefaultInstance();
      }
      while (cursor.moveToNext()) {
        cp2ContactInfos.add(Cp2Projections.buildCp2ContactInfoFromCursor(appContext, cursor));
        cp2ContactInfos.add(
            Cp2Projections.buildCp2ContactInfoFromCursor(appContext, cursor, Directory.DEFAULT));
      }
    } finally {
      if (cursor != null) {
@@ -794,7 +796,8 @@ public final class Cp2DefaultDirectoryPhoneLookup implements PhoneLookup<Cp2Info
                  cp2ContactInfosByNumber.put(validE164Number, cp2ContactInfos);
                }
                cp2ContactInfos.add(
                    Cp2Projections.buildCp2ContactInfoFromCursor(appContext, cursor));
                    Cp2Projections.buildCp2ContactInfoFromCursor(
                        appContext, cursor, Directory.DEFAULT));
              }
            }
          }
@@ -818,7 +821,8 @@ public final class Cp2DefaultDirectoryPhoneLookup implements PhoneLookup<Cp2Info
            } else {
              while (cursor.moveToNext()) {
                cp2ContactInfos.add(
                    Cp2Projections.buildCp2ContactInfoFromCursor(appContext, cursor));
                    Cp2Projections.buildCp2ContactInfoFromCursor(
                        appContext, cursor, Directory.DEFAULT));
              }
            }
          }
+1 −1
Original line number Diff line number Diff line
@@ -175,7 +175,7 @@ public final class Cp2ExtendedDirectoryPhoneLookup implements PhoneLookup<Cp2Inf

            do {
              cp2InfoBuilder.addCp2ContactInfo(
                  Cp2Projections.buildCp2ContactInfoFromCursor(appContext, cursor));
                  Cp2Projections.buildCp2ContactInfoFromCursor(appContext, cursor, directoryId));
            } while (cursor.moveToNext());
          }

+10 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.dialer.phonelookup.cp2;

import android.content.Context;
import android.database.Cursor;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.PhoneLookup;
@@ -85,7 +86,8 @@ final class Cp2Projections {
   * Builds a {@link Cp2ContactInfo} based on the current row of {@code cursor}, of which the
   * projection is either {@link #PHONE_PROJECTION} or {@link #PHONE_LOOKUP_PROJECTION}.
   */
  static Cp2ContactInfo buildCp2ContactInfoFromCursor(Context appContext, Cursor cursor) {
  static Cp2ContactInfo buildCp2ContactInfoFromCursor(
      Context appContext, Cursor cursor, long directoryId) {
    String displayName = cursor.getString(CP2_INFO_NAME_INDEX);
    String photoThumbnailUri = cursor.getString(CP2_INFO_PHOTO_THUMBNAIL_URI_INDEX);
    String photoUri = cursor.getString(CP2_INFO_PHOTO_URI_INDEX);
@@ -116,7 +118,13 @@ final class Cp2Projections {
    }
    infoBuilder.setContactId(contactId);
    if (!TextUtils.isEmpty(lookupKey)) {
      infoBuilder.setLookupUri(Contacts.getLookupUri(contactId, lookupKey).toString());
      infoBuilder.setLookupUri(
          Contacts.getLookupUri(contactId, lookupKey)
              .buildUpon()
              .appendQueryParameter(
                  ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId))
              .build()
              .toString());
    }

    // Only PHONE_PROJECTION has a column containing carrier presence info.