summaryrefslogtreecommitdiff
path: root/InCallUI
diff options
context:
space:
mode:
authorJay Shrauner <shrauner@google.com>2013-10-09 15:52:48 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-10-09 15:52:48 -0700
commita55055f82605ae0bdeb34ba7a4f1fbe3caaf721e (patch)
tree01cc8cda21690c7ba3beae1f9bbbac0bcc817386 /InCallUI
parentc3a5ed3faae9f0bbe5cbe459a0e7d04545b8d912 (diff)
parente41fcac5874a588276179e099d9032348da563f5 (diff)
am 495425bb: am c2555d1c: am 4e9d508e: Merge "Catch potential NPE" into klp-dev
* commit '495425bbe206bd7b19d27204060aa9723846cfc8': Catch potential NPE
Diffstat (limited to 'InCallUI')
-rw-r--r--InCallUI/src/com/android/incallui/CallerInfo.java31
-rw-r--r--InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java5
2 files changed, 22 insertions, 14 deletions
diff --git a/InCallUI/src/com/android/incallui/CallerInfo.java b/InCallUI/src/com/android/incallui/CallerInfo.java
index 4047d9900..c5d397191 100644
--- a/InCallUI/src/com/android/incallui/CallerInfo.java
+++ b/InCallUI/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/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java b/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java
index c9d282b25..c09baf210 100644
--- a/InCallUI/src/com/android/incallui/CallerInfoAsyncQuery.java
+++ b/InCallUI/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));
}
}