From cbed581719fdd31daa0f7aa096bb2ca7d40456d3 Mon Sep 17 00:00:00 2001 From: Jay Shrauner Date: Fri, 13 Nov 2015 09:36:04 -0800 Subject: Catch work profile CP2 lookup exception Catch IllegalArgumentExceptions throw for work profile contact alternative display name lookups. Bug:25680927 Change-Id: I1e3245239c8521de6edc5286a898547fc83bd23e --- .../android/dialer/calllog/ContactInfoHelper.java | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/com/android/dialer/calllog/ContactInfoHelper.java') diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index e760750b2..2da6840ba 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -198,23 +198,26 @@ public class ContactInfoHelper { return null; } - Uri uri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey); - - Cursor cursor = context.getContentResolver().query(uri, - PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION, null, null, null); - - if (cursor == null) { - return null; - } + final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey); + Cursor cursor = null; try { - if (!cursor.moveToFirst()) { - return null; + cursor = context.getContentResolver().query(uri, + PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION, null, null, null); + + if (cursor != null && cursor.moveToFirst()) { + return cursor.getString(PhoneQuery.NAME_ALTERNATIVE); } - return cursor.getString(PhoneQuery.NAME_ALTERNATIVE); + } catch (IllegalArgumentException e) { + // Thrown for work profile queries. For those, we don't support + // alternative display names. } finally { - cursor.close(); + if (cursor != null) { + cursor.close(); + } } + + return null; } /** -- cgit v1.2.3