MNCs not in carrier_list can get the wrong MNC value am: a0adafc6f1
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/providers/TelephonyProvider/+/14663267
Change-Id: I8046e39cafdb3817633b57b5f05af9670c409e57
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 84536ba..6ac78e0 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -282,6 +282,40 @@
private boolean mManagedApnEnforced;
/**
+ * Mobile country codes where there is a high likelyhood that the MNC has 3 digits
+ * and need one more prefix zero to set correct mobile network code value.
+ *
+ * Please note! The best solution is to add the MCCMNC combo to carrier id
+ * carrier_list, this is just a best effort.
+ */
+ private static final String[] COUNTRY_MCC_WITH_THREE_DIGIT_MNC = {
+ "302" // Canada
+ ,"310" // Guam, USA
+ ,"311" // USA
+ ,"312" // USA
+ ,"313" // USA
+ ,"316" // USA
+ ,"334" // Mexico
+ ,"338" // Bermuda, Jamaica
+ ,"342" // Barbados
+ ,"344" // Antigua and Barbuda
+ ,"346" // Cayman Islands
+ ,"348" // British Virgin Islands
+ ,"356" // Saint Kitts and Nevis
+ ,"358" // Saint Lucia
+ ,"360" // Saint Vincent and the Grenadines
+ ,"365" // Anguilla
+ ,"366" // Dominica
+ ,"376" // Turks and Caicos Islands
+ ,"405" // India
+ ,"708" // Honduras
+ ,"722" // Argentina
+ ,"732" // Colombia
+ ,"738" // Guyana
+ ,"750" // Falkland Islands
+ };
+
+ /**
* Available radio technologies for GSM, UMTS and CDMA.
* Duplicates the constants from hardware/radio/include/ril.h
* This should only be used by agents working with the ril. Others
@@ -4889,18 +4923,32 @@
}
String twoDigitMnc = String.format(Locale.getDefault(), "%02d", mnc);
String threeDigitMnc = "0" + twoDigitMnc;
+ boolean threeDigitNetworkCode =
+ Arrays.asList(COUNTRY_MCC_WITH_THREE_DIGIT_MNC).contains(mcc);
+ int twoDigitResult = countMccMncInCarrierList(context, mcc + twoDigitMnc);
+ int threeDigitResult = countMccMncInCarrierList(context, mcc + threeDigitMnc);
- try (
- Cursor twoDigitMncCursor = context.getContentResolver().query(
- Telephony.CarrierId.All.CONTENT_URI,
- /* projection */ null,
- /* selection */ Telephony.CarrierId.All.MCCMNC + "=?",
- /* selectionArgs */ new String[]{mcc + twoDigitMnc}, null)
- ) {
- if (twoDigitMncCursor.getCount() > 0) {
- return twoDigitMnc;
- }
+ if ((threeDigitResult > twoDigitResult) ||
+ (threeDigitNetworkCode && (twoDigitResult == threeDigitResult))) {
return threeDigitMnc;
+ } else {
+ return twoDigitMnc;
+ }
+ }
+
+ /**
+ * Check carrier_list how many mcc mnc combo matches there are
+ */
+ private static int countMccMncInCarrierList(Context ctx, String mccMncCombo) {
+ try (
+ Cursor mccMncCursor = ctx.getContentResolver().query(
+ Telephony.CarrierId.All.CONTENT_URI,
+ /* projection */ null,
+ /* selection */ Telephony.CarrierId.All.MCCMNC + "=?",
+ /* selectionArgs */ new String[]{mccMncCombo}, null);
+ )
+ {
+ return mccMncCursor.getCount();
}
}