Make getCurrentCountryIso null safe

Catch case if CountryDetector isn't available or detectCountry()
returns null; in this case use Locale.getDefault().getCountry()

Bug:9438025
Change-Id: I28fc0278342f6801e64ca07f7255cbd612d26ec1
diff --git a/src/com/android/contacts/common/GeoUtil.java b/src/com/android/contacts/common/GeoUtil.java
index 335d316..aaf4715 100644
--- a/src/com/android/contacts/common/GeoUtil.java
+++ b/src/com/android/contacts/common/GeoUtil.java
@@ -17,8 +17,11 @@
 package com.android.contacts.common;
 
 import android.content.Context;
+import android.location.Country;
 import android.location.CountryDetector;
 
+import java.util.Locale;
+
 /**
  * Static methods related to Geo.
  */
@@ -29,8 +32,15 @@
      *         is in.
      */
     public static final String getCurrentCountryIso(Context context) {
-        CountryDetector detector =
+        final CountryDetector detector =
                 (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR);
-        return detector.detectCountry().getCountryIso();
+        if (detector != null) {
+            final Country country = detector.detectCountry();
+            if (country != null) {
+                return country.getCountryIso();
+            }
+        }
+        // Fallback to Locale if have issues with CountryDetector
+        return Locale.getDefault().getCountry();
     }
 }