diff options
16 files changed, 213 insertions, 40 deletions
diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 2e2bea8ce..690b3e10a 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -107,11 +107,19 @@ public class CallDetailActivity extends AppCompatActivity // All calls are from the same number and same contact, so pick the first detail. mDetails = details[0]; mNumber = TextUtils.isEmpty(mDetails.number) ? null : mDetails.number.toString(); + mPostDialDigits = TextUtils.isEmpty(mDetails.postDialDigits) + ? "" : mDetails.postDialDigits; mDisplayNumber = mDetails.displayNumber; final CharSequence callLocationOrType = getNumberTypeOrLocation(mDetails); - final CharSequence displayNumber = mDetails.displayNumber; + final CharSequence displayNumber; + if (!TextUtils.isEmpty(mDetails.postDialDigits)) { + displayNumber = mDetails.number + mDetails.postDialDigits; + } else { + displayNumber = mDetails.displayNumber; + } + final String displayNumberStr = mBidiFormatter.unicodeWrap( displayNumber.toString(), TextDirectionHeuristics.LTR); @@ -197,6 +205,7 @@ public class CallDetailActivity extends AppCompatActivity private PhoneCallDetails mDetails; protected String mNumber; private Uri mVoicemailUri; + private String mPostDialDigits = ""; private String mDisplayNumber; private ListView mHistoryList; @@ -252,7 +261,7 @@ public class CallDetailActivity extends AppCompatActivity return; } mContext.startActivity( - new CallIntentBuilder(mNumber) + new CallIntentBuilder(getDialableNumber()) .setCallInitiationType(LogState.INITIATION_CALL_DETAILS) .build()); } @@ -371,7 +380,8 @@ public class CallDetailActivity extends AppCompatActivity ClipboardUtils.copyText(mContext, null, mNumber, true); break; case R.id.call_detail_action_edit_before_call: - Intent dialIntent = new Intent(Intent.ACTION_DIAL, CallUtil.getCallUri(mNumber)); + Intent dialIntent = new Intent(Intent.ACTION_DIAL, + CallUtil.getCallUri(getDialableNumber())); DialerUtils.startActivityWithErrorToast(mContext, dialIntent); break; default: @@ -460,6 +470,10 @@ public class CallDetailActivity extends AppCompatActivity sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); } + private String getDialableNumber() { + return mNumber + mPostDialDigits; + } + @NeededForTesting public boolean hasVoicemail() { return mVoicemailUri != null; diff --git a/src/com/android/dialer/PhoneCallDetails.java b/src/com/android/dialer/PhoneCallDetails.java index fb1827dc4..71aa26d15 100644 --- a/src/com/android/dialer/PhoneCallDetails.java +++ b/src/com/android/dialer/PhoneCallDetails.java @@ -31,6 +31,8 @@ import android.text.TextUtils; public class PhoneCallDetails { // The number of the other party involved in the call. public CharSequence number; + // Post-dial digits associated with the outgoing call. + public String postDialDigits; // The number presenting rules set by the network, e.g., {@link Calls#PRESENTATION_ALLOWED} public int numberPresentation; // The formatted version of {@link #number}. @@ -114,16 +116,19 @@ public class PhoneCallDetails { CharSequence number, int numberPresentation, CharSequence formattedNumber, + CharSequence postDialDigits, boolean isVoicemail) { this.number = number; this.numberPresentation = numberPresentation; this.formattedNumber = formattedNumber; this.isVoicemail = isVoicemail; + this.postDialDigits = postDialDigits.toString(); this.displayNumber = PhoneNumberDisplayUtil.getDisplayNumber( context, this.number, this.numberPresentation, this.formattedNumber, + this.postDialDigits, this.isVoicemail).toString(); } diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index 42b2f230d..53fe9f748 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -423,6 +423,9 @@ public class CallLogAdapter extends GroupingListAdapter int count = getGroupSize(position); final String number = c.getString(CallLogQuery.NUMBER); + final String postDialDigits = PhoneNumberDisplayUtil.canShowPostDial() + ? c.getString(CallLogQuery.POST_DIAL_DIGITS) : ""; + final int numberPresentation = c.getInt(CallLogQuery.NUMBER_PRESENTATION); final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount( c.getString(CallLogQuery.ACCOUNT_COMPONENT_NAME), @@ -438,13 +441,15 @@ public class CallLogAdapter extends GroupingListAdapter ContactInfo info = ContactInfo.EMPTY; if (PhoneNumberUtil.canPlaceCallsTo(number, numberPresentation) && !isVoicemailNumber) { // Lookup contacts with this number - info = mContactInfoCache.getValue(number, countryIso, cachedContactInfo); + info = mContactInfoCache.getValue(number + postDialDigits, + countryIso, cachedContactInfo); } CharSequence formattedNumber = info.formattedNumber == null ? null : PhoneNumberUtils.createTtsSpannable(info.formattedNumber); final PhoneCallDetails details = new PhoneCallDetails( - mContext, number, numberPresentation, formattedNumber, isVoicemailNumber); + mContext, number, numberPresentation, formattedNumber, + postDialDigits, isVoicemailNumber); details.accountHandle = accountHandle; details.callTypes = getCallTypes(c, count); details.countryIso = countryIso; @@ -478,6 +483,7 @@ public class CallLogAdapter extends GroupingListAdapter views.rowId = c.getLong(CallLogQuery.ID); // Store values used when the actions ViewStub is inflated on expansion. views.number = number; + views.postDialDigits = details.postDialDigits; views.displayNumber = details.displayNumber; views.numberPresentation = numberPresentation; views.callType = c.getInt(CallLogQuery.CALL_TYPE); diff --git a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java index 777156345..bb7bdbd0a 100644 --- a/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java +++ b/src/com/android/dialer/calllog/CallLogAsyncTaskUtil.java @@ -39,6 +39,9 @@ import com.android.dialer.util.TelecomUtil; import com.google.common.annotations.VisibleForTesting; +import java.util.ArrayList; +import java.util.Arrays; + public class CallLogAsyncTaskUtil { private static String TAG = CallLogAsyncTaskUtil.class.getSimpleName(); @@ -51,8 +54,9 @@ public class CallLogAsyncTaskUtil { GET_CALL_DETAILS, } - private static class CallDetailQuery { - static final String[] CALL_LOG_PROJECTION = new String[] { + private static final class CallDetailQuery { + + private static final String[] CALL_LOG_PROJECTION_INTERNAL = new String[] { CallLog.Calls.DATE, CallLog.Calls.DURATION, CallLog.Calls.NUMBER, @@ -66,6 +70,7 @@ public class CallLogAsyncTaskUtil { CallLog.Calls.DATA_USAGE, CallLog.Calls.TRANSCRIPTION }; + public static final String[] CALL_LOG_PROJECTION; static final int DATE_COLUMN_INDEX = 0; static final int DURATION_COLUMN_INDEX = 1; @@ -79,6 +84,17 @@ public class CallLogAsyncTaskUtil { static final int FEATURES = 9; static final int DATA_USAGE = 10; static final int TRANSCRIPTION_COLUMN_INDEX = 11; + static final int POST_DIAL_DIGITS = 12; + + static { + ArrayList<String> projectionList = new ArrayList<>(); + projectionList.addAll(Arrays.asList(CALL_LOG_PROJECTION_INTERNAL)); + if (PhoneNumberDisplayUtil.canShowPostDial()) { + projectionList.add(AppCompatConstants.POST_DIAL_DIGITS); + } + projectionList.trimToSize(); + CALL_LOG_PROJECTION = projectionList.toArray(new String[projectionList.size()]); + } } private static class CallLogDeleteBlockedCallQuery { @@ -164,6 +180,8 @@ public class CallLogAsyncTaskUtil { // Read call log. final String countryIso = cursor.getString(CallDetailQuery.COUNTRY_ISO_COLUMN_INDEX); final String number = cursor.getString(CallDetailQuery.NUMBER_COLUMN_INDEX); + final String postDialDigits = PhoneNumberDisplayUtil.canShowPostDial() + ? cursor.getString(CallDetailQuery.POST_DIAL_DIGITS) : ""; final int numberPresentation = cursor.getInt(CallDetailQuery.NUMBER_PRESENTATION_COLUMN_INDEX); @@ -185,7 +203,8 @@ public class CallLogAsyncTaskUtil { } PhoneCallDetails details = new PhoneCallDetails( - context, number, numberPresentation, info.formattedNumber, isVoicemail); + context, number, numberPresentation, info.formattedNumber, + postDialDigits, isVoicemail); details.accountHandle = accountHandle; details.contactUri = info.lookupUri; diff --git a/src/com/android/dialer/calllog/CallLogGroupBuilder.java b/src/com/android/dialer/calllog/CallLogGroupBuilder.java index 5eea096b8..194231b90 100644 --- a/src/com/android/dialer/calllog/CallLogGroupBuilder.java +++ b/src/com/android/dialer/calllog/CallLogGroupBuilder.java @@ -17,7 +17,6 @@ package com.android.dialer.calllog; import android.database.Cursor; -import android.provider.CallLog.Calls; import android.telephony.PhoneNumberUtils; import android.text.format.Time; import android.text.TextUtils; @@ -28,8 +27,6 @@ import com.android.dialer.util.AppCompatConstants; import com.google.common.annotations.VisibleForTesting; -import java.util.Objects; - /** * Groups together calls in the call log. The primary grouping attempts to group together calls * to and from the same number into a single row on the call log. @@ -125,12 +122,15 @@ public class CallLogGroupBuilder { // Instantiate the group values to those of the first call in the cursor. String groupNumber = cursor.getString(CallLogQuery.NUMBER); + String groupPostDialDigits = PhoneNumberDisplayUtil.canShowPostDial() + ? cursor.getString(CallLogQuery.POST_DIAL_DIGITS) : ""; int groupCallType = cursor.getInt(CallLogQuery.CALL_TYPE); String groupAccountComponentName = cursor.getString(CallLogQuery.ACCOUNT_COMPONENT_NAME); String groupAccountId = cursor.getString(CallLogQuery.ACCOUNT_ID); int groupSize = 1; String number; + String numberPostDialDigits; int callType; String accountComponentName; String accountId; @@ -138,17 +138,21 @@ public class CallLogGroupBuilder { while (cursor.moveToNext()) { // Obtain the values for the current call to group. number = cursor.getString(CallLogQuery.NUMBER); + numberPostDialDigits = PhoneNumberDisplayUtil.canShowPostDial() + ? cursor.getString(CallLogQuery.POST_DIAL_DIGITS) : ""; callType = cursor.getInt(CallLogQuery.CALL_TYPE); accountComponentName = cursor.getString(CallLogQuery.ACCOUNT_COMPONENT_NAME); accountId = cursor.getString(CallLogQuery.ACCOUNT_ID); final boolean isSameNumber = equalNumbers(groupNumber, number); + final boolean isSamePostDialDigits = groupPostDialDigits.equals(numberPostDialDigits); final boolean isSameAccount = isSameAccount( groupAccountComponentName, accountComponentName, groupAccountId, accountId); // Group with the same number and account. Never group voicemails. Only group blocked // calls with other blocked calls. - if (isSameNumber && isSameAccount && areBothNotVoicemail(callType, groupCallType) + if (isSameNumber && isSameAccount && isSamePostDialDigits + && areBothNotVoicemail(callType, groupCallType) && (areBothNotBlocked(callType, groupCallType) || areBothBlocked(callType, groupCallType))) { // Increment the size of the group to include the current call, but do not create @@ -168,6 +172,7 @@ public class CallLogGroupBuilder { // Update the group values to those of the current call. groupNumber = number; + groupPostDialDigits = numberPostDialDigits; groupCallType = callType; groupAccountComponentName = accountComponentName; groupAccountId = accountId; diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java index be0e146bf..fb2bab8cc 100644 --- a/src/com/android/dialer/calllog/CallLogListItemHelper.java +++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java @@ -16,7 +16,6 @@ package com.android.dialer.calllog; -import android.content.Context; import android.content.res.Resources; import android.provider.CallLog.Calls; import android.text.SpannableStringBuilder; @@ -263,7 +262,7 @@ import com.android.dialer.R; if (!TextUtils.isEmpty(details.getPreferredName())) { recipient = details.getPreferredName(); } else { - recipient = details.displayNumber; + recipient = details.displayNumber + details.postDialDigits; } return recipient; } diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index 89596f2e1..b82b35dbf 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -111,6 +111,11 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder public String number; /** + * The post-dial numbers that are dialed following the phone number. + */ + public String postDialDigits; + + /** * The formatted phone number to display. */ public String displayNumber; @@ -416,7 +421,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder IntentProvider.getReturnVoicemailCallIntentProvider()); } else { primaryActionButtonView.setTag( - IntentProvider.getReturnCallIntentProvider(number)); + IntentProvider.getReturnCallIntentProvider(number + postDialDigits)); } primaryActionButtonView.setContentDescription(TextUtils.expandTemplate( @@ -596,7 +601,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder info.lookupUri, (String) nameOrNumber /* top line of contact view in call subject dialog */, isBusiness, - number, /* callable number used for ACTION_CALL intent */ + number, TextUtils.isEmpty(info.name) ? null : displayNumber, /* second line of contact view in dialog. */ numberType, /* phone number type (e.g. mobile) in second line of contact view */ diff --git a/src/com/android/dialer/calllog/CallLogQuery.java b/src/com/android/dialer/calllog/CallLogQuery.java index 2b43c2857..3f798010e 100644 --- a/src/com/android/dialer/calllog/CallLogQuery.java +++ b/src/com/android/dialer/calllog/CallLogQuery.java @@ -18,11 +18,17 @@ package com.android.dialer.calllog; import android.provider.CallLog.Calls; +import com.android.dialer.util.AppCompatConstants; + +import java.util.ArrayList; +import java.util.Arrays; + /** * The query for the call log table. */ public final class CallLogQuery { - public static final String[] _PROJECTION = new String[] { + + private static final String[] _PROJECTION_INTERNAL = new String[] { Calls._ID, // 0 Calls.NUMBER, // 1 Calls.DATE, // 2 @@ -73,4 +79,18 @@ public final class CallLogQuery { public static final int DATA_USAGE = 21; public static final int TRANSCRIPTION = 22; public static final int CACHED_PHOTO_URI = 23; + public static final int POST_DIAL_DIGITS = 24; + + public static final String[] _PROJECTION; + + static { + ArrayList<String> projectionList = new ArrayList<String>(); + projectionList.addAll(Arrays.asList(_PROJECTION_INTERNAL)); + if (PhoneNumberDisplayUtil.canShowPostDial()) { + projectionList.add(AppCompatConstants.POST_DIAL_DIGITS); + } + projectionList.trimToSize(); + _PROJECTION = projectionList.toArray(new String[projectionList.size()]); + } + } diff --git a/src/com/android/dialer/calllog/ContactInfoHelper.java b/src/com/android/dialer/calllog/ContactInfoHelper.java index e760750b2..5d88efee2 100644 --- a/src/com/android/dialer/calllog/ContactInfoHelper.java +++ b/src/com/android/dialer/calllog/ContactInfoHelper.java @@ -397,7 +397,11 @@ public class ContactInfoHelper { info.type = c.getInt(CallLogQuery.CACHED_NUMBER_TYPE); info.label = c.getString(CallLogQuery.CACHED_NUMBER_LABEL); String matchedNumber = c.getString(CallLogQuery.CACHED_MATCHED_NUMBER); - info.number = matchedNumber == null ? c.getString(CallLogQuery.NUMBER) : matchedNumber; + String postDialDigits = PhoneNumberDisplayUtil.canShowPostDial() + ? c.getString(CallLogQuery.POST_DIAL_DIGITS) : ""; + info.number = (matchedNumber == null) ? + c.getString(CallLogQuery.NUMBER) + postDialDigits : matchedNumber; + info.normalizedNumber = c.getString(CallLogQuery.CACHED_NORMALIZED_NUMBER); info.photoId = c.getLong(CallLogQuery.CACHED_PHOTO_ID); info.photoUri = UriUtils.nullForNonContactsUri( diff --git a/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java b/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java index 5030efd48..91cd3e1f0 100644 --- a/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java +++ b/src/com/android/dialer/calllog/PhoneNumberDisplayUtil.java @@ -17,10 +17,9 @@ package com.android.dialer.calllog; import android.content.Context; -import android.content.res.Resources; +import android.os.Build; import android.provider.CallLog.Calls; import android.text.TextUtils; -import android.util.Log; import com.android.dialer.R; import com.android.dialer.util.PhoneNumberUtil; @@ -67,6 +66,7 @@ public class PhoneNumberDisplayUtil { CharSequence number, int presentation, CharSequence formattedNumber, + CharSequence postDialDigits, boolean isVoicemail) { final CharSequence displayName = getDisplayName(context, number, presentation, isVoicemail); if (!TextUtils.isEmpty(displayName)) { @@ -76,9 +76,18 @@ public class PhoneNumberDisplayUtil { if (!TextUtils.isEmpty(formattedNumber)) { return formattedNumber; } else if (!TextUtils.isEmpty(number)) { - return number; + return number.toString() + postDialDigits; } else { return ""; } } + + /** + * Returns whether we can expect the post-dial digits to be in the call log. + * + * These digits will be present in versions N+. + */ + public static boolean canShowPostDial() { + return Build.VERSION.SDK_INT > Build.VERSION_CODES.M; + } } diff --git a/src/com/android/dialer/util/AppCompatConstants.java b/src/com/android/dialer/util/AppCompatConstants.java index 1d52eee1d..0bb78df26 100644 --- a/src/com/android/dialer/util/AppCompatConstants.java +++ b/src/com/android/dialer/util/AppCompatConstants.java @@ -27,4 +27,6 @@ public final class AppCompatConstants { public static final int CALLS_REJECTED_TYPE = 5; // Added to android.provider.CallLog.Calls in N+. public static final int CALLS_BLOCKED_TYPE = 6; + // Added to android.provider.CallLog.Calls in N+. + public static final String POST_DIAL_DIGITS = "post_dial_digits"; } diff --git a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java index a5a61ad46..13ca0fd76 100644 --- a/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogAdapterTest.java @@ -64,6 +64,7 @@ public class CallLogAdapterTest extends AndroidTestCase { private static final String TEST_NUMBER_1 = "12345678"; private static final String TEST_NUMBER_2 = "87654321"; private static final String TEST_NUMBER_3 = "18273645"; + private static final String TEST_POST_DIAL_DIGITS = ";12345"; private static final String TEST_FORMATTED_NUMBER = "1 212-555-1000"; // The object under test. @@ -233,6 +234,16 @@ public class CallLogAdapterTest extends AndroidTestCase { } @MediumTest + public void testBindView_CallButtonWithPostDialDigits() { + createCallLogEntry(TEST_NUMBER, TEST_POST_DIAL_DIGITS, NO_VALUE_SET, NO_VALUE_SET); + + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + assertHasCallActionToGivenNumber(mViewHolder, TEST_NUMBER + TEST_POST_DIAL_DIGITS); + } + + @MediumTest public void testBindView_VoicemailUri() { createVoicemailCallLogEntry(); @@ -245,6 +256,28 @@ public class CallLogAdapterTest extends AndroidTestCase { } @MediumTest + public void testBindView_NumberWithPostDialDigits() { + createCallLogEntry(TEST_NUMBER, TEST_POST_DIAL_DIGITS, NO_VALUE_SET, NO_VALUE_SET); + + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + assertNameIs(mViewHolder, TEST_NUMBER + TEST_POST_DIAL_DIGITS); + } + + @MediumTest + public void testBindView_ContactWithPrefix() { + createCallLogEntry(TEST_NUMBER, TEST_POST_DIAL_DIGITS, NO_VALUE_SET, NO_VALUE_SET); + mAdapter.injectContactInfoForTest(TEST_NUMBER + TEST_POST_DIAL_DIGITS, TEST_COUNTRY_ISO, + createContactInfo()); + + mAdapter.changeCursor(mCursor); + mAdapter.onBindViewHolder(mViewHolder, 0); + + assertNameIs(mViewHolder, TEST_CACHED_NAME); + } + + @MediumTest public void testPresentationAfterRebindingViewHolders() { final int increment = 10; final int size = increment * 4; @@ -513,12 +546,13 @@ public class CallLogAdapterTest extends AndroidTestCase { } private void createCallLogEntry(String testNumber) { - createCallLogEntry(testNumber, NO_VALUE_SET, NO_VALUE_SET); + createCallLogEntry(testNumber, EMPTY_STRING, NO_VALUE_SET, NO_VALUE_SET); } private void createPrivateCallLogEntry() { createCallLogEntry( EMPTY_STRING, + EMPTY_STRING, Calls.PRESENTATION_RESTRICTED, AppCompatConstants.CALLS_INCOMING_TYPE); } @@ -526,16 +560,17 @@ public class CallLogAdapterTest extends AndroidTestCase { private void createUnknownCallLogEntry() { createCallLogEntry( EMPTY_STRING, + EMPTY_STRING, Calls.PRESENTATION_UNKNOWN, AppCompatConstants.CALLS_INCOMING_TYPE); } private void createVoicemailCallLogEntry() { - createCallLogEntry(TEST_NUMBER, NO_VALUE_SET, Calls.VOICEMAIL_TYPE); + createCallLogEntry(TEST_NUMBER, EMPTY_STRING, NO_VALUE_SET, Calls.VOICEMAIL_TYPE); } - private void createCallLogEntry(String number, int presentation, int type) { - Object[] values = getValues(number, presentation, type); + private void createCallLogEntry(String number, String postDialDigits, int presentation, int type) { + Object[] values = getValues(number, postDialDigits, presentation, type); mCursor.addRow(values); } @@ -583,7 +618,7 @@ public class CallLogAdapterTest extends AndroidTestCase { String cachedNumberLabel, String cachedFormattedNumber, boolean inject) { - Object[] values = getValues(number, NO_VALUE_SET, type); + Object[] values = getValues(number, EMPTY_STRING, NO_VALUE_SET, type); values[CallLogQuery.CACHED_NAME] = cachedName; values[CallLogQuery.CACHED_NUMBER_TYPE] = cachedNumberType; values[CallLogQuery.CACHED_NUMBER_LABEL] = cachedNumberLabel; @@ -600,12 +635,14 @@ public class CallLogAdapterTest extends AndroidTestCase { /** * @param number The phone number. + * @param postDialDigits The post dial digits dialed (if any) * @param presentation Number representing display rules for "allowed", * "payphone", "restricted", or "unknown". - * @param date In millisec since epoch. Use NOW to use the current time. + * @param type The type of the call (outgoing/ingoing) */ private Object[] getValues( String number, + String postDialDigits, int presentation, int type) { Object[] values = CallLogQueryTestUtils.createTestValues(); @@ -618,6 +655,9 @@ public class CallLogAdapterTest extends AndroidTestCase { if (!TextUtils.isEmpty(number)) { values[CallLogQuery.NUMBER] = number; } + if (!TextUtils.isEmpty(postDialDigits)) { + values[CallLogQuery.POST_DIAL_DIGITS] = postDialDigits; + } if (presentation != NO_VALUE_SET) { values[CallLogQuery.NUMBER_PRESENTATION] = presentation; } @@ -676,14 +716,16 @@ public class CallLogAdapterTest extends AndroidTestCase { } private void assertHasCallAction(CallLogListItemViewHolder viewHolder) { - // The primaryActionView tag is set when the ViewHolder is binded. If it is possible - // to place a call to the phone number, a call intent will have been created which - // starts a phone call to the entry's number. + assertHasCallActionToGivenNumber(viewHolder, TEST_NUMBER); + } + + private void assertHasCallActionToGivenNumber(CallLogListItemViewHolder viewHolder, + String number) { IntentProvider intentProvider = (IntentProvider) viewHolder.primaryActionButtonView.getTag(); Intent intent = intentProvider.getIntent(getContext()); assertEquals(TestConstants.CALL_INTENT_ACTION, intent.getAction()); - assertEquals(Uri.parse("tel:" + TEST_NUMBER), intent.getData()); + assertEquals(Uri.parse("tel:" + Uri.encode(number)), intent.getData()); } /** Returns the label associated with a given phone type. */ diff --git a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java index 5d0b6bebb..fa18afff5 100644 --- a/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogGroupBuilderTest.java @@ -35,6 +35,8 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { private static final String TEST_NUMBER1 = "14125551234"; /** A phone number for testing. */ private static final String TEST_NUMBER2 = "14125555555"; + /** A post-dial string for testing */ + private static final String TEST_POST_DIAL_DIGITS = ";12435;0987"; /** The object under test. */ private CallLogGroupBuilder mBuilder; @@ -86,6 +88,21 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { assertGroupIs(0, 3, mFakeGroupCreator.groups.get(0)); } + public void testAddGroups_WithPostDialMatching() { + addCallLogEntryWithPostDialDigits(TEST_NUMBER1, TEST_POST_DIAL_DIGITS, + AppCompatConstants.CALLS_OUTGOING_TYPE); + addCallLogEntryWithPostDialDigits(TEST_NUMBER1, TEST_POST_DIAL_DIGITS, + AppCompatConstants.CALLS_OUTGOING_TYPE); + addCallLogEntryWithPostDialDigits(TEST_NUMBER1, "", + AppCompatConstants.CALLS_OUTGOING_TYPE); + + mBuilder.addGroups(mCursor); + + assertEquals(2, mFakeGroupCreator.groups.size()); + assertGroupIs(0, 2, mFakeGroupCreator.groups.get(0)); + assertGroupIs(2, 1, mFakeGroupCreator.groups.get(1)); + } + public void testAddGroups_MatchingIncomingAndOutgoing() { addCallLogEntry(TEST_NUMBER1, AppCompatConstants.CALLS_INCOMING_TYPE); addCallLogEntry(TEST_NUMBER1, AppCompatConstants.CALLS_OUTGOING_TYPE); @@ -312,11 +329,17 @@ public class CallLogGroupBuilderTest extends AndroidTestCase { } /** Adds a call log entry with the given number and type to the cursor. */ private void addCallLogEntry(String number, int type) { + addCallLogEntryWithPostDialDigits(number, "", type); + } + + /** Adds a call log entry with the given number, post-dial digits, and type to the cursor. */ + private void addCallLogEntryWithPostDialDigits(String number, String postDialDigits, int type) { mCursor.moveToNext(); Object[] values = CallLogQueryTestUtils.createTestValues(); values[CallLogQuery.ID] = mCursor.getPosition(); values[CallLogQuery.NUMBER] = number; values[CallLogQuery.CALL_TYPE] = type; + values[CallLogQuery.POST_DIAL_DIGITS] = postDialDigits; mCursor.addRow(values); } diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java index c9d826473..a97fce3f7 100644 --- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java +++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java @@ -246,26 +246,34 @@ public class CallLogListItemHelperTest extends AndroidTestCase { /** Sets the details of a phone call using the specified phone number. */ private void setPhoneCallDetailsWithNumber(String number, int presentation, String formattedNumber) { - setPhoneCallDetailsWithNumberAndType(number, presentation, + setPhoneCallDetailsWithNumberTypeAndPostDialDigits(number, "", presentation, formattedNumber, Calls.INCOMING_TYPE); } /** Sets the details of a phone call using the specified phone number. */ private void setPhoneCallDetailsWithNumberAndType(String number, int presentation, String formattedNumber, int callType) { + setPhoneCallDetailsWithNumberTypeAndPostDialDigits(number, "", presentation, + formattedNumber, callType); + } + + /** Sets the details of a phone call using the specified phone number and post-dial digits. */ + private void setPhoneCallDetailsWithNumberTypeAndPostDialDigits(String number, + String postDialDigits, int presentation, String formattedNumber, int callType) { PhoneCallDetails details = getPhoneCallDetails( - number, presentation, formattedNumber); + number, postDialDigits, presentation, formattedNumber); details.callTypes = new int[] {callType}; mHelper.setPhoneCallDetails(mViewHolder, details); } private PhoneCallDetails getPhoneCallDetails( - String number, int presentation, String formattedNumber) { + String number, String postDialDigits, int presentation, String formattedNumber) { PhoneCallDetails details = new PhoneCallDetails( mContext, number, presentation, formattedNumber, + postDialDigits, false /* isVoicemail */); setDefaultDetails(details); return details; @@ -278,6 +286,7 @@ public class CallLogListItemHelperTest extends AndroidTestCase { TEST_NUMBER, Calls.PRESENTATION_ALLOWED, TEST_FORMATTED_NUMBER, + "", false /* isVoicemail */); setDefaultDetails(details); details.callTypes = types; diff --git a/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java b/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java index 5b4629318..1e4a00000 100644 --- a/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java +++ b/tests/src/com/android/dialer/calllog/CallLogQueryTestUtils.java @@ -20,17 +20,24 @@ import static junit.framework.Assert.assertEquals; import android.provider.CallLog.Calls; -import junit.framework.Assert; - /** * Helper class to create test values for {@link CallLogQuery}. */ public class CallLogQueryTestUtils { public static Object[] createTestValues() { - Object[] values = new Object[]{ - 0L, "", 0L, 0L, Calls.INCOMING_TYPE, "", "", "", null, 0, null, null, null, null, - 0L, null, 0, Calls.PRESENTATION_ALLOWED, null, null, 0, null, null, null - }; + Object[] values; + if (PhoneNumberDisplayUtil.canShowPostDial()) { + values = new Object[]{ + 0L, "", 0L, 0L, Calls.INCOMING_TYPE, "", "", "", null, 0, null, null, null, + null, 0L, null, 0, Calls.PRESENTATION_ALLOWED, null, null, 0, null, null, + null, "" + }; + } else { + values = new Object[]{ + 0L, "", 0L, 0L, Calls.INCOMING_TYPE, "", "", "", null, 0, null, null, null, + null, 0L, null, 0, Calls.PRESENTATION_ALLOWED, null, null, 0, null, null, null + }; + } assertEquals(CallLogQuery._PROJECTION.length, values.length); return values; } diff --git a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java index c30861c8e..23ee7b311 100644 --- a/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java +++ b/tests/src/com/android/dialer/calllog/PhoneCallDetailsHelperTest.java @@ -58,6 +58,8 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { private static final String TEST_GEOCODE = "United States"; /** Empty geocode label */ private static final String EMPTY_GEOCODE = ""; + /** Empty post-dial digits label */ + private static final String EMPTY_POSTDIAL = ""; /** The object under test. */ private PhoneCallDetailsHelper mHelper; @@ -428,6 +430,7 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { TEST_NUMBER, Calls.PRESENTATION_ALLOWED, TEST_FORMATTED_NUMBER, + EMPTY_POSTDIAL, false /* isVoicemail */); setDefaultDetails(details); return details; @@ -440,6 +443,7 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase { number, presentation, formattedNumber, + EMPTY_POSTDIAL, isVoicemail(number)); setDefaultDetails(details); return details; |