Merge "Make the force stop dialog work properly in split screen" into tm-dev am: f6c416054e

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18281655

Change-Id: I9cea804407d90ff8b7304d311031e25d1b340e0e
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Yi-Ling Chuang
2022-05-12 03:47:04 +00:00
committed by Automerger Merge Worker
2 changed files with 23 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);