diff options
author | Yorke Lee <yorkelee@google.com> | 2015-08-26 19:08:30 -0700 |
---|---|---|
committer | Yorke Lee <yorkelee@google.com> | 2015-08-31 11:19:09 -0700 |
commit | 7de107bff21b046c50a42bebf57eb244772412e9 (patch) | |
tree | 6c6c65a2b384337abe52971cf68e5a0bca1f92cc | |
parent | 16b68491261362737752e6babc95f89e2b468f49 (diff) |
Don't strip post dial string when handling DIAL intent
Also add tests and update test APK manifest to allow it to be
installed.
Bug: 22007312
Change-Id: Ibc71d9efd8666c38b0d879a27dae3f5642ce383c
-rw-r--r-- | src/com/android/dialer/dialpad/DialpadFragment.java | 41 | ||||
-rw-r--r-- | tests/AndroidManifest.xml | 4 | ||||
-rw-r--r-- | tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java | 26 |
3 files changed, 65 insertions, 6 deletions
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index 3792a1d9f..01dc892e5 100644 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -560,19 +560,48 @@ public class DialpadFragment extends Fragment * Sets formatted digits to digits field. */ private void setFormattedDigits(String data, String normalizedNumber) { - // strip the non-dialable numbers out of the data string. - String dialString = PhoneNumberUtils.extractNetworkPortion(data); - dialString = - PhoneNumberUtils.formatNumber(dialString, normalizedNumber, mCurrentCountryIso); - if (!TextUtils.isEmpty(dialString)) { + final String formatted = getFormattedDigits(data, normalizedNumber, mCurrentCountryIso); + if (!TextUtils.isEmpty(formatted)) { Editable digits = mDigits.getText(); - digits.replace(0, digits.length(), dialString); + digits.replace(0, digits.length(), formatted); // for some reason this isn't getting called in the digits.replace call above.. // but in any case, this will make sure the background drawable looks right afterTextChanged(digits); } } + /** + * Format the provided string of digits into one that represents a properly formatted phone + * number. + * + * @param dialString String of characters to format + * @param normalizedNumber the E164 format number whose country code is used if the given + * phoneNumber doesn't have the country code. + * @param countryIso The country code representing the format to use if the provided normalized + * number is null or invalid. + * @return the provided string of digits as a formatted phone number, retaining any + * post-dial portion of the string. + */ + @VisibleForTesting + static String getFormattedDigits(String dialString, String normalizedNumber, String countryIso) { + String number = PhoneNumberUtils.extractNetworkPortion(dialString); + // Also retrieve the post dial portion of the provided data, so that the entire dial + // string can be reconstituted later. + final String postDial = PhoneNumberUtils.extractPostDialPortion(dialString); + + if (TextUtils.isEmpty(number)) { + return postDial; + } + + number = PhoneNumberUtils.formatNumber(number, normalizedNumber, countryIso); + + if (TextUtils.isEmpty(postDial)) { + return number; + } + + return number.concat(postDial); + } + private void configureKeypadListeners(View fragmentView) { final int[] buttonIds = new int[] {R.id.one, R.id.two, R.id.three, R.id.four, R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine, R.id.star, R.id.zero, R.id.pound}; diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml index 73febff64..40c5502da 100644 --- a/tests/AndroidManifest.xml +++ b/tests/AndroidManifest.xml @@ -18,6 +18,10 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.dialer.tests"> + <uses-sdk + android:minSdkVersion="23" + android:targetSdkVersion="23" /> + <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.WRITE_CONTACTS" /> <uses-permission android:name="android.permission.READ_CALL_LOG" /> diff --git a/tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java b/tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java index 6f18fe69a..3015e87ff 100644 --- a/tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java +++ b/tests/src/com/android/dialer/dialpad/DialpadFragmentTest.java @@ -82,4 +82,30 @@ public class DialpadFragmentTest extends TestCase { assertTrue(DialpadFragment.canAddDigit("55;55", 3, 3, ',')); // WAIT & PAUSE assertTrue(DialpadFragment.canAddDigit("55,55", 3, 4, ';')); } + + public void testGetFormattedDigits_NoPostDialString() { + assertEquals("(510) 333-7596", + DialpadFragment.getFormattedDigits("5103337596", null, "US")); + assertEquals("(510) 333-7596", + DialpadFragment.getFormattedDigits("5103337596", "+15103337596", "US")); + } + + public void testGetFormattedDigits_WithPostDialString() { + assertEquals("(510) 333-7596,1234", + DialpadFragment.getFormattedDigits("5103337596,1234", null, "US")); + assertEquals("(510) 333-7596;;1234", + DialpadFragment.getFormattedDigits("5103337596;;1234", null, "US")); + assertEquals("(510) 333-7596;123,,4", + DialpadFragment.getFormattedDigits("(510)3337596;123,,4", "+15103337596", "US")); + } + + public void testGetFormattedDigits_PostDialStringOnly() { + assertEquals(",1234567", DialpadFragment.getFormattedDigits(",1234567", null, "US")); + assertEquals(";4321", DialpadFragment.getFormattedDigits(";4321", null, "US")); + } + + public void testGetFormattedDigits_Invalid() { + assertEquals(null, DialpadFragment.getFormattedDigits(null, null, "US")); + assertEquals("", DialpadFragment.getFormattedDigits("", "+15104233335", "US")); + } } |