From abbbf058f5a72d8b6b709da18248d690e58f317a Mon Sep 17 00:00:00 2001 From: Victor Chang Date: Wed, 30 Mar 2016 15:30:58 +0100 Subject: 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 --- .../dialer/calllog/ContactInfoHelperTest.java | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'tests/src/com/android/dialer') diff --git a/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java b/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java index e53eb7893..df385f425 100644 --- a/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java +++ b/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java @@ -17,6 +17,7 @@ package com.android.dialer.calllog; import android.net.Uri; +import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; import android.provider.ContactsContract.PhoneLookup; import android.test.AndroidTestCase; @@ -101,14 +102,14 @@ public class ContactInfoHelperTest extends AndroidTestCase { public void testLookupDisplayNameAlternative_NullLookup() { Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, null, - ContactsUtils.USER_TYPE_CURRENT)); + ContactsUtils.USER_TYPE_CURRENT, null)); } public void testLookupDisplayNameAlternative_NoResults() { setUpQueryExpectations(displayNameAlternativeUri, PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION); Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, - TEST_LOOKUP_KEY, ContactsUtils.USER_TYPE_CURRENT)); + TEST_LOOKUP_KEY, ContactsUtils.USER_TYPE_CURRENT, null)); mContext.verify(); } @@ -117,10 +118,32 @@ public class ContactInfoHelperTest extends AndroidTestCase { PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION, TEST_DISPLAY_NAME_ALTERNATIVE_ROW); Assert.assertEquals(TEST_DISPLAY_NAME_ALTERNATIVE, mContactInfoHelper.lookUpDisplayNameAlternative(mContext, TEST_LOOKUP_KEY - , ContactsUtils.USER_TYPE_CURRENT)); + , ContactsUtils.USER_TYPE_CURRENT, null)); mContext.verify(); } + public void testLookupDisplayNameAlternative_EnterpriseLocalDirectory() { + Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, TEST_LOOKUP_KEY, + ContactsUtils.USER_TYPE_WORK, ContactsContract.Directory.ENTERPRISE_DEFAULT)); + Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, TEST_LOOKUP_KEY, + ContactsUtils.USER_TYPE_CURRENT, ContactsContract.Directory.ENTERPRISE_DEFAULT)); + } + + public void testLookupDisplayNameAlternative_EnterpriseRemoteDirectory() { + Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, TEST_LOOKUP_KEY, + ContactsUtils.USER_TYPE_WORK, + ContactsContract.Directory.ENTERPRISE_DEFAULT + 10)); + Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, TEST_LOOKUP_KEY, + ContactsUtils.USER_TYPE_CURRENT, + ContactsContract.Directory.ENTERPRISE_DEFAULT + 10)); + } + + public void testLookupDisplayNameAlternative_PersonalRemoteDirectory() { + Assert.assertNull(mContactInfoHelper.lookUpDisplayNameAlternative(mContext, null, + ContactsUtils.USER_TYPE_CURRENT, + ContactsContract.Directory.DEFAULT + 10)); + } + /* * Sets up query expectations to return the given row for all queries for the given * uri and projection. If row is null, an empty cursor is returned for query calls -- cgit v1.2.3