From 3b8f62b6027200932676fed5246cf3ee2afe863a Mon Sep 17 00:00:00 2001 From: Tyler Gunn Date: Sun, 12 Feb 2017 21:26:13 -0800 Subject: [PATCH] Format Japanese numbers using national format when in Japan. Similar to the like change for Korean phone numbers, ensure that when the user is in Japan, Japanese phone numbers are formatted using the national format rather than the international format. Test: Unit Bug: 27090466 Change-Id: I3487eea9fddbe7ee15c03da3f03d53f9dcea0834 --- .../android/telephony/PhoneNumberUtils.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/telephony/java/android/telephony/PhoneNumberUtils.java b/telephony/java/android/telephony/PhoneNumberUtils.java index 152b8685027ef..38cffae961326 100644 --- a/telephony/java/android/telephony/PhoneNumberUtils.java +++ b/telephony/java/android/telephony/PhoneNumberUtils.java @@ -1139,6 +1139,8 @@ public class PhoneNumberUtils private static final String KOREA_ISO_COUNTRY_CODE = "KR"; + private static final String JAPAN_ISO_COUNTRY_CODE = "JP"; + /** * Breaks the given number down and formats it according to the rules * for the country the number is from. @@ -1459,15 +1461,25 @@ public class PhoneNumberUtils String result = null; try { PhoneNumber pn = util.parseAndKeepRawInput(phoneNumber, defaultCountryIso); - /** - * Need to reformat any local Korean phone numbers (when the user is in Korea) with - * country code to corresponding national format which would replace the leading - * +82 with 0. - */ - if (KOREA_ISO_COUNTRY_CODE.equals(defaultCountryIso) && + + if (KOREA_ISO_COUNTRY_CODE.equalsIgnoreCase(defaultCountryIso) && (pn.getCountryCode() == util.getCountryCodeForRegion(KOREA_ISO_COUNTRY_CODE)) && (pn.getCountryCodeSource() == PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN)) { + /** + * Need to reformat any local Korean phone numbers (when the user is in Korea) with + * country code to corresponding national format which would replace the leading + * +82 with 0. + */ + result = util.format(pn, PhoneNumberUtil.PhoneNumberFormat.NATIONAL); + } else if (JAPAN_ISO_COUNTRY_CODE.equalsIgnoreCase(defaultCountryIso) && + pn.getCountryCode() == util.getCountryCodeForRegion(JAPAN_ISO_COUNTRY_CODE) && + (pn.getCountryCodeSource() == + PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN)) { + /** + * Need to reformat Japanese phone numbers (when user is in Japan) with the national + * dialing format. + */ result = util.format(pn, PhoneNumberUtil.PhoneNumberFormat.NATIONAL); } else { result = util.formatInOriginalFormat(pn, defaultCountryIso);