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

Commit 622b7b6a authored by Ravi Paluri's avatar Ravi Paluri Committed by Steve Kondik
Browse files

Ims: Fix for Phone App crash and NullPtrException in getCountryIso API

When back to back VOLTE calls are made, sometimes
next MO VOLTE call is failing due to a NullPointerException. The
issue is because of unexpected value in getting the current
country code. Added null check for detector.detectCountry(), if this
function call fails, then CountryIso will be picked up based on the Locale
CRs-Fixed: 478645, 490472

Change-Id: I9f35fe959fc072bf59a6aabc6c17dc4162426721
parent 29b593ee
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.location.CountryDetector;
import android.location.Country;
import android.net.Uri;
import android.os.SystemProperties;
import android.provider.Contacts;
@@ -1812,16 +1813,21 @@ public class PhoneNumberUtils
    private static boolean isLocalEmergencyNumberInternal(String number,
                                                          Context context,
                                                          boolean useExactMatch) {
        String countryIso;
        String countryIso = null;
        Country country;
        CountryDetector detector = (CountryDetector) context.getSystemService(
                Context.COUNTRY_DETECTOR);
        if (detector != null) {
            countryIso = detector.detectCountry().getCountryIso();
        if ((detector != null) && ((country = detector.detectCountry()) != null)) {
            countryIso = country.getCountryIso();
        } else {
            Locale locale = context.getResources().getConfiguration().locale;
            if(locale != null) {
                countryIso = locale.getCountry();
                Rlog.w(LOG_TAG, "No CountryDetector; falling back to countryIso based on locale: "
                        + countryIso);
            } else {
                countryIso = "US"; //default value is "US"
            }
        }
        return isEmergencyNumberInternal(number, countryIso, useExactMatch);
    }
+2 −0
Original line number Diff line number Diff line
@@ -550,6 +550,8 @@ public class CallerInfo {
            if (VDBG) Rlog.v(TAG, "- parsed number: " + pn);
        } catch (NumberParseException e) {
            Rlog.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + number + "'");
        } catch (Exception e) {
            Log.w(TAG, "Exception Caught" + e);
        }

        if (pn != null) {
+10 −3
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.location.CountryDetector;
import android.location.Country;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
@@ -271,11 +272,17 @@ public class CallerInfoAsyncQuery {

                    // Use the number entered by the user for display.
                    if (!TextUtils.isEmpty(cw.number)) {
                        Country country;
                        CountryDetector detector = (CountryDetector) mQueryContext.getSystemService(
                                Context.COUNTRY_DETECTOR);
                        if (detector != null) {
                            country = detector.detectCountry();
                            if (country != null) {
                                mCallerInfo.phoneNumber = PhoneNumberUtils.formatNumber(cw.number,
                                    mCallerInfo.normalizedNumber,
                                detector.detectCountry().getCountryIso());
                                    country.getCountryIso());
                            }
                        }
                    }
                }