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()); + } }