diff options
author | Victor Chang <vichang@google.com> | 2016-03-30 15:30:58 +0100 |
---|---|---|
committer | Victor Chang <vichang@google.com> | 2016-03-30 19:23:33 +0100 |
commit | abbbf058f5a72d8b6b709da18248d690e58f317a (patch) | |
tree | 99a7d683505d5892fde3783e0e6c1fb2f19bd5f6 /src/com/android | |
parent | 1d764e39c9f9c94d81dd22cd2a53e2c94ce22cfc (diff) |
Fix Dialer crash loop for caller id in personal contact directory
The bug is dialer queries CP2 for alternative name by lookup key of personal directory
CP2 throws IllegalArgumentException as the lookup key is not found locally
2 fixes are included to avoid this happening
1. slient IllegalArgumentException since alternative name is not very important to crash dialer.
(It's a fix by reverting some changes in ag/880910)
2. Check directory id before querying CP2
either one should fix this bug. Include both to make sure that it's not crashed.
Unit test added.
Bug:27905000
Change-Id: Ib8eab5f718a168fcec2785c3101e96bb91521d40
Diffstat (limited to 'src/com/android')
-rw-r--r-- | src/com/android/dialer/calllog/ContactInfoHelper.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index 6e84a92f9..abbddd241 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -14,6 +14,8 @@ package com.android.dialer.calllog; +import com.google.common.primitives.Longs; + import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -33,6 +35,7 @@ import android.util.Log; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.ContactsUtils.UserType; import com.android.contacts.common.compat.CompatUtils; +import com.android.contacts.common.compat.DirectoryCompat; import com.android.contacts.common.util.Constants; import com.android.contacts.common.util.PermissionsUtil; import com.android.contacts.common.util.PhoneNumberHelper; @@ -163,6 +166,9 @@ public class ContactInfoHelper { return ContactInfo.EMPTY; } + final String directory = uri.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY); + final Long directoryId = directory == null ? null : Longs.tryParse(directory); + Cursor phoneLookupCursor = null; try { String[] projection = PhoneQuery.getPhoneLookupProjection(uri); @@ -183,7 +189,7 @@ public class ContactInfoHelper { String lookupKey = phoneLookupCursor.getString(PhoneQuery.LOOKUP_KEY); ContactInfo contactInfo = createPhoneLookupContactInfo(phoneLookupCursor, lookupKey); contactInfo.nameAlternative = lookUpDisplayNameAlternative(mContext, lookupKey, - contactInfo.userType); + contactInfo.userType, directoryId); return contactInfo; } finally { phoneLookupCursor.close(); @@ -210,11 +216,24 @@ public class ContactInfoHelper { } public static String lookUpDisplayNameAlternative(Context context, String lookupKey, - @UserType long userType) { + @UserType long userType, @Nullable Long directoryId) { // Query {@link Contacts#CONTENT_LOOKUP_URI} directly with work lookup key is not allowed. if (lookupKey == null || userType == ContactsUtils.USER_TYPE_WORK) { return null; } + + if (directoryId != null) { + // Query {@link Contacts#CONTENT_LOOKUP_URI} with work lookup key is not allowed. + if (DirectoryCompat.isEnterpriseDirectoryId(directoryId)) { + return null; + } + + // Skip this to avoid an extra remote network call for alternative name + if (DirectoryCompat.isRemoteDirectory(directoryId)) { + return null; + } + } + final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey); Cursor cursor = null; try { @@ -224,6 +243,9 @@ public class ContactInfoHelper { if (cursor != null && cursor.moveToFirst()) { return cursor.getString(PhoneQuery.NAME_ALTERNATIVE); } + } catch (IllegalArgumentException e) { + // Avoid dialer crash when lookup key is not valid + Log.e(TAG, "IllegalArgumentException in lookUpDisplayNameAlternative", e); } finally { if (cursor != null) { cursor.close(); |