diff options
| author | 2022-09-24 01:13:30 +0800 | |
|---|---|---|
| committer | 2022-12-06 14:51:31 -0500 | |
| commit | 3588cb06ba73bd42f47bc3ea69b58bcfffa7a92f (patch) | |
| tree | da9fd836e05b75c9e9702a6791193223354f12c6 | |
| parent | 5cb3c55774aa7c1c5d5b147a75c4f7addbd6b60a (diff) | |
Fix crash when trying to dismiss dialog
Calling Dialog.dismiss() requires a safe condition, including that
dialog is shown,and activity is neither finishing nor destroying, so we
should add a precondition check here to avoid crash.
Bug: 248562161
Test: manual and atest
Change-Id: I87de2cd05680815d4bb4e80ac1e0d6e2e4a685f7
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt index 8472ca0731d7..041ed1d557d7 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlActionCoordinatorImpl.kt @@ -18,6 +18,7 @@ package com.android.systemui.controls.ui import android.annotation.AnyThread import android.annotation.MainThread +import android.app.Activity import android.app.AlertDialog import android.app.Dialog import android.app.PendingIntent @@ -85,8 +86,16 @@ class ControlActionCoordinatorImpl @Inject constructor( } override fun closeDialogs() { - dialog?.dismiss() - dialog = null + val isActivityFinishing = + (activityContext as? Activity)?.let { it.isFinishing || it.isDestroyed } + if (isActivityFinishing == true) { + dialog = null + return + } + if (dialog?.isShowing == true) { + dialog?.dismiss() + dialog = null + } } override fun toggle(cvh: ControlViewHolder, templateId: String, isChecked: Boolean) { |