diff options
author | twyen <twyen@google.com> | 2018-03-19 14:47:28 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-19 15:22:34 -0700 |
commit | e931c12468e5558b1516f6eaea154d4844040a79 (patch) | |
tree | 8475b4a61d7d637dd3aa41f258e29d4e1e4f5f49 /java | |
parent | 6f80c367c2579fc6829fc68bed9b5c8d220709b6 (diff) |
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
Diffstat (limited to 'java')
5 files changed, 16 insertions, 3 deletions
diff --git a/java/com/android/contacts/common/dialog/CallSubjectDialog.java b/java/com/android/contacts/common/dialog/CallSubjectDialog.java index 7bc13fe72..48f292cfa 100644 --- a/java/com/android/contacts/common/dialog/CallSubjectDialog.java +++ b/java/com/android/contacts/common/dialog/CallSubjectDialog.java @@ -531,6 +531,9 @@ public class CallSubjectDialog extends Activity { TelecomManager telecomManager = (TelecomManager) getSystemService(Context.TELECOM_SERVICE); final PhoneAccount account = telecomManager.getPhoneAccount(mPhoneAccountHandle); + if (account == null) { + return; + } Bundle phoneAccountExtras = account.getExtras(); if (phoneAccountExtras == null) { 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"); diff --git a/java/com/android/dialer/telecom/TelecomUtil.java b/java/com/android/dialer/telecom/TelecomUtil.java index 56349b651..2608cb2aa 100644 --- a/java/com/android/dialer/telecom/TelecomUtil.java +++ b/java/com/android/dialer/telecom/TelecomUtil.java @@ -311,6 +311,9 @@ public abstract class TelecomUtil { TelecomManager telecomManager = context.getSystemService(TelecomManager.class); for (PhoneAccountHandle phoneAccountHandle : telecomManager.getCallCapablePhoneAccounts()) { PhoneAccount phoneAccount = telecomManager.getPhoneAccount(phoneAccountHandle); + if (phoneAccount == null) { + continue; + } if (phoneAccount.hasCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION) && !phoneAccountHandle.equals(currentAccount)) { return phoneAccountHandle; diff --git a/java/com/android/incallui/StatusBarNotifier.java b/java/com/android/incallui/StatusBarNotifier.java index e2340b5e7..ef5965c09 100644 --- a/java/com/android/incallui/StatusBarNotifier.java +++ b/java/com/android/incallui/StatusBarNotifier.java @@ -803,6 +803,9 @@ public class StatusBarNotifier private CharSequence getMultiSimIncomingText(DialerCall call) { PhoneAccount phoneAccount = context.getSystemService(TelecomManager.class).getPhoneAccount(call.getAccountHandle()); + if (phoneAccount == null) { + return context.getString(R.string.notification_incoming_call); + } SpannableString string = new SpannableString( context.getString( |