From 2754a20c72a483f1e29d6234177bf4667f72a485 Mon Sep 17 00:00:00 2001 From: Yi-Ling Chuang Date: Wed, 11 May 2022 16:29:34 +0800 Subject: [PATCH] Make the force stop dialog work properly in split screen When it's in a multi-window mode, force stopping an app will lead to an activity recreate, and the dialog fragment will also be recreated. That's why the dialog still shows after the button is clicked. Hence, dismiss the dialog before stopping the app to fix it. Fixes: 231529730 Test: robotest Change-Id: I75d27624f0c60bb617e7d1a92ffe01d3c0fbf7be --- .../appinfo/ButtonActionDialogFragment.java | 6 ++++++ .../appinfo/ButtonActionDialogFragmentTest.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/com/android/settings/applications/appinfo/ButtonActionDialogFragment.java b/src/com/android/settings/applications/appinfo/ButtonActionDialogFragment.java index 80ce8020035..7b7e3e944ea 100644 --- a/src/com/android/settings/applications/appinfo/ButtonActionDialogFragment.java +++ b/src/com/android/settings/applications/appinfo/ButtonActionDialogFragment.java @@ -90,6 +90,12 @@ public class ButtonActionDialogFragment extends InstrumentedDialogFragment imple @Override public void onClick(DialogInterface dialog, int which) { + // When it's in a multi-window mode, force stopping an app will lead to an activity + // recreate, and the dialog fragment will also be recreated. So dismiss the dialog before + // stopping the app. + if (mId == ButtonActionDialogFragment.DialogType.FORCE_STOP) { + dialog.dismiss(); + } final AppButtonsDialogListener lsn = (AppButtonsDialogListener) getTargetFragment(); lsn.handleDialogClick(mId); diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/ButtonActionDialogFragmentTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/ButtonActionDialogFragmentTest.java index d9ed6b08b63..432104d27cc 100644 --- a/tests/robotests/src/com/android/settings/applications/appinfo/ButtonActionDialogFragmentTest.java +++ b/tests/robotests/src/com/android/settings/applications/appinfo/ButtonActionDialogFragmentTest.java @@ -18,7 +18,9 @@ package com.android.settings.applications.appinfo; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -72,6 +74,21 @@ public class ButtonActionDialogFragmentTest { verify(mTargetFragment).handleDialogClick(anyInt()); } + @Test + public void testOnClick_forceStop_dismissDialog() { + ButtonActionDialogFragment fragment = + spy(ButtonActionDialogFragment.newInstance(FORCE_STOP_ID)); + FragmentController.setupFragment(fragment, FragmentActivity.class, 0 /* containerViewId */, + null /* bundle */); + doReturn(mTargetFragment).when(fragment).getTargetFragment(); + doNothing().when(mTargetFragment).handleDialogClick(anyInt()); + final AlertDialog dialog = mock(AlertDialog.class); + + fragment.onClick(dialog, 0); + + verify(dialog).dismiss(); + } + @Test public void testOnCreateDialog_forceStopDialog() { ButtonActionDialogFragment fragment = ButtonActionDialogFragment.newInstance(FORCE_STOP_ID);