From e931c12468e5558b1516f6eaea154d4844040a79 Mon Sep 17 00:00:00 2001 From: twyen Date: Mon, 19 Mar 2018 14:47:28 -0700 Subject: Check null for getPhoneAccount() A phone account can be removed after calling getCallCapablePhoneAccounts(), so subsequent getPhoneAccount() can be null. Other usages already has the null check. Bug: 75598828 Test: N/A testing this involves getPhoneAccount() returning null on the nth call, which requires replacing the shadows with a mock and is highly coupled with the implementation. The is an edge case and is not worth the effort and brittleness it will cause. PiperOrigin-RevId: 189644833 Change-Id: Ie92dda2537befb5936ad734954b4eaf75964f465 --- java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java | 7 ++++--- java/com/android/dialer/app/settings/DialerSettingsActivity.java | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'java/com/android/dialer/app') diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java index 7b1536b37..f37d52d68 100644 --- a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java +++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java @@ -141,13 +141,14 @@ public final class LegacyVoicemailNotifier { if (TelecomUtil.getCallCapablePhoneAccounts(context).size() > 1) { TelecomManager telecomManager = context.getSystemService(TelecomManager.class); PhoneAccount phoneAccount = telecomManager.getPhoneAccount(handle); - return phoneAccount.getShortDescription().toString(); - } else { + if (phoneAccount != null) { + return phoneAccount.getShortDescription().toString(); + } + } return String.format( context.getString(R.string.notification_voicemail_text_format), PhoneNumberHelper.formatNumber( context, voicemailNumber, GeoUtil.getCurrentCountryIso(context))); - } } public static void cancelNotification( diff --git a/java/com/android/dialer/app/settings/DialerSettingsActivity.java b/java/com/android/dialer/app/settings/DialerSettingsActivity.java index 24e5fe8aa..09fe03ef5 100644 --- a/java/com/android/dialer/app/settings/DialerSettingsActivity.java +++ b/java/com/android/dialer/app/settings/DialerSettingsActivity.java @@ -241,6 +241,9 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { PhoneAccountHandle result = null; for (PhoneAccountHandle phoneAccountHandle : telecomManager.getCallCapablePhoneAccounts()) { PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle); + if (phoneAccount == null) { + continue; + } if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION)) { LogUtil.i( "DialerSettingsActivity.getSoleSimAccount", phoneAccountHandle + " is a SIM account"); -- cgit v1.2.3