diff options
Diffstat (limited to 'java/com/android/dialer/phonenumbercache')
4 files changed, 54 insertions, 9 deletions
diff --git a/java/com/android/dialer/phonenumbercache/CachedNumberLookupService.java b/java/com/android/dialer/phonenumbercache/CachedNumberLookupService.java index 2aed9e75e..c398251e4 100644 --- a/java/com/android/dialer/phonenumbercache/CachedNumberLookupService.java +++ b/java/com/android/dialer/phonenumbercache/CachedNumberLookupService.java @@ -49,6 +49,8 @@ public interface CachedNumberLookupService { boolean canReportAsInvalid(ContactSource.Type sourceType, String objectId); + boolean reportAsInvalid(Context context, CachedContactInfo cachedContactInfo); + /** @return return {@link Uri} to the photo or return {@code null} when failing to add photo */ @Nullable Uri addPhoto(Context context, String number, InputStream in); diff --git a/java/com/android/dialer/phonenumbercache/CallLogQuery.java b/java/com/android/dialer/phonenumbercache/CallLogQuery.java index 6d4756927..2ebc302cf 100644 --- a/java/com/android/dialer/phonenumbercache/CallLogQuery.java +++ b/java/com/android/dialer/phonenumbercache/CallLogQuery.java @@ -60,6 +60,9 @@ public final class CallLogQuery { @RequiresApi(VERSION_CODES.N) public static final int VIA_NUMBER = 25; + @RequiresApi(VERSION_CODES.O) + public static final int TRANSCRIPTION_STATE = 26; + private static final String[] PROJECTION_M = new String[] { Calls._ID, // 0 @@ -97,8 +100,23 @@ public final class CallLogQuery { PROJECTION_N = projectionList.toArray(new String[projectionList.size()]); } + private static final String[] PROJECTION_O; + + // TODO(mdooley): remove when this becomes a public api + // Copied from android.provider.CallLog.Calls + private static final String TRANSCRIPTION_STATE_COLUMN = "transcription_state"; + + static { + List<String> projectionList = new ArrayList<>(Arrays.asList(PROJECTION_N)); + projectionList.add(TRANSCRIPTION_STATE_COLUMN); + PROJECTION_O = projectionList.toArray(new String[projectionList.size()]); + } + @NonNull public static String[] getProjection() { + if (VERSION.SDK_INT >= VERSION_CODES.O) { + return PROJECTION_O; + } if (VERSION.SDK_INT >= VERSION_CODES.N) { return PROJECTION_N; } diff --git a/java/com/android/dialer/phonenumbercache/ContactInfo.java b/java/com/android/dialer/phonenumbercache/ContactInfo.java index 5546553f9..a620a2377 100644 --- a/java/com/android/dialer/phonenumbercache/ContactInfo.java +++ b/java/com/android/dialer/phonenumbercache/ContactInfo.java @@ -17,11 +17,11 @@ package com.android.dialer.phonenumbercache; import android.net.Uri; -import android.support.annotation.Nullable; +import android.support.annotation.NonNull; import android.text.TextUtils; import com.android.contacts.common.ContactsUtils.UserType; -import com.android.contacts.common.util.UriUtils; import com.android.dialer.logging.ContactSource; +import com.android.dialer.util.UriUtils; /** Information for a contact as needed by the Call Log. */ public class ContactInfo { @@ -59,7 +59,7 @@ public class ContactInfo { public boolean isBadData; public String objectId; public @UserType long userType; - public @Nullable ContactSource.Type sourceType = ContactSource.Type.UNKNOWN_SOURCE_TYPE; + public @NonNull ContactSource.Type sourceType = ContactSource.Type.UNKNOWN_SOURCE_TYPE; /** * True if local contact exists. This is only used for Cequint Caller ID so it won't overwrite * photo if local contact exists. diff --git a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java index bd4ba9764..b680bd57d 100644 --- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java +++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java @@ -38,7 +38,6 @@ import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.ContactsUtils.UserType; import com.android.contacts.common.compat.DirectoryCompat; import com.android.contacts.common.util.Constants; -import com.android.contacts.common.util.UriUtils; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.logging.ContactSource; @@ -48,6 +47,7 @@ import com.android.dialer.phonenumbercache.CachedNumberLookupService.CachedConta import com.android.dialer.phonenumberutil.PhoneNumberHelper; import com.android.dialer.telecom.TelecomUtil; import com.android.dialer.util.PermissionsUtil; +import com.android.dialer.util.UriUtils; import java.util.ArrayList; import java.util.List; import org.json.JSONException; @@ -203,6 +203,7 @@ public class ContactInfoHelper { return info; } + @Nullable public ContactInfo lookupNumber(String number, String countryIso) { return lookupNumber(number, countryIso, -1); } @@ -223,12 +224,14 @@ public class ContactInfoHelper { @SuppressWarnings("ReferenceEquality") public ContactInfo lookupNumber(String number, String countryIso, long directoryId) { if (TextUtils.isEmpty(number)) { + LogUtil.d("ContactInfoHelper.lookupNumber", "number is empty"); return null; } ContactInfo info; if (PhoneNumberHelper.isUriNumber(number)) { + LogUtil.d("ContactInfoHelper.lookupNumber", "number is sip"); // The number is a SIP address.. info = lookupContactFromUri(getContactInfoLookupUri(number, directoryId)); if (info == null || info == ContactInfo.EMPTY) { @@ -246,6 +249,7 @@ public class ContactInfoHelper { final ContactInfo updatedInfo; if (info == null) { // The lookup failed. + LogUtil.d("ContactInfoHelper.lookupNumber", "lookup failed"); updatedInfo = null; } else { // If we did not find a matching contact, generate an empty contact info for the number. @@ -325,9 +329,11 @@ public class ContactInfoHelper { */ ContactInfo lookupContactFromUri(Uri uri) { if (uri == null) { + LogUtil.d("ContactInfoHelper.lookupContactFromUri", "uri is null"); return null; } if (!PermissionsUtil.hasContactsReadPermissions(mContext)) { + LogUtil.d("ContactInfoHelper.lookupContactFromUri", "no contact permission, return empty"); return ContactInfo.EMPTY; } @@ -336,10 +342,12 @@ public class ContactInfoHelper { String[] projection = PhoneQuery.getPhoneLookupProjection(uri); phoneLookupCursor = mContext.getContentResolver().query(uri, projection, null, null, null); } catch (NullPointerException e) { + LogUtil.e("ContactInfoHelper.lookupContactFromUri", "phone lookup", e); // Trap NPE from pre-N CP2 return null; } if (phoneLookupCursor == null) { + LogUtil.d("ContactInfoHelper.lookupContactFromUri", "phoneLookupCursor is null"); return null; } @@ -408,19 +416,32 @@ public class ContactInfoHelper { private ContactInfo queryContactInfoForPhoneNumber( String number, String countryIso, long directoryId) { if (TextUtils.isEmpty(number)) { + LogUtil.d("ContactInfoHelper.queryContactInfoForPhoneNumber", "number is empty"); return null; } ContactInfo info = lookupContactFromUri(getContactInfoLookupUri(number, directoryId)); + if (info == null) { + LogUtil.d("ContactInfoHelper.queryContactInfoForPhoneNumber", "info looked up is null"); + } if (info != null && info != ContactInfo.EMPTY) { info.formattedNumber = formatPhoneNumber(number, null, countryIso); + if (directoryId == -1) { + // Contact found in the default directory + info.sourceType = ContactSource.Type.SOURCE_TYPE_DIRECTORY; + } else { + // Contact found in the extended directory specified by directoryId + info.sourceType = ContactSource.Type.SOURCE_TYPE_EXTENDED; + } } else if (mCachedNumberLookupService != null) { CachedContactInfo cacheInfo = mCachedNumberLookupService.lookupCachedContactFromNumber(mContext, number); if (cacheInfo != null) { - info = cacheInfo.getContactInfo().isBadData ? null : cacheInfo.getContactInfo(); - } else { - info = null; + if (!cacheInfo.getContactInfo().isBadData) { + info = cacheInfo.getContactInfo(); + } else { + LogUtil.i("ContactInfoHelper.queryContactInfoForPhoneNumber", "info is bad data"); + } } } return info; @@ -601,13 +622,17 @@ public class ContactInfoHelper { * will be updated if available. */ @WorkerThread - public void updateFromCequintCallerId(ContactInfo info, String number) { + public void updateFromCequintCallerId( + @Nullable CequintCallerIdManager cequintCallerIdManager, ContactInfo info, String number) { Assert.isWorkerThread(); if (!CequintCallerIdManager.isCequintCallerIdEnabled(mContext)) { return; } + if (cequintCallerIdManager == null) { + return; + } CequintCallerIdContact cequintCallerIdContact = - CequintCallerIdManager.getCequintCallerIdContact(mContext, number); + cequintCallerIdManager.getCequintCallerIdContact(mContext, number); if (cequintCallerIdContact == null) { return; } |