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

Commit c907d581 authored by Sankar Gonella's avatar Sankar Gonella Committed by Steve Kondik
Browse files

Ims: Fix the NullPointerException in getCountryIso() function

Added Null check for detector.detectCountry(), if this function call
fails, then CountryIso will be picked up based on the Locale.
CRs-Fixed: 490472

Change-Id: Ia94891629cf6170a821f76a718d4b965ae7ab802
parent f0c330fe
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.location.CountryDetector;
import android.location.Country;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Data;
@@ -566,14 +567,17 @@ public class CallerInfo {
     */
    private static String getCurrentCountryIso(Context context, Locale locale) {
      String countryIso;
      Country country;
      CountryDetector detector = (CountryDetector) context.getSystemService(
          Context.COUNTRY_DETECTOR);
      if (detector != null) {
        countryIso = detector.detectCountry().getCountryIso();
      } else {
      if ((detector != null) && ((country = detector.detectCountry()) != null)) {
              countryIso = country.getCountryIso();
      } else if (locale != null) {
           countryIso = locale.getCountry();
           Rlog.w(TAG, "No CountryDetector; falling back to countryIso based on locale: "
                  + countryIso);
      } else {
           countryIso = "US"; //default value is "US"
      }
      return countryIso;
    }