diff options
author | Tony Mak <tonymak@google.com> | 2016-02-22 20:35:29 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-02-22 20:35:29 +0000 |
commit | c58829eee08d834b40909ea780ba666af44262ed (patch) | |
tree | a46edcc3a24f3505363f59793541f3f246f93444 | |
parent | bc156d7884f221c8191a4c9a99ba3b4c35d1ef53 (diff) | |
parent | 639ed3451d911c9a282d1351b87595f3e1d8aaa4 (diff) |
Merge "Show Briefcase icon not displayed in in-call UI for work SIP calls" into nyc-dev
am: 639ed3451d
* commit '639ed3451d911c9a282d1351b87595f3e1d8aaa4':
Show Briefcase icon not displayed in in-call UI for work SIP calls
6 files changed, 122 insertions, 32 deletions
diff --git a/InCallUI/src/com/android/incallui/CallerInfo.java b/InCallUI/src/com/android/incallui/CallerInfo.java index 670c3fd66..55a4be6fd 100644 --- a/InCallUI/src/com/android/incallui/CallerInfo.java +++ b/InCallUI/src/com/android/incallui/CallerInfo.java @@ -16,6 +16,7 @@ package com.android.incallui; +import com.android.dialer.util.PhoneLookupUtil; import com.google.common.primitives.Longs; import android.content.Context; @@ -32,6 +33,8 @@ import android.provider.ContactsContract.RawContacts; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; +import com.android.contacts.common.compat.CompatUtils; +import com.android.contacts.common.compat.PhoneLookupSdkCompat; import com.android.contacts.common.ContactsUtils; import com.android.contacts.common.ContactsUtils.UserType; import com.android.contacts.common.util.PhoneNumberHelper; @@ -44,8 +47,9 @@ import com.android.dialer.calllog.ContactInfoHelper; public class CallerInfo { private static final String TAG = "CallerInfo"; - public static final String[] DEFAULT_PHONELOOKUP_PROJECTION = new String[] { - PhoneLookup._ID, + // We should always use this projection starting from NYC onward. + private static final String[] DEFAULT_PHONELOOKUP_PROJECTION = new String[] { + PhoneLookupSdkCompat.CONTACT_ID, PhoneLookup.DISPLAY_NAME, PhoneLookup.LOOKUP_KEY, PhoneLookup.NUMBER, @@ -57,6 +61,32 @@ public class CallerInfo { PhoneLookup.SEND_TO_VOICEMAIL }; + // In pre-N, contact id is stored in {@link PhoneLookup._ID} in non-sip query. + private static final String[] BACKWARD_COMPATIBLE_NON_SIP_DEFAULT_PHONELOOKUP_PROJECTION = + new String[] { + PhoneLookup._ID, + PhoneLookup.DISPLAY_NAME, + PhoneLookup.LOOKUP_KEY, + PhoneLookup.NUMBER, + PhoneLookup.NORMALIZED_NUMBER, + PhoneLookup.LABEL, + PhoneLookup.TYPE, + PhoneLookup.PHOTO_URI, + PhoneLookup.CUSTOM_RINGTONE, + PhoneLookup.SEND_TO_VOICEMAIL + }; + + public static String[] getDefaultPhoneLookupProjection(Uri phoneLookupUri) { + if (CompatUtils.isNCompatible()) { + return DEFAULT_PHONELOOKUP_PROJECTION; + } + // Pre-N + boolean isSip = phoneLookupUri.getBooleanQueryParameter( + ContactsContract.PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, false); + return (isSip) ? DEFAULT_PHONELOOKUP_PROJECTION + : BACKWARD_COMPATIBLE_NON_SIP_DEFAULT_PHONELOOKUP_PROJECTION; + } + /** * Please note that, any one of these member variables can be null, * and any accesses to them should be prepared to handle such a case. @@ -480,7 +510,7 @@ public class CallerInfo { // for phone numbers. // MIME type: PhoneLookup.CONTENT_TYPE (= "vnd.android.cursor.dir/phone_lookup") Log.v(TAG, "'phone_lookup' URI; using PhoneLookup._ID"); - columnName = PhoneLookup._ID; + columnName = PhoneLookupUtil.getContactIdColumnNameForUri(contactRef); } else { Log.v(TAG, "Unexpected prefix for contactRef '" + url + "'"); } diff --git a/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java b/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java index 590afafca..be5a275f3 100644 --- a/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java +++ b/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java @@ -407,13 +407,15 @@ public class CallerInfoAsyncQuery { cw.event = EVENT_NEW_QUERY; } + + String[] proejection = CallerInfo.getDefaultPhoneLookupProjection(contactRef); c.mHandler.startQuery(token, - cw, // cookie - contactRef, // uri - CallerInfo.DEFAULT_PHONELOOKUP_PROJECTION, // projection - null, // selection - null, // selectionArgs - null); // orderBy + cw, // cookie + contactRef, // uri + proejection, // projection + null, // selection + null, // selectionArgs + null); // orderBy return c; } diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index 75e7ab746..a9c7651d9 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -164,8 +164,7 @@ public class ContactInfoHelper { Cursor phoneLookupCursor = null; try { - String[] projection = (isSip) ? PhoneQuery.SIP_PHONE_LOOKUP_PROJECTION - : PhoneQuery.PHONE_LOOKUP_PROJECTION; + String[] projection = PhoneQuery.getPhoneLookupProjection(uri); phoneLookupCursor = mContext.getContentResolver().query(uri, projection, null, null, null); } catch (NullPointerException e) { diff --git a/src/com/android/dialer/calllog/PhoneQuery.java b/src/com/android/dialer/calllog/PhoneQuery.java index 5261874c8..f1f14c66e 100644 --- a/src/com/android/dialer/calllog/PhoneQuery.java +++ b/src/com/android/dialer/calllog/PhoneQuery.java @@ -16,10 +16,15 @@ package com.android.dialer.calllog; +import android.net.Uri; +import android.provider.ContactsContract; import android.provider.ContactsContract.Contacts; -import android.provider.ContactsContract.Data; import android.provider.ContactsContract.PhoneLookup; +import com.android.contacts.common.compat.CompatUtils; +import com.android.contacts.common.compat.PhoneLookupSdkCompat; +import com.android.contacts.common.ContactsUtils; + /** * The queries to look up the {@link ContactInfo} for a given number in the Call Log. */ @@ -27,10 +32,11 @@ final class PhoneQuery { /** * Projection to look up the ContactInfo. Does not include DISPLAY_NAME_ALTERNATIVE as that - * column isn't available in ContactsCommon.PhoneLookup + * column isn't available in ContactsCommon.PhoneLookup. + * We should always use this projection starting from NYC onward. */ - public static final String[] PHONE_LOOKUP_PROJECTION = new String[] { - PhoneLookup._ID, + private static final String[] PHONE_LOOKUP_PROJECTION = new String[] { + PhoneLookupSdkCompat.CONTACT_ID, PhoneLookup.DISPLAY_NAME, PhoneLookup.TYPE, PhoneLookup.LABEL, @@ -42,21 +48,32 @@ final class PhoneQuery { }; /** - * Similar to {@link PHONE_LOOKUP_PROJECTION}. Due to a bug in framework, the column name of - * contact id in normal phonelookup query is _id, but that in sip phonelookup query is - * contact_id. + * Similar to {@link PHONE_LOOKUP_PROJECTION}. In pre-N, contact id is stored in + * {@link PhoneLookup#_ID} in non-sip query. */ - public static final String[] SIP_PHONE_LOOKUP_PROJECTION = new String[] { - Data.CONTACT_ID, - PhoneLookup.DISPLAY_NAME, - PhoneLookup.TYPE, - PhoneLookup.LABEL, - PhoneLookup.NUMBER, - PhoneLookup.NORMALIZED_NUMBER, - PhoneLookup.PHOTO_ID, - PhoneLookup.LOOKUP_KEY, - PhoneLookup.PHOTO_URI - }; + private static final String[] BACKWARD_COMPATIBLE_NON_SIP_PHONE_LOOKUP_PROJECTION = + new String[] { + PhoneLookup._ID, + PhoneLookup.DISPLAY_NAME, + PhoneLookup.TYPE, + PhoneLookup.LABEL, + PhoneLookup.NUMBER, + PhoneLookup.NORMALIZED_NUMBER, + PhoneLookup.PHOTO_ID, + PhoneLookup.LOOKUP_KEY, + PhoneLookup.PHOTO_URI + }; + + public static String[] getPhoneLookupProjection(Uri phoneLookupUri) { + if (CompatUtils.isNCompatible()) { + return PHONE_LOOKUP_PROJECTION; + } + // Pre-N + boolean isSip = phoneLookupUri.getBooleanQueryParameter( + ContactsContract.PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, false); + return (isSip) ? PHONE_LOOKUP_PROJECTION + : BACKWARD_COMPATIBLE_NON_SIP_PHONE_LOOKUP_PROJECTION; + } public static final int PERSON_ID = 0; public static final int NAME = 1; diff --git a/src/com/android/dialer/util/PhoneLookupUtil.java b/src/com/android/dialer/util/PhoneLookupUtil.java new file mode 100644 index 000000000..1a7239642 --- /dev/null +++ b/src/com/android/dialer/util/PhoneLookupUtil.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.util; + +import android.net.Uri; +import android.provider.ContactsContract; + +import com.android.contacts.common.compat.CompatUtils; +import com.android.contacts.common.compat.PhoneLookupSdkCompat; + +public final class PhoneLookupUtil { + /** + * @return the column name that stores contact id for phone lookup query. + */ + public static String getContactIdColumnNameForUri(Uri phoneLookupUri) { + if (CompatUtils.isNCompatible()) { + return PhoneLookupSdkCompat.CONTACT_ID; + } + // In pre-N, contact id is stored in {@link PhoneLookup#_ID} in non-sip query. + boolean isSip = phoneLookupUri.getBooleanQueryParameter( + ContactsContract.PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, false); + return (isSip) ? PhoneLookupSdkCompat.CONTACT_ID : ContactsContract.PhoneLookup._ID; + } + + private PhoneLookupUtil() {} +} diff --git a/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java b/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java index 0e032c15f..680afb15f 100644 --- a/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java +++ b/tests/src/com/android/dialer/calllog/ContactInfoHelperTest.java @@ -63,7 +63,7 @@ public class ContactInfoHelperTest extends AndroidTestCase { public void testLookupContactFromUri_NoResults() { setUpQueryExpectations(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, - PhoneQuery.PHONE_LOOKUP_PROJECTION); + PhoneQuery.getPhoneLookupProjection(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI)); Assert.assertEquals(ContactInfo.EMPTY, mContactInfoHelper.lookupContactFromUri( PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, false)); @@ -72,7 +72,8 @@ public class ContactInfoHelperTest extends AndroidTestCase { public void testLookupContactFromUri_NoDisplayNameAlternative() { setUpQueryExpectations(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, - PhoneQuery.PHONE_LOOKUP_PROJECTION, TEST_LOOKUP_ROW); + PhoneQuery.getPhoneLookupProjection(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI), + TEST_LOOKUP_ROW); setUpQueryExpectations(displayNameAlternativeUri, PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION); @@ -85,7 +86,8 @@ public class ContactInfoHelperTest extends AndroidTestCase { public void testLookupContactFromUri_HasDisplayNameAlternative() { setUpQueryExpectations(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, - PhoneQuery.PHONE_LOOKUP_PROJECTION, TEST_LOOKUP_ROW); + PhoneQuery.getPhoneLookupProjection(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI), + TEST_LOOKUP_ROW); setUpQueryExpectations(displayNameAlternativeUri, PhoneQuery.DISPLAY_NAME_ALTERNATIVE_PROJECTION, TEST_DISPLAY_NAME_ALTERNATIVE_ROW); |