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
This commit is contained in:
Anna Bauza
2022-03-14 13:35:17 +00:00
parent 8a7f011f14
commit 4cd393a317
3 changed files with 27 additions and 7 deletions

View File

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

View File

@@ -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<Runnable> 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) {

View File

@@ -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<BroadcastReceiver> broadcastReceiverCaptor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
final ArgumentCaptor<IntentFilter> 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());
}
}