From f42d5e7e2ee7dde31e64270246c2e3b8d573d61b Mon Sep 17 00:00:00 2001 From: David Brown Date: Wed, 17 Mar 2010 23:03:45 -0700 Subject: [PATCH] Fix 2520977: NPE in com.android.settings.deviceinfo.Status In normal operation, Phone.getLine1Number() returns an empty string if the device doesn't know its own phone number for some reason. However the monkey caught a case where it was returning null, which crashed the Settings -> About Phone -> Status app. However the javadoc for Phone.getLine1Number() *does* clearly say "May return null if not available or the SIM is not ready", so the Status app *should* gracefully handle this. Now it does. (We display this case as "Unknown", just like if we get an empty string.) FWIW I grepped thru the rest of the code base for other uses of getLine1Number(), and everybody else *does* handle null gracefully except for one case in apps/Mms, which I'll open a separate bug about. Bug: 2520977 Change-Id: I173561f903f116dbdc2b7c32b8011b59a9eb29d7 --- src/com/android/settings/deviceinfo/Status.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/deviceinfo/Status.java b/src/com/android/settings/deviceinfo/Status.java index ea3ca97642f..99a8975e07d 100644 --- a/src/com/android/settings/deviceinfo/Status.java +++ b/src/com/android/settings/deviceinfo/Status.java @@ -222,7 +222,13 @@ public class Status extends PreferenceActivity { } } - setSummaryText("number", PhoneNumberUtils.formatNumber(mPhone.getLine1Number())); + String rawNumber = mPhone.getLine1Number(); // may be null or empty + String formattedNumber = null; + if (!TextUtils.isEmpty(rawNumber)) { + formattedNumber = PhoneNumberUtils.formatNumber(rawNumber); + } + // If formattedNumber is null or empty, it'll display as "Unknown". + setSummaryText("number", formattedNumber); mPhoneStateReceiver = new PhoneStateIntentReceiver(this, mHandler); mPhoneStateReceiver.notifySignalStrength(EVENT_SIGNAL_STRENGTH_CHANGED);