Don't crash in CP2 if country detector is null
Bug: 10539498
Change-Id: Ic094e472e5a567e1dc6be4cbd14c02938df1de47
diff --git a/src/com/android/providers/contacts/CountryMonitor.java b/src/com/android/providers/contacts/CountryMonitor.java
index 2a20b08..7796849 100644
--- a/src/com/android/providers/contacts/CountryMonitor.java
+++ b/src/com/android/providers/contacts/CountryMonitor.java
@@ -22,6 +22,8 @@
import android.location.CountryListener;
import android.os.Looper;
+import java.util.Locale;
+
/**
* This class monitors the change of country.
* <p>
@@ -45,12 +47,20 @@
if (mCurrentCountryIso == null) {
final CountryDetector countryDetector =
(CountryDetector) mContext.getSystemService(Context.COUNTRY_DETECTOR);
- mCurrentCountryIso = countryDetector.detectCountry().getCountryIso();
- countryDetector.addCountryListener(new CountryListener() {
- public void onCountryDetected(Country country) {
- mCurrentCountryIso = country.getCountryIso();
- }
- }, Looper.getMainLooper());
+ Country country = null;
+ if (countryDetector != null) country = countryDetector.detectCountry();
+
+ if (country == null) {
+ // Fallback to Locale if there are issues with CountryDetector
+ return Locale.getDefault().getCountry();
+ }
+
+ mCurrentCountryIso = country.getCountryIso();
+ countryDetector.addCountryListener(new CountryListener() {
+ public void onCountryDetected(Country country) {
+ mCurrentCountryIso = country.getCountryIso();
+ }
+ }, Looper.getMainLooper());
}
return mCurrentCountryIso;
}