Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ad079e31 authored by Steve Statia's avatar Steve Statia Committed by Android (Google) Code Review
Browse files

Merge "Add Taiwan country code to be formatted for local calls to remove the...

Merge "Add Taiwan country code to be formatted for local calls to remove the international prefix." into main
parents 6b4ba15d 43bc7843
Loading
Loading
Loading
Loading
+52 −31
Original line number Original line Diff line number Diff line
@@ -49,6 +49,7 @@ import com.android.telephony.Rlog;


import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.Locale;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.Pattern;
@@ -1285,6 +1286,13 @@ public class PhoneNumberUtils {


    private static final String SINGAPORE_ISO_COUNTRY_CODE = "SG";
    private static final String SINGAPORE_ISO_COUNTRY_CODE = "SG";


    private static final String[] COUNTRY_CODES_TO_FORMAT_NATIONALLY = new String[] {
            "KR", // Korea
            "JP", // Japan
            "SG", // Singapore
            "TW", // Taiwan
    };

    /**
    /**
     * Breaks the given number down and formats it according to the rules
     * Breaks the given number down and formats it according to the rules
     * for the country the number is from.
     * for the country the number is from.
@@ -1647,36 +1655,47 @@ public class PhoneNumberUtils {
            defaultCountryIso = defaultCountryIso.toUpperCase(Locale.ROOT);
            defaultCountryIso = defaultCountryIso.toUpperCase(Locale.ROOT);
        }
        }


        Rlog.v(LOG_TAG, "formatNumber: defaultCountryIso: " + defaultCountryIso);

        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
        String result = null;
        String result = null;
        try {
        try {
            PhoneNumber pn = util.parseAndKeepRawInput(phoneNumber, defaultCountryIso);
            PhoneNumber pn = util.parseAndKeepRawInput(phoneNumber, defaultCountryIso);


            if (KOREA_ISO_COUNTRY_CODE.equalsIgnoreCase(defaultCountryIso) &&
            if (Flags.nationalCountryCodeFormattingForLocalCalls()) {
                    (pn.getCountryCode() == util.getCountryCodeForRegion(KOREA_ISO_COUNTRY_CODE)) &&
                if (Arrays.asList(COUNTRY_CODES_TO_FORMAT_NATIONALLY).contains(defaultCountryIso)
                    (pn.getCountryCodeSource() ==
                        && pn.getCountryCode() == util.getCountryCodeForRegion(defaultCountryIso)
                            PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN)) {
                        && pn.getCountryCodeSource()
                        == PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN) {
                    return util.format(pn, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
                } else {
                    return util.formatInOriginalFormat(pn, defaultCountryIso);
                }
            } else {
                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
                     * Need to reformat any local Korean phone numbers (when the user is in
                 * country code to corresponding national format which would replace the leading
                     * Korea) with country code to corresponding national format which would
                 * +82 with 0.
                     * replace the leading +82 with 0.
                     */
                     */
                    result = util.format(pn, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
                    result = util.format(pn, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
            } else if (JAPAN_ISO_COUNTRY_CODE.equalsIgnoreCase(defaultCountryIso) &&
                } else if (JAPAN_ISO_COUNTRY_CODE.equalsIgnoreCase(defaultCountryIso)
                    pn.getCountryCode() == util.getCountryCodeForRegion(JAPAN_ISO_COUNTRY_CODE) &&
                        && pn.getCountryCode() == util.getCountryCodeForRegion(
                    (pn.getCountryCodeSource() ==
                        JAPAN_ISO_COUNTRY_CODE) && (pn.getCountryCodeSource()
                            PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN)) {
                        == PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN)) {
                    /**
                    /**
                 * Need to reformat Japanese phone numbers (when user is in Japan) with the national
                     * Need to reformat Japanese phone numbers (when user is in Japan) with the
                 * dialing format.
                     * national dialing format.
                     */
                     */
                    result = util.format(pn, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
                    result = util.format(pn, PhoneNumberUtil.PhoneNumberFormat.NATIONAL);
            } else if (Flags.removeCountryCodeFromLocalSingaporeCalls() &&
                } else if (Flags.removeCountryCodeFromLocalSingaporeCalls() && (
                    (SINGAPORE_ISO_COUNTRY_CODE.equalsIgnoreCase(defaultCountryIso) &&
                        SINGAPORE_ISO_COUNTRY_CODE.equalsIgnoreCase(defaultCountryIso)
                            pn.getCountryCode() ==
                                && pn.getCountryCode() == util.getCountryCodeForRegion(
                                    util.getCountryCodeForRegion(SINGAPORE_ISO_COUNTRY_CODE) &&
                                SINGAPORE_ISO_COUNTRY_CODE) && (pn.getCountryCodeSource()
                            (pn.getCountryCodeSource() ==
                                == PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN))) {
                                    PhoneNumber.CountryCodeSource.FROM_NUMBER_WITH_PLUS_SIGN))) {
                    /*
                    /*
                     * Need to reformat Singaporean phone numbers (when the user is in Singapore)
                     * Need to reformat Singaporean phone numbers (when the user is in Singapore)
                     * with the country code (+65) removed to comply with Singaporean regulations.
                     * with the country code (+65) removed to comply with Singaporean regulations.
@@ -1685,7 +1704,9 @@ public class PhoneNumberUtils {
                } else {
                } else {
                    result = util.formatInOriginalFormat(pn, defaultCountryIso);
                    result = util.formatInOriginalFormat(pn, defaultCountryIso);
                }
                }
            }
        } catch (NumberParseException e) {
        } catch (NumberParseException e) {
            if (DBG) log("formatNumber: NumberParseException caught " + e);
        }
        }
        return result;
        return result;
    }
    }