summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Shrauner <shrauner@google.com>2013-10-09 22:41:51 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-10-09 22:41:52 +0000
commit4e9d508e08b3b7fe929a64d98d11a372a4a44045 (patch)
treed3ae430d9908420501202090b291b2dc3ff0878e
parent8f7a4eb36ceaa19e19c4a4d0e71cbad4cc3c934c (diff)
parent1c85bef1f4ee97a3443d130bdff178ba4db1539f (diff)
downloadpackages_apps_InCallUI-4e9d508e08b3b7fe929a64d98d11a372a4a44045.tar.gz
packages_apps_InCallUI-4e9d508e08b3b7fe929a64d98d11a372a4a44045.tar.bz2
packages_apps_InCallUI-4e9d508e08b3b7fe929a64d98d11a372a4a44045.zip
Merge "Catch potential NPE" into klp-dev
-rw-r--r--src/com/android/incallui/CallerInfo.java31
-rw-r--r--src/com/android/incallui/CallerInfoAsyncQuery.java5
2 files changed, 22 insertions, 14 deletions
diff --git a/src/com/android/incallui/CallerInfo.java b/src/com/android/incallui/CallerInfo.java
index 4047d990..c5d39719 100644
--- a/src/com/android/incallui/CallerInfo.java
+++ b/src/com/android/incallui/CallerInfo.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
+import android.location.Country;
import android.location.CountryDetector;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -560,17 +561,27 @@ public class CallerInfo {
* is in.
*/
private static String getCurrentCountryIso(Context context, Locale locale) {
- String countryIso;
- CountryDetector detector = (CountryDetector) context.getSystemService(
- Context.COUNTRY_DETECTOR);
- if (detector != null) {
- countryIso = detector.detectCountry().getCountryIso();
- } else {
- countryIso = locale.getCountry();
- Log.v(TAG, "No CountryDetector; falling back to countryIso based on locale: "
+ String countryIso = null;
+ CountryDetector detector = (CountryDetector) context.getSystemService(
+ Context.COUNTRY_DETECTOR);
+ if (detector != null) {
+ Country country = detector.detectCountry();
+ if (country != null) {
+ countryIso = country.getCountryIso();
+ } else {
+ Log.e(TAG, "CountryDetector.detectCountry() returned null.");
+ }
+ }
+ if (countryIso == null) {
+ countryIso = locale.getCountry();
+ Log.w(TAG, "No CountryDetector; falling back to countryIso based on locale: "
+ countryIso);
- }
- return countryIso;
+ }
+ return countryIso;
+ }
+
+ protected static String getCurrentCountryIso(Context context) {
+ return getCurrentCountryIso(context, Locale.getDefault());
}
/**
diff --git a/src/com/android/incallui/CallerInfoAsyncQuery.java b/src/com/android/incallui/CallerInfoAsyncQuery.java
index c9d282b2..c09baf21 100644
--- a/src/com/android/incallui/CallerInfoAsyncQuery.java
+++ b/src/com/android/incallui/CallerInfoAsyncQuery.java
@@ -20,7 +20,6 @@ import android.content.AsyncQueryHandler;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
-import android.location.CountryDetector;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
@@ -269,11 +268,9 @@ public class CallerInfoAsyncQuery {
// Use the number entered by the user for display.
if (!TextUtils.isEmpty(cw.number)) {
- CountryDetector detector = (CountryDetector) mQueryContext.getSystemService(
- Context.COUNTRY_DETECTOR);
mCallerInfo.phoneNumber = PhoneNumberUtils.formatNumber(cw.number,
mCallerInfo.normalizedNumber,
- detector.detectCountry().getCountryIso());
+ CallerInfo.getCurrentCountryIso(mQueryContext));
}
}