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

Commit 3e3f77dd authored by Deepak Kundra's avatar Deepak Kundra
Browse files

Support for new properties to identify country based ecc #s added by RIL

If the device is in a country where the ecclist list has been
updated with the current country's ECC#s. For example if device
is in INDIA and we are checking for (XYZ, am, 101, XYZ) it will
return true since 101 will be found in ecclist but 101 is not
valid ECC# for Armenia(am). There could be a case where this
logic errors. For example 101 is valid ECC for INDIA and PAK
and we are currently in INDIA and CTS passes (XYZ, pk, 101,
XYZ). We should return true/valid ECC# but current logic will
return false. This scenario fails even today, so there is no
regression.

Issue-id:CYNGNOS-2412

Change-Id: I6e19aed8a84bd57244a40e7f1e06d4625d26ec77
parent 76e688ba
Loading
Loading
Loading
Loading
+55 −2
Original line number Diff line number Diff line
@@ -1935,11 +1935,13 @@ public class PhoneNumberUtils
                // It is not possible to append additional digits to an emergency number to dial
                // the number in Brazil - it won't connect.
                if (useExactMatch || "BR".equalsIgnoreCase(defaultCountryIso)) {
                    if (number.equals(emergencyNum)) {
                    if (number.equals(emergencyNum) &&
                        isEmergencyNumberForCurrentIso(number, defaultCountryIso, slotId))  {
                        return true;
                    }
                } else {
                    if (number.startsWith(emergencyNum)) {
                    if (number.startsWith(emergencyNum) &&
                        isEmergencyNumberForCurrentIso(number, defaultCountryIso, slotId))  {
                        return true;
                    }
                }
@@ -1981,6 +1983,57 @@ public class PhoneNumberUtils
        return false;
    }

    /**
     * When checking for ECC numbers the country (defaultCountryIso) passed in is not taken into
     * consideration by the function isEmergencyNumberInternal(subId, number, defaultCountryIso,
     * useExactMatchecclist) this causes the function to return TRUE even in the case when the
     * number is not emergency for defaultCountryIso.
     */
     private static boolean isEmergencyNumberForCurrentIso(String number,
                                                     String country,
                                                     int slotId) {
         Rlog.w(LOG_TAG, "isEmergencyNumberForCurrentIso: number =" + number + " iso=" + country);

         String mccEccIso = "";
         String mccEccIsoProp = (slotId == 0) ? "ril.mcc.ecc.iso" : ("ril.mcc.ecc.iso" + slotId);
         mccEccIso = SystemProperties.get(mccEccIsoProp, "");

         if (TextUtils.isEmpty(mccEccIso) || TextUtils.isEmpty(country) || slotId < 0 ||
             isEmergencyIsoMatchCountryIso(mccEccIso, country)) {
             Rlog.w(LOG_TAG, "MCC/ISO is empty or matches region for ECC#'s set via RIL db");
             return true;
         }

         String mccEccList = "";
         String mccEccListProp = (slotId == 0) ? "ril.mcc.ecclist" : ("ril.mcc.ecclist" + slotId);
         mccEccList = SystemProperties.get(mccEccListProp, "");

         if (!TextUtils.isEmpty(mccEccList)) {
             for (String emergencyNum : mccEccList.split(",")) {
                 if (number.equals(emergencyNum)) {
                     Rlog.w(LOG_TAG, "Number " + number + " matches with  " + mccEccListProp);
                     return false;
                 }
             }
         }

         return true;
     }

     /**
      * Checks if the two strings passed are equal ignoring the case
      */
      private static boolean isEmergencyIsoMatchCountryIso(String iso, String country) {
         Rlog.w(LOG_TAG, "isEmergencyIsoMatchCountryIso: iso=" + iso + " country=" + country);

         if(iso.equalsIgnoreCase(country)) {
             return true;
         } else {
             return false;
         }

      }

    /**
     * Checks if a given number is an emergency number for the country that the user is in.
     *