From 4cd393a317ed797173735cb35f011e480073721c Mon Sep 17 00:00:00 2001 From: Anna Bauza Date: Mon, 14 Mar 2022 13:35:17 +0000 Subject: [PATCH] Fix "Welcome back Guest" dialog dismisses when screen turns off. New constructor to SystemUIDialog has been introduced which does not take theme (apply default) and takes additional boolean parameter dismissOnDeviceLock. This has been used with false. Bug: 199768843 Test: atest SystemUIDialogTest Change-Id: Ib423a58ad9efe557a8ee5c95807026a6c0fa5f93 --- .../systemui/GuestResumeSessionReceiver.java | 2 +- .../statusbar/phone/SystemUIDialog.java | 10 +++++++-- .../statusbar/phone/SystemUIDialogTest.java | 22 +++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/GuestResumeSessionReceiver.java b/packages/SystemUI/src/com/android/systemui/GuestResumeSessionReceiver.java index b5b6b1340108b..9a6020f8556bd 100644 --- a/packages/SystemUI/src/com/android/systemui/GuestResumeSessionReceiver.java +++ b/packages/SystemUI/src/com/android/systemui/GuestResumeSessionReceiver.java @@ -128,7 +128,7 @@ public class GuestResumeSessionReceiver extends BroadcastReceiver { UserSwitcherController userSwitcherController, UiEventLogger uiEventLogger, int userId) { - super(context); + super(context, false /* dismissOnDeviceLock */); setTitle(context.getString(R.string.guest_wipe_session_title)); setMessage(context.getString(R.string.guest_wipe_session_message)); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java index 79d646cdbd134..d26b378650e39 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/SystemUIDialog.java @@ -63,6 +63,8 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh // TODO(b/203389579): Remove this once the dialog width on large screens has been agreed on. private static final String FLAG_TABLET_DIALOG_WIDTH = "persist.systemui.flag_tablet_dialog_width"; + private static final int DEFAULT_THEME = R.style.Theme_SystemUI_Dialog; + private static final boolean DEFAULT_DISMISS_ON_DEVICE_LOCK = true; private final Context mContext; @Nullable private final DismissReceiver mDismissReceiver; @@ -78,11 +80,15 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh private List mOnCreateRunnables = new ArrayList<>(); public SystemUIDialog(Context context) { - this(context, R.style.Theme_SystemUI_Dialog); + this(context, DEFAULT_THEME, DEFAULT_DISMISS_ON_DEVICE_LOCK); } public SystemUIDialog(Context context, int theme) { - this(context, theme, true /* dismissOnDeviceLock */); + this(context, theme, DEFAULT_DISMISS_ON_DEVICE_LOCK); + } + + public SystemUIDialog(Context context, boolean dismissOnDeviceLock) { + this(context, DEFAULT_THEME, dismissOnDeviceLock); } public SystemUIDialog(Context context, int theme, boolean dismissOnDeviceLock) { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java index 589aa03538708..7c05c69ff3b5b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/SystemUIDialogTest.java @@ -14,10 +14,12 @@ package com.android.systemui.statusbar.phone; +import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import android.content.BroadcastReceiver; @@ -43,7 +45,6 @@ import org.mockito.MockitoAnnotations; @SmallTest public class SystemUIDialogTest extends SysuiTestCase { - private SystemUIDialog mDialog; @Mock private BroadcastDispatcher mBroadcastDispatcher; @@ -52,12 +53,11 @@ public class SystemUIDialogTest extends SysuiTestCase { MockitoAnnotations.initMocks(this); mDependency.injectTestDependency(BroadcastDispatcher.class, mBroadcastDispatcher); - - mDialog = new SystemUIDialog(mContext); } @Test public void testRegisterReceiver() { + final SystemUIDialog mDialog = new SystemUIDialog(mContext); final ArgumentCaptor broadcastReceiverCaptor = ArgumentCaptor.forClass(BroadcastReceiver.class); final ArgumentCaptor intentFilterCaptor = @@ -66,10 +66,24 @@ public class SystemUIDialogTest extends SysuiTestCase { mDialog.show(); verify(mBroadcastDispatcher).registerReceiver(broadcastReceiverCaptor.capture(), intentFilterCaptor.capture(), eq(null), any()); - + assertTrue(intentFilterCaptor.getValue().hasAction(Intent.ACTION_SCREEN_OFF)); assertTrue(intentFilterCaptor.getValue().hasAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); mDialog.dismiss(); verify(mBroadcastDispatcher).unregisterReceiver(eq(broadcastReceiverCaptor.getValue())); } + + + @Test + public void testNoRegisterReceiver() { + final SystemUIDialog mDialog = new SystemUIDialog(mContext, false); + + mDialog.show(); + verify(mBroadcastDispatcher, never()).registerReceiver(any(), any(), eq(null), any()); + assertTrue(mDialog.isShowing()); + + mDialog.dismiss(); + verify(mBroadcastDispatcher, never()).unregisterReceiver(any()); + assertFalse(mDialog.isShowing()); + } }