From 6d87dbcb3843d6c5adf5f6d82e4fd00cba6dd8e5 Mon Sep 17 00:00:00 2001 From: maxwelb Date: Mon, 13 Nov 2017 18:58:45 -0800 Subject: Fix crash caused by opening dialogs with a dead activity This CL fixes crashes that are caused by opening the PhoneDisambiguationDialogFragment after the associated activity is destroyed. This is done by detecting when the activity is destroyed or finished. Bug: 69133504 Test: PhoneNumberInteractionTest PiperOrigin-RevId: 175623483 Change-Id: Ic639e9e9421205edcb5438d594bb144c6b09dd86 --- java/com/android/dialer/interactions/PhoneNumberInteraction.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/java/com/android/dialer/interactions/PhoneNumberInteraction.java b/java/com/android/dialer/interactions/PhoneNumberInteraction.java index 15c6ce899..5a6c34607 100644 --- a/java/com/android/dialer/interactions/PhoneNumberInteraction.java +++ b/java/com/android/dialer/interactions/PhoneNumberInteraction.java @@ -82,7 +82,7 @@ import java.util.List; */ public class PhoneNumberInteraction implements OnLoadCompleteListener { - private static final String TAG = PhoneNumberInteraction.class.getSimpleName(); + static final String TAG = PhoneNumberInteraction.class.getSimpleName(); /** The identifier for a permissions request if one is generated. */ public static final int REQUEST_READ_CONTACTS = 1; @@ -356,12 +356,19 @@ public class PhoneNumberInteraction implements OnLoadCompleteListener { } private void showDisambiguationDialog(ArrayList phoneList) { + // TODO(a bug): don't leak the activity final Activity activity = (Activity) mContext; + if (activity.isFinishing()) { + LogUtil.i("PhoneNumberInteraction.showDisambiguationDialog", "activity finishing"); + return; + } + if (activity.isDestroyed()) { // Check whether the activity is still running LogUtil.i("PhoneNumberInteraction.showDisambiguationDialog", "activity destroyed"); return; } + try { PhoneDisambiguationDialogFragment.show( activity.getFragmentManager(), -- cgit v1.2.3