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

Commit 10d24568 authored by Ladios Jonquil's avatar Ladios Jonquil
Browse files

telephony: MccTable: Updates for worldwide needs

* Spare 2 bits from country code to language code
  7 bits for each character of country code would be enough.
  LANG_STRINGS[]'s max index is now increased to 63 (from 15).
  FYI, there are at least 3 dozens of languages in frameworks.

* Lookup country's primary time zone from xml
  There are hundreds of time zones. Import all of them into
  MccTable wouldn't be a good idea. Now it gets the time zone
  ID from com.android.internal.R.xml.time_zones_by_country for
  MCCs without time zone assigned. As I see, the first entry
  matched in the xml would be the primary time zone for the
  specified country. We only need to assign time zones for
  countries that have more than one MCC and its time zone.

* Add a script to update MccTable.java automatically
  By executing tools/genmcctable, any changes to mcc_table in
  Python code will be updated to the auto generated section of
  Java code.

* Minor Changes
 - Fix indent of Java comment generated by Python
 - Set Chinese as the default language of Taiwan

Change-Id: I8724d9e8d5b733a91d5ec9f42ff33b17c9d23eb0
parent afffa0f2
Loading
Loading
Loading
Loading
+46 −0
Original line number Original line Diff line number Diff line
@@ -111,6 +111,52 @@ public class TimeUtils {
        return best;
        return best;
    }
    }


    /**
     * Returns the ID of the specified country's primary time zone.
     * Returns null if no suitable zone could be found.
     * @hide
     */
    public static String getPrimaryTimeZoneID(String country) {
        if (country == null) {
            return null;
        }

        String id = null;

        Resources r = Resources.getSystem();
        XmlResourceParser parser = r.getXml(com.android.internal.R.xml.time_zones_by_country);

        try {
            XmlUtils.beginDocument(parser, "timezones");

            while (true) {
                XmlUtils.nextElement(parser);

                String element = parser.getName();
                if (element == null || !(element.equals("timezone"))) {
                    break;
                }

                String code = parser.getAttributeValue(null, "code");

                if (country.equals(code)) {
                    if (parser.next() == XmlPullParser.TEXT) {
                        id = parser.getText();
                        break;
                    }
                }
            }
        } catch (XmlPullParserException e) {
            Log.e(TAG, "Got exception while getting preferred time zone.", e);
        } catch (IOException e) {
            Log.e(TAG, "Got exception while getting preferred time zone.", e);
        } finally {
            parser.close();
        }

        return id;
    }

    /**
    /**
     * Returns a String indicating the version of the time zone database currently
     * Returns a String indicating the version of the time zone database currently
     * in use.  The format of the string is dependent on the underlying time zone
     * in use.  The format of the string is dependent on the underlying time zone
+87 −103
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.SystemProperties;
import android.provider.Settings;
import android.provider.Settings;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
import android.util.TimeUtils;


import java.util.Arrays;
import java.util.Arrays;


@@ -45,7 +46,8 @@ import java.util.Arrays;
 * only unresolved discrepancy being that this list has an extra entry
 * only unresolved discrepancy being that this list has an extra entry
 * (461) for China.
 * (461) for China.
 *
 *
 * TODO: Complete the mappings for timezones and language/locale codes.
 * TODO: Complete the mappings for language/locale codes, and
 *       timezones which are not the countries' primary ones.
 *
 *
 * The actual table data used in the Java code is generated from the
 * The actual table data used in the Java code is generated from the
 * below Python code for efficiency.  The information is expected to
 * below Python code for efficiency.  The information is expected to
@@ -55,25 +57,25 @@ import java.util.Arrays;


mcc_table = [
mcc_table = [
  (202, 'gr', 2, 'Greece'),
  (202, 'gr', 2, 'Greece'),
  (204, 'nl', 2, 'Europe/Amsterdam', 'nl', 13, 'Netherlands (Kingdom of the)'),
  (204, 'nl', 2, '', 'nl', 13, 'Netherlands (Kingdom of the)'),
  (206, 'be', 2, 'Belgium'),
  (206, 'be', 2, 'Belgium'),
  (208, 'fr', 2, 'Europe/Paris', 'fr', 'France'),
  (208, 'fr', 2, '', 'fr', 'France'),
  (212, 'mc', 2, 'Monaco (Principality of)'),
  (212, 'mc', 2, 'Monaco (Principality of)'),
  (213, 'ad', 2, 'Andorra (Principality of)'),
  (213, 'ad', 2, 'Andorra (Principality of)'),
  (214, 'es', 2, 'Europe/Madrid', 'es', 'Spain'),
  (214, 'es', 2, '', 'es', 'Spain'),
  (216, 'hu', 2, 'Hungary (Republic of)'),
  (216, 'hu', 2, 'Hungary (Republic of)'),
  (218, 'ba', 2, 'Bosnia and Herzegovina'),
  (218, 'ba', 2, 'Bosnia and Herzegovina'),
  (219, 'hr', 2, 'Croatia (Republic of)'),
  (219, 'hr', 2, 'Croatia (Republic of)'),
  (220, 'rs', 2, 'Serbia and Montenegro'),
  (220, 'rs', 2, 'Serbia and Montenegro'),
  (222, 'it', 2, 'Europe/Rome', 'it', 'Italy'),
  (222, 'it', 2, '', 'it', 'Italy'),
  (225, 'va', 2, 'Europe/Rome', 'it', 'Vatican City State'),
  (225, 'va', 2, '', 'it', 'Vatican City State'),
  (226, 'ro', 2, 'Romania'),
  (226, 'ro', 2, 'Romania'),
  (228, 'ch', 2, 'Europe/Zurich', 'de', 'Switzerland (Confederation of)'),
  (228, 'ch', 2, '', 'de', 'Switzerland (Confederation of)'),
  (230, 'cz', 2, 'Europe/Prague', 'cs', 13, 'Czech Republic'),
  (230, 'cz', 2, '', 'cs', 13, 'Czech Republic'),
  (231, 'sk', 2, 'Slovak Republic'),
  (231, 'sk', 2, 'Slovak Republic'),
  (232, 'at', 2, 'Europe/Vienna', 'de', 13, 'Austria'),
  (232, 'at', 2, '', 'de', 13, 'Austria'),
  (234, 'gb', 2, 'Europe/London', 'en', 13, 'United Kingdom of Great Britain and Northern Ireland'),
  (234, 'gb', 2, '', 'en', 13, 'United Kingdom of Great Britain and Northern Ireland'),
  (235, 'gb', 2, 'Europe/London', 'en', 13, 'United Kingdom of Great Britain and Northern Ireland'),
  (235, 'gb', 2, '', 'en', 13, 'United Kingdom of Great Britain and Northern Ireland'),
  (238, 'dk', 2, 'Denmark'),
  (238, 'dk', 2, 'Denmark'),
  (240, 'se', 2, 'Sweden'),
  (240, 'se', 2, 'Sweden'),
  (242, 'no', 2, 'Norway'),
  (242, 'no', 2, 'Norway'),
@@ -85,12 +87,12 @@ mcc_table = [
  (255, 'ua', 2, 'Ukraine'),
  (255, 'ua', 2, 'Ukraine'),
  (257, 'by', 2, 'Belarus (Republic of)'),
  (257, 'by', 2, 'Belarus (Republic of)'),
  (259, 'md', 2, 'Moldova (Republic of)'),
  (259, 'md', 2, 'Moldova (Republic of)'),
  (260, 'pl', 2, 'Europe/Warsaw', 'Poland (Republic of)'),
  (260, 'pl', 2, 'Poland (Republic of)'),
  (262, 'de', 2, 'Europe/Berlin', 'de', 13, 'Germany (Federal Republic of)'),
  (262, 'de', 2, '', 'de', 13, 'Germany (Federal Republic of)'),
  (266, 'gi', 2, 'Gibraltar'),
  (266, 'gi', 2, 'Gibraltar'),
  (268, 'pt', 2, 'Portugal'),
  (268, 'pt', 2, 'Portugal'),
  (270, 'lu', 2, 'Luxembourg'),
  (270, 'lu', 2, 'Luxembourg'),
  (272, 'ie', 2, 'Europe/Dublin', 'en', 'Ireland'),
  (272, 'ie', 2, '', 'en', 'Ireland'),
  (274, 'is', 2, 'Iceland'),
  (274, 'is', 2, 'Iceland'),
  (276, 'al', 2, 'Albania (Republic of)'),
  (276, 'al', 2, 'Albania (Republic of)'),
  (278, 'mt', 2, 'Malta'),
  (278, 'mt', 2, 'Malta'),
@@ -172,29 +174,29 @@ mcc_table = [
  (436, 'tj', 2, 'Tajikistan (Republic of)'),
  (436, 'tj', 2, 'Tajikistan (Republic of)'),
  (437, 'kg', 2, 'Kyrgyz Republic'),
  (437, 'kg', 2, 'Kyrgyz Republic'),
  (438, 'tm', 2, 'Turkmenistan'),
  (438, 'tm', 2, 'Turkmenistan'),
  (440, 'jp', 2, 'Asia/Tokyo', 'ja', 14, 'Japan'),
  (440, 'jp', 2, '', 'ja', 14, 'Japan'),
  (441, 'jp', 2, 'Asia/Tokyo', 'ja', 14, 'Japan'),
  (441, 'jp', 2, '', 'ja', 14, 'Japan'),
  (450, 'kr', 2, 'Asia/Seoul', 'ko', 13, 'Korea (Republic of)'),
  (450, 'kr', 2, '', 'ko', 13, 'Korea (Republic of)'),
  (452, 'vn', 2, 'Viet Nam (Socialist Republic of)'),
  (452, 'vn', 2, 'Viet Nam (Socialist Republic of)'),
  (454, 'hk', 2, '"Hong Kong, China"'),
  (454, 'hk', 2, '"Hong Kong, China"'),
  (455, 'mo', 2, '"Macao, China"'),
  (455, 'mo', 2, '"Macao, China"'),
  (456, 'kh', 2, 'Cambodia (Kingdom of)'),
  (456, 'kh', 2, 'Cambodia (Kingdom of)'),
  (457, 'la', 2, "Lao People's Democratic Republic"),
  (457, 'la', 2, "Lao People's Democratic Republic"),
  (460, 'cn', 2, "Asia/Beijing", 'zh', 13, "China (People's Republic of)"),
  (460, 'cn', 2, '', 'zh', 13, "China (People's Republic of)"),
  (461, 'cn', 2, "Asia/Beijing", 'zh', 13, "China (People's Republic of)"),
  (461, 'cn', 2, '', 'zh', 13, "China (People's Republic of)"),
  (466, 'tw', 2, "Taiwan (Republic of China)"),
  (466, 'tw', 2, '', 'zh', "Taiwan (Republic of China)"),
  (467, 'kp', 2, "Democratic People's Republic of Korea"),
  (467, 'kp', 2, "Democratic People's Republic of Korea"),
  (470, 'bd', 2, "Bangladesh (People's Republic of)"),
  (470, 'bd', 2, "Bangladesh (People's Republic of)"),
  (472, 'mv', 2, 'Maldives (Republic of)'),
  (472, 'mv', 2, 'Maldives (Republic of)'),
  (502, 'my', 2, 'Malaysia'),
  (502, 'my', 2, 'Malaysia'),
  (505, 'au', 2, 'Australia/Sydney', 'en', 11, 'Australia'),
  (505, 'au', 2, '', 'en', 11, 'Australia'),
  (510, 'id', 2, 'Indonesia (Republic of)'),
  (510, 'id', 2, 'Indonesia (Republic of)'),
  (514, 'tl', 2, 'Democratic Republic of Timor-Leste'),
  (514, 'tl', 2, 'Democratic Republic of Timor-Leste'),
  (515, 'ph', 2, 'Philippines (Republic of the)'),
  (515, 'ph', 2, 'Philippines (Republic of the)'),
  (520, 'th', 2, 'Thailand'),
  (520, 'th', 2, 'Thailand'),
  (525, 'sg', 2, 'Asia/Singapore', 'en', 11, 'Singapore (Republic of)'),
  (525, 'sg', 2, '', 'en', 11, 'Singapore (Republic of)'),
  (528, 'bn', 2, 'Brunei Darussalam'),
  (528, 'bn', 2, 'Brunei Darussalam'),
  (530, 'nz', 2, 'Pacific/Auckland', 'en', 'New Zealand'),
  (530, 'nz', 2, '', 'en', 'New Zealand'),
  (534, 'mp', 2, 'Northern Mariana Islands (Commonwealth of the)'),
  (534, 'mp', 2, 'Northern Mariana Islands (Commonwealth of the)'),
  (535, 'gu', 2, 'Guam'),
  (535, 'gu', 2, 'Guam'),
  (536, 'nr', 2, 'Nauru (Republic of)'),
  (536, 'nr', 2, 'Nauru (Republic of)'),
@@ -265,7 +267,7 @@ mcc_table = [
  (652, 'bw', 2, 'Botswana (Republic of)'),
  (652, 'bw', 2, 'Botswana (Republic of)'),
  (653, 'sz', 2, 'Swaziland (Kingdom of)'),
  (653, 'sz', 2, 'Swaziland (Kingdom of)'),
  (654, 'km', 2, 'Comoros (Union of the)'),
  (654, 'km', 2, 'Comoros (Union of the)'),
  (655, 'za', 2, 'Africa/Johannesburg', 'en', 'South Africa (Republic of)'),
  (655, 'za', 2, '', 'en', 'South Africa (Republic of)'),
  (657, 'er', 2, 'Eritrea'),
  (657, 'er', 2, 'Eritrea'),
  (702, 'bz', 2, 'Belize'),
  (702, 'bz', 2, 'Belize'),
  (704, 'gt', 2, 'Guatemala (Republic of)'),
  (704, 'gt', 2, 'Guatemala (Republic of)'),
@@ -302,12 +304,12 @@ lang_set = sorted(x for x in set(get_lang(elt) for elt in mcc_table))


def mk_ind_code(elt):
def mk_ind_code(elt):
  iso = get_iso(elt)
  iso = get_iso(elt)
  iso_code = ((ord(iso[0]) << 8) | ord(iso[1])) & 0xFFFF # 16 bits
  iso_code = ((ord(iso[0]) << 7) | ord(iso[1])) & 0x3FFF # 14 bits
  wifi = get_wifi(elt) & 0x000F                          #  4 bits
  wifi = get_wifi(elt) & 0x000F                          #  4 bits
  sd = get_sd(elt) & 0x0003                              #  2 bits
  sd = get_sd(elt) & 0x0003                              #  2 bits
  tz_ind = tz_set.index(get_tz(elt)) & 0x001F            #  5 bits
  tz_ind = tz_set.index(get_tz(elt)) & 0x001F            #  5 bits
  lang_ind = lang_set.index(get_lang(elt)) & 0x000F      #  4 bits
  lang_ind = lang_set.index(get_lang(elt)) & 0x003F      #  6 bits
  return (iso_code << 16) | (wifi << 11) | (sd << 9) | (tz_ind << 4) | lang_ind
  return (iso_code << 18) | (wifi << 13) | (sd << 11) | (tz_ind << 6) | lang_ind


ind_codes = ['0x%08x' % mk_ind_code(elt) for elt in mcc_table]
ind_codes = ['0x%08x' % mk_ind_code(elt) for elt in mcc_table]


@@ -333,24 +335,24 @@ do_autogen_comment(['This table is a list of MCC codes. The index in this table
                    'that MCC in the IND_CODES table.'])
                    'that MCC in the IND_CODES table.'])
print fmt_list('short[] MCC_CODES', mcc_codes, 10)
print fmt_list('short[] MCC_CODES', mcc_codes, 10)
do_autogen_comment(['The values in this table are broken down as follows (msb to lsb):',
do_autogen_comment(['The values in this table are broken down as follows (msb to lsb):',
                    '    iso country code 16 bits',
                    '    iso country code 14 bits',
                    '    (unused)          1 bit',
                    '    (unused)          1 bit',
                    '    wifi channel      4 bits',
                    '    wifi channel      4 bits',
                    '    smalled digit     2 bits',
                    '    smalled digit     2 bits',
                    '    default timezone  5 bits',
                    '    default timezone  5 bits',
                    '    default language  4 bits'])
                    '    default language  6 bits'])
print fmt_list('int[] IND_CODES', ind_codes, 6)
print fmt_list('int[] IND_CODES', ind_codes, 6)


def parse_ind_code(ind):
def parse_ind_code(ind):
  mcc = eval(mcc_codes[ind])
  mcc = eval(mcc_codes[ind])
  code = eval(ind_codes[ind])
  code = eval(ind_codes[ind])
  iso_lsb = int((code >> 16) & 0x00FF)
  iso_lsb = int((code >> 18) & 0x007F)
  iso_msb = int((code >> 24) & 0x00FF)
  iso_msb = int((code >> 25) & 0x007F)
  iso = '%s%s' % (chr(iso_msb), chr(iso_lsb))
  iso = '%s%s' % (chr(iso_msb), chr(iso_lsb))
  wifi = int((code >> 11) & 0x000F)
  wifi = int((code >> 13) & 0x000F)
  sd = int((code >> 9) & 0x0003)
  sd = int((code >> 11) & 0x0003)
  tz_ind = (code >> 4) & 0x001F
  tz_ind = (code >> 6) & 0x001F
  lang_ind = (code >> 0) & 0x000F
  lang_ind = (code >> 0) & 0x003F
  return (mcc, iso, sd, tz_set[tz_ind], lang_set[lang_ind], wifi)
  return (mcc, iso, sd, tz_set[tz_ind], lang_set[lang_ind], wifi)


fmt_str = 'mcc = %s, iso = %s, sd = %s, tz = %s, lang = %s, wifi = %s'
fmt_str = 'mcc = %s, iso = %s, sd = %s, tz = %s, lang = %s, wifi = %s'
@@ -375,25 +377,7 @@ public final class MccTable
     * AUTO GENERATED (by the Python code above)
     * AUTO GENERATED (by the Python code above)
     */
     */
    private static final String[] TZ_STRINGS = {
    private static final String[] TZ_STRINGS = {
        "",
        ""
        "Africa/Johannesburg",
        "Asia/Beijing",
        "Asia/Seoul",
        "Asia/Singapore",
        "Asia/Tokyo",
        "Australia/Sydney",
        "Europe/Amsterdam",
        "Europe/Berlin",
        "Europe/Dublin",
        "Europe/London",
        "Europe/Madrid",
        "Europe/Paris",
        "Europe/Prague",
        "Europe/Rome",
        "Europe/Vienna",
        "Europe/Warsaw",
        "Europe/Zurich",
        "Pacific/Auckland"
    };
    };


    /**
    /**
@@ -440,53 +424,53 @@ public final class MccTable
    /**
    /**
     * AUTO GENERATED (by the Python code above)
     * AUTO GENERATED (by the Python code above)
     * The values in this table are broken down as follows (msb to lsb):
     * The values in this table are broken down as follows (msb to lsb):
     *     iso country code 16 bits
     *     iso country code 14 bits
     *     (unused)          1 bit
     *     (unused)          1 bit
     *     wifi channel      4 bits
     *     wifi channel      4 bits
     *     smalled digit     2 bits
     *     smalled digit     2 bits
     *     default timezone  5 bits
     *     default timezone  5 bits
     *     default language  4 bits
     *     default language  6 bits
     */
     */
    private static final int[] IND_CODES = {
    private static final int[] IND_CODES = {
        0x67720400, 0x6e6c6c79, 0x62650400, 0x667204c5, 0x6d630400, 0x61640400,
        0xcfc81000, 0xddb1b009, 0xc5941000, 0xcdc81005, 0xdb8c1000, 0xc3901000,
        0x657304b4, 0x68750400, 0x62610400, 0x68720400, 0x72730400, 0x697404e6,
        0xcbcc1004, 0xd1d41000, 0xc5841000, 0xd1c81000, 0xe5cc1000, 0xd3d01006,
        0x766104e6, 0x726f0400, 0x63680512, 0x637a6cd1, 0x736b0400, 0x61746cf2,
        0xed841006, 0xe5bc1000, 0xc7a01002, 0xc7e9b001, 0xe7ac1000, 0xc3d1b002,
        0x67626ca3, 0x67626ca3, 0x646b0400, 0x73650400, 0x6e6f0400, 0x66690400,
        0xcf89b003, 0xcf89b003, 0xc9ac1000, 0xe7941000, 0xddbc1000, 0xcda41000,
        0x6c740400, 0x6c760400, 0x65650400, 0x72750400, 0x75610400, 0x62790400,
        0xd9d01000, 0xd9d81000, 0xcb941000, 0xe5d41000, 0xeb841000, 0xc5e41000,
        0x6d640400, 0x706c0500, 0x64656c82, 0x67690400, 0x70740400, 0x6c750400,
        0xdb901000, 0xe1b01000, 0xc995b002, 0xcfa41000, 0xe1d01000, 0xd9d41000,
        0x69650493, 0x69730400, 0x616c0400, 0x6d740400, 0x63790400, 0x67650400,
        0xd3941003, 0xd3cc1000, 0xc3b01000, 0xdbd01000, 0xc7e41000, 0xcf941000,
        0x616d0400, 0x62670400, 0x74720400, 0x666f0400, 0x67650400, 0x676c0400,
        0xc3b41000, 0xc59c1000, 0xe9c81000, 0xcdbc1000, 0xcf941000, 0xcfb01000,
        0x736d0400, 0x736c0400, 0x6d6b0400, 0x6c690400, 0x6d650400, 0x63615e00,
        0xe7b41000, 0xe7b01000, 0xdbac1000, 0xd9a41000, 0xdb941000, 0xc7857800,
        0x706d0400, 0x75735e03, 0x75735e03, 0x75735e03, 0x75735e03, 0x75735e03,
        0xe1b41000, 0xebcd7803, 0xebcd7803, 0xebcd7803, 0xebcd7803, 0xebcd7803,
        0x75735e03, 0x75735e03, 0x70720400, 0x76690400, 0x6d780600, 0x6a6d0600,
        0xebcd7803, 0xebcd7803, 0xe1c81000, 0xeda41000, 0xdbe01800, 0xd5b41800,
        0x67700400, 0x62620600, 0x61670600, 0x6b790600, 0x76670600, 0x626d0400,
        0xcfc01000, 0xc5881800, 0xc39c1800, 0xd7e41800, 0xed9c1800, 0xc5b41000,
        0x67640400, 0x6d730400, 0x6b6e0400, 0x6c630400, 0x76630400, 0x6e6c0400,
        0xcf901000, 0xdbcc1000, 0xd7b81000, 0xd98c1000, 0xed8c1000, 0xddb01000,
        0x61770400, 0x62730400, 0x61690600, 0x646d0400, 0x63750400, 0x646f0400,
        0xc3dc1000, 0xc5cc1000, 0xc3a41800, 0xc9b41000, 0xc7d41000, 0xc9bc1000,
        0x68740400, 0x74740400, 0x74630400, 0x617a0400, 0x6b7a0400, 0x62740400,
        0xd1d01000, 0xe9d01000, 0xe98c1000, 0xc3e81000, 0xd7e81000, 0xc5d01000,
        0x696e0400, 0x696e0400, 0x706b0400, 0x61660400, 0x6c6b0400, 0x6d6d0400,
        0xd3b81000, 0xd3b81000, 0xe1ac1000, 0xc3981000, 0xd9ac1000, 0xdbb41000,
        0x6c620400, 0x6a6f0400, 0x73790400, 0x69710400, 0x6b770400, 0x73610400,
        0xd9881000, 0xd5bc1000, 0xe7e41000, 0xd3c41000, 0xd7dc1000, 0xe7841000,
        0x79650400, 0x6f6d0400, 0x70730400, 0x61650400, 0x696c0400, 0x62680400,
        0xf3941000, 0xdfb41000, 0xe1cc1000, 0xc3941000, 0xd3b01000, 0xc5a01000,
        0x71610400, 0x6d6e0400, 0x6e700400, 0x61650400, 0x61650400, 0x69720400,
        0xe3841000, 0xdbb81000, 0xddc01000, 0xc3941000, 0xc3941000, 0xd3c81000,
        0x757a0400, 0x746a0400, 0x6b670400, 0x746d0400, 0x6a707457, 0x6a707457,
        0xebe81000, 0xe9a81000, 0xd79c1000, 0xe9b41000, 0xd5c1d007, 0xd5c1d007,
        0x6b726c38, 0x766e0400, 0x686b0400, 0x6d6f0400, 0x6b680400, 0x6c610400,
        0xd7c9b008, 0xedb81000, 0xd1ac1000, 0xdbbc1000, 0xd7a01000, 0xd9841000,
        0x636e6c2a, 0x636e6c2a, 0x74770400, 0x6b700400, 0x62640400, 0x6d760400,
        0xc7b9b00a, 0xc7b9b00a, 0xe9dc100a, 0xd7c01000, 0xc5901000, 0xdbd81000,
        0x6d790400, 0x61755c63, 0x69640400, 0x746c0400, 0x70680400, 0x74680400,
        0xdbe41000, 0xc3d57003, 0xd3901000, 0xe9b01000, 0xe1a01000, 0xe9a01000,
        0x73675c43, 0x626e0400, 0x6e7a0523, 0x6d700400, 0x67750400, 0x6e720400,
        0xe79d7003, 0xc5b81000, 0xdde81003, 0xdbc01000, 0xcfd41000, 0xddc81000,
        0x70670400, 0x746f0400, 0x73620400, 0x76750400, 0x666a0400, 0x77660400,
        0xe19c1000, 0xe9bc1000, 0xe7881000, 0xedd41000, 0xcda81000, 0xef981000,
        0x61730400, 0x6b690400, 0x6e630400, 0x70660400, 0x636b0400, 0x77730400,
        0xc3cc1000, 0xd7a41000, 0xdd8c1000, 0xe1981000, 0xc7ac1000, 0xefcc1000,
        0x666d0400, 0x6d680400, 0x70770400, 0x65670400, 0x647a0400, 0x6d610400,
        0xcdb41000, 0xdba01000, 0xe1dc1000, 0xcb9c1000, 0xc9e81000, 0xdb841000,
        0x746e0400, 0x6c790400, 0x676d0400, 0x736e0400, 0x6d720400, 0x6d6c0400,
        0xe9b81000, 0xd9e41000, 0xcfb41000, 0xe7b81000, 0xdbc81000, 0xdbb01000,
        0x676e0400, 0x63690400, 0x62660400, 0x6e650400, 0x74670400, 0x626a0400,
        0xcfb81000, 0xc7a41000, 0xc5981000, 0xdd941000, 0xe99c1000, 0xc5a81000,
        0x6d750400, 0x6c720400, 0x736c0400, 0x67680400, 0x6e670400, 0x74640400,
        0xdbd41000, 0xd9c81000, 0xe7b01000, 0xcfa01000, 0xdd9c1000, 0xe9901000,
        0x63660400, 0x636d0400, 0x63760400, 0x73740400, 0x67710400, 0x67610400,
        0xc7981000, 0xc7b41000, 0xc7d81000, 0xe7d01000, 0xcfc41000, 0xcf841000,
        0x63670400, 0x63670400, 0x616f0400, 0x67770400, 0x73630400, 0x73640400,
        0xc79c1000, 0xc79c1000, 0xc3bc1000, 0xcfdc1000, 0xe78c1000, 0xe7901000,
        0x72770400, 0x65740400, 0x736f0400, 0x646a0400, 0x6b650400, 0x747a0400,
        0xe5dc1000, 0xcbd01000, 0xe7bc1000, 0xc9a81000, 0xd7941000, 0xe9e81000,
        0x75670400, 0x62690400, 0x6d7a0400, 0x7a6d0400, 0x6d670400, 0x72650400,
        0xeb9c1000, 0xc5a41000, 0xdbe81000, 0xf5b41000, 0xdb9c1000, 0xe5941000,
        0x7a770400, 0x6e610400, 0x6d770400, 0x6c730400, 0x62770400, 0x737a0400,
        0xf5dc1000, 0xdd841000, 0xdbdc1000, 0xd9cc1000, 0xc5dc1000, 0xe7e81000,
        0x6b6d0400, 0x7a610413, 0x65720400, 0x627a0400, 0x67740400, 0x73760400,
        0xd7b41000, 0xf5841003, 0xcbc81000, 0xc5e81000, 0xcfd01000, 0xe7d81000,
        0x686e0600, 0x6e690400, 0x63720400, 0x70610400, 0x70650400, 0x61720600,
        0xd1b81800, 0xdda41000, 0xc7c81000, 0xe1841000, 0xe1941000, 0xc3c81800,
        0x62720400, 0x636c0400, 0x636f0600, 0x76650400, 0x626f0400, 0x67790400,
        0xc5c81000, 0xc7b01000, 0xc7bc1800, 0xed941000, 0xc5bc1000, 0xcfe41000,
        0x65630400, 0x67660400, 0x70790400, 0x73720400, 0x75790400, 0x666b0400
        0xcb8c1000, 0xcf981000, 0xe1e41000, 0xe7c81000, 0xebe41000, 0xcdac1000
    };
    };


    static final String LOG_TAG = "MccTable";
    static final String LOG_TAG = "MccTable";
@@ -504,7 +488,7 @@ public final class MccTable
        int tzInd = (indCode >>> 4) & 0x001F;
        int tzInd = (indCode >>> 4) & 0x001F;
        String tz = TZ_STRINGS[tzInd];
        String tz = TZ_STRINGS[tzInd];
        if (tz == "") {
        if (tz == "") {
            return null;
            return TimeUtils.getPrimaryTimeZoneID(countryCodeForMcc(mcc));
        }
        }
        return tz;
        return tz;
    }
    }
@@ -519,7 +503,7 @@ public final class MccTable
            return "";
            return "";
        }
        }
        int indCode = IND_CODES[index];
        int indCode = IND_CODES[index];
        byte[] iso = {(byte)((indCode >>> 24) & 0x00FF), (byte)((indCode >>> 16) & 0x00FF)};
        byte[] iso = {(byte)((indCode >>> 25) & 0x007F), (byte)((indCode >>> 18) & 0x007F)};
        return new String(iso);
        return new String(iso);
    }
    }


@@ -533,7 +517,7 @@ public final class MccTable
            return null;
            return null;
        }
        }
        int indCode = IND_CODES[index];
        int indCode = IND_CODES[index];
        int langInd = indCode & 0x000F;
        int langInd = indCode & 0x003F;
        String lang = LANG_STRINGS[langInd];
        String lang = LANG_STRINGS[langInd];
        if (lang == "") {
        if (lang == "") {
            return null;
            return null;
@@ -551,7 +535,7 @@ public final class MccTable
            return 2;
            return 2;
        }
        }
        int indCode = IND_CODES[index];
        int indCode = IND_CODES[index];
        int smDig = (indCode >>> 9) & 0x0003;
        int smDig = (indCode >>> 11) & 0x0003;
        return smDig;
        return smDig;
    }
    }


@@ -565,7 +549,7 @@ public final class MccTable
            return 0;
            return 0;
        }
        }
        int indCode = IND_CODES[index];
        int indCode = IND_CODES[index];
        int wifi = (indCode >>> 11) & 0x000F;
        int wifi = (indCode >>> 13) & 0x000F;
        return wifi;
        return wifi;
    }
    }


tools/genmcctable

0 → 100755
+67 −0
Original line number Original line Diff line number Diff line
#!/bin/bash

function gettop()
{
    echo $(dirname $0)/../../..
}

function genmcctable()
{
    local PYTHON=$(which python)
    if [ ! -x "$PYTHON" ]; then
        echo "Python not found"
        return
    fi
    T=$(gettop)
    if [ ! "$T" ]; then
        echo "Couldn't locate the top of the tree.  Try setting TOP."
        return
    fi
    local MCC="$T/frameworks/base/telephony/java/com/android/internal/telephony/MccTable.java"
    if [ ! -f "$MCC" ]; then
        echo "File not found: $MCC"
        return
    fi
    local TMP=$(tempfile)
    if [ -z "$TMP" ] || [ ! -f "$TMP" ]; then
        echo "Couldn't create temporary file"
        return
    fi
    trap "rm -f -- '$TMP'" EXIT
    cat $MCC > $TMP
    echo -n "" > $MCC
    local LINE=
    local PY=
    local IFS=$'\n'
    cat $TMP | while read -r LINE; do
        if echo "$LINE" | grep -P '^\s*mcc_table\s*=\s*\[' > /dev/null; then
            echo "$LINE" >> $MCC
            PY="$LINE"
            while read -r LINE; do
                echo "$LINE" >> $MCC
                if echo "$LINE" | grep -P '^\s*\*+/' > /dev/null; then
                    break
                else
                    PY="$PY
$LINE"
                fi
            done
        elif echo "$LINE" | grep -P '^\s*public\s+final\s+class\s+MccTable' > /dev/null; then
            echo "$LINE" >> $MCC
            echo "{" >> $MCC
            echo "$PY" | "$PYTHON" - >> $MCC
            while read -r LINE; do
                if echo "$LINE" | grep -P '^\s*static\s+final\s+String\s+LOG_TAG\s*=\s*"MccTable"' > /dev/null; then
                    echo "$LINE" >> $MCC
                    break
                fi
            done
        else
            echo "$LINE" >> $MCC
        fi
    done
    rm -f -- "$TMP"
    trap - EXIT
}

genmcctable