From b210f35a76222b3486524cca6e95f8c36ebe3b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Hern=C3=A1ndez?= Date: Mon, 2 Sep 2024 18:00:36 +0200 Subject: [PATCH] Prevent "new mode" and "choose schedule" dialogs from being created without a listener This can happen if the activity is recreated; our approach doesn't support this case very well. With this change, the dialog is not reshown when the activity is recreated, which is not optimal but better than crashing (as it does today). There is no lost work because it's the first choice, and the follow-on steps (icon picker, etc) can be recreated without problems. Fixes: 359746551 Test: manual, with don't keep activities Flag: android.app.modes_ui Change-Id: I84bdeb0007e8c50ec9dd8af61991c7e55ddb8298 --- .../modes/ZenModeScheduleChooserDialog.java | 11 +++++++++++ .../modes/ZenModesListAddModeTypeChooserDialog.java | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/com/android/settings/notification/modes/ZenModeScheduleChooserDialog.java b/src/com/android/settings/notification/modes/ZenModeScheduleChooserDialog.java index d129aad6ad6..370199a6292 100644 --- a/src/com/android/settings/notification/modes/ZenModeScheduleChooserDialog.java +++ b/src/com/android/settings/notification/modes/ZenModeScheduleChooserDialog.java @@ -81,6 +81,17 @@ public class ZenModeScheduleChooserDialog extends InstrumentedDialogFragment { dialog.show(parent.getParentFragmentManager(), TAG); } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (mOptionListener == null) { + // Probably the dialog fragment was recreated after its activity being destroyed. + // It's pointless to re-show the dialog if we can't do anything when its options are + // selected, so we don't. + dismiss(); + } + } + @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { diff --git a/src/com/android/settings/notification/modes/ZenModesListAddModeTypeChooserDialog.java b/src/com/android/settings/notification/modes/ZenModesListAddModeTypeChooserDialog.java index e7905a8f936..0bf9c5bd472 100644 --- a/src/com/android/settings/notification/modes/ZenModesListAddModeTypeChooserDialog.java +++ b/src/com/android/settings/notification/modes/ZenModesListAddModeTypeChooserDialog.java @@ -70,6 +70,17 @@ public class ZenModesListAddModeTypeChooserDialog extends InstrumentedDialogFrag dialog.show(parent.getParentFragmentManager(), TAG); } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (mChooseModeTypeListener == null) { + // Probably the dialog fragment was recreated after its activity being destroyed. + // It's pointless to re-show the dialog if we can't do anything when its options are + // selected, so we don't. + dismiss(); + } + } + @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {