Replace country code with 0 for Korean carriers.

Korean carriers don't want the country codes displayed for local calls.
However the network returns the entire phone number including the
country code for Volte calls. According to the Koean phone numbering
scheme (https://en.wikipedia.org/wiki/Telephone_numbers_in_South_Korea),
we need to replace the country code +82 with a 0 prepended to the carrier
code to format it as a national number.

BUG: 22862845

Change-Id: I4f09af9869c78db82fbdfdfdf7c121dfb2fd44f4
diff --git a/src/com/android/contacts/common/util/PhoneNumberHelper.java b/src/com/android/contacts/common/util/PhoneNumberHelper.java
index 9d67668..11f2153 100644
--- a/src/com/android/contacts/common/util/PhoneNumberHelper.java
+++ b/src/com/android/contacts/common/util/PhoneNumberHelper.java
@@ -36,6 +36,7 @@
 
     private static final String LOG_TAG = PhoneNumberHelper.class.getSimpleName();
 
+    private static final String KOREA_ISO_COUNTRY_CODE = "KR";
     /**
      * Determines if the specified number is actually a URI (i.e. a SIP address) rather than a
      * regular PSTN phone number, based on whether or not the number contains an "@" character.
@@ -124,7 +125,14 @@
         String result = null;
         try {
             PhoneNumber pn = util.parseAndKeepRawInput(phoneNumber, defaultCountryIso);
-            result = util.formatInOriginalFormat(pn, defaultCountryIso);
+            if (KOREA_ISO_COUNTRY_CODE.equals(defaultCountryIso) &&
+                    (pn.getCountryCode() == util.getCountryCodeForRegion(KOREA_ISO_COUNTRY_CODE))) {
+                // Format local Korean phone numbers with country code to corresponding national
+                // format which would replace the leading +82 with 0.
+                result = util.format(pn, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
+            } else {
+                result = util.formatInOriginalFormat(pn, defaultCountryIso);
+            }
         } catch (NumberParseException e) {
             Log.w(LOG_TAG, "Number could not be parsed with the given country code!");
         }