Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c903e9d8 authored by Kevin Chyn's avatar Kevin Chyn Committed by Android (Google) Code Review
Browse files

Merge "Add option to not dismiss SysuiDialog due to ACSD" into main

parents a7656c9a c59e5928
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
@@ -119,6 +120,22 @@ public class SystemUIDialogTest extends SysuiTestCase {
        assertFalse(dialog.isShowing());
    }

    @Test
    public void testRegisterReceiverWithoutAcsd() {
        SystemUIDialog dialog = createDialogWithDelegate(mContext, mDelegate,
                false /* shouldAcsdDismissDialog */);
        final ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor =
                ArgumentCaptor.forClass(BroadcastReceiver.class);
        final ArgumentCaptor<IntentFilter> intentFilterCaptor =
                ArgumentCaptor.forClass(IntentFilter.class);

        dialog.show();
        verify(mBroadcastDispatcher).registerReceiver(broadcastReceiverCaptor.capture(),
                intentFilterCaptor.capture(), ArgumentMatchers.eq(null), ArgumentMatchers.any());
        assertTrue(intentFilterCaptor.getValue().hasAction(Intent.ACTION_SCREEN_OFF));
        assertFalse(intentFilterCaptor.getValue().hasAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_PREDICTIVE_BACK_ANIMATE_DIALOGS)
    public void usePredictiveBackAnimFlag() {
@@ -163,7 +180,8 @@ public class SystemUIDialogTest extends SysuiTestCase {
    public void delegateIsCalled_inCorrectOrder() {
        Configuration configuration = new Configuration();
        InOrder inOrder = Mockito.inOrder(mDelegate);
        SystemUIDialog dialog = createDialogWithDelegate();
        SystemUIDialog dialog = createDialogWithDelegate(mContext, mDelegate,
                true /* shouldAcsdDismissDialog */);

        dialog.show();
        dialog.onWindowFocusChanged(/* hasFocus= */ true);
@@ -178,7 +196,8 @@ public class SystemUIDialogTest extends SysuiTestCase {
        inOrder.verify(mDelegate).onStop(dialog);
    }

    private SystemUIDialog createDialogWithDelegate() {
    private SystemUIDialog createDialogWithDelegate(Context context,
            SystemUIDialog.Delegate delegate, boolean shouldAcsdDismissDialog) {
        SystemUIDialog.Factory factory = new SystemUIDialog.Factory(
                getContext(),
                Dependency.get(SystemUIDialogManager.class),
@@ -186,6 +205,6 @@ public class SystemUIDialogTest extends SysuiTestCase {
                Dependency.get(BroadcastDispatcher.class),
                Dependency.get(DialogTransitionAnimator.class)
        );
        return factory.create(mDelegate);
        return factory.create(delegate, context, shouldAcsdDismissDialog);
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -47,7 +47,11 @@ internal constructor(
    }

    override fun createDialog(): SystemUIDialog {
        return systemUIDialogFactory.create(this, rearDisplayContext)
        return systemUIDialogFactory.create(
            this,
            rearDisplayContext,
            false, /* shouldAcsdDismissDialog */
        )
    }

    override fun onCreate(dialog: SystemUIDialog, savedInstanceState: Bundle?) {
+1 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ class ComponentSystemUIDialog(
        broadcastDispatcher,
        dialogTransitionAnimator,
        delegate,
        true, /* shouldAcsdDismissDialog */
    ),
    LifecycleOwner,
    SavedStateRegistryOwner,
+37 −18
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
         */
        public SystemUIDialog create() {
            return create(new DialogDelegate<>() {
            }, mContext, DEFAULT_THEME);
            }, mContext, DEFAULT_THEME, true /* shouldAcsdDismissDialog */);
        }

        /**
@@ -155,7 +155,7 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
         */
        public SystemUIDialog create(Context context) {
            return create(new DialogDelegate<>() {
            }, context, DEFAULT_THEME);
            }, context, DEFAULT_THEME, true /* shouldAcsdDismissDialog */);
        }

        /**
@@ -168,8 +168,21 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
            return create(delegate, context, DEFAULT_THEME);
        }

        /**
         * Creates a new instance of {@link SystemUIDialog} with {@code delegate} as the {@link
         * Delegate}. When you need to customize the dialog, pass it a delegate.
         *
         * This method allows the caller to specify if the dialog should be dismissed in response
         * to the ACTION_CLOSE_SYSTEM_DIALOGS intent.
         */
        public SystemUIDialog create(Delegate delegate, Context context,
                boolean shouldAcsdDismissDialog) {
            return create(delegate, context, DEFAULT_THEME, shouldAcsdDismissDialog);
        }

        public SystemUIDialog create(Delegate delegate, Context context, @StyleRes int theme) {
            return create((DialogDelegate<SystemUIDialog>) delegate, context, theme);
            return create((DialogDelegate<SystemUIDialog>) delegate, context, theme,
                    true /* shouldAcsdDismissDialog */);
        }

        public SystemUIDialog create(Delegate delegate) {
@@ -177,7 +190,7 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
        }

        private SystemUIDialog create(DialogDelegate<SystemUIDialog> dialogDelegate,
                Context context, @StyleRes int theme) {
                Context context, @StyleRes int theme, boolean shouldAcsdDismissDialog) {
            return new SystemUIDialog(
                    context,
                    theme,
@@ -186,7 +199,8 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
                    mSysUiState,
                    mBroadcastDispatcher,
                    mDialogTransitionAnimator,
                    dialogDelegate);
                    dialogDelegate,
                    shouldAcsdDismissDialog);
        }
    }

@@ -207,7 +221,8 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
                broadcastDispatcher,
                dialogTransitionAnimator,
                new DialogDelegate<>() {
                });
                },
                true /* shouldAcsdDismissDialog */);
    }

    public SystemUIDialog(
@@ -227,7 +242,8 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
                sysUiState,
                broadcastDispatcher,
                dialogTransitionAnimator,
                (DialogDelegate<SystemUIDialog>) delegate);
                (DialogDelegate<SystemUIDialog>) delegate,
                true /* shouldAcsdDismissDialog */);
    }

    public SystemUIDialog(
@@ -238,7 +254,8 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
            SysUiState sysUiState,
            BroadcastDispatcher broadcastDispatcher,
            DialogTransitionAnimator dialogTransitionAnimator,
            DialogDelegate<SystemUIDialog> delegate) {
            DialogDelegate<SystemUIDialog> delegate,
            boolean shouldAcsdDismissDialog) {
        super(context, theme);
        mContext = context;
        mDelegate = delegate;
@@ -249,7 +266,7 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
        getWindow().setAttributes(attrs);

        mDismissReceiver = dismissOnDeviceLock ? new DismissReceiver(this, broadcastDispatcher,
                dialogTransitionAnimator) : null;
                dialogTransitionAnimator, shouldAcsdDismissDialog) : null;
        mDialogManager = dialogManager;
        mSysUiState = sysUiState;
    }
@@ -523,7 +540,8 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
        // TODO(b/219008720): Remove those calls to Dependency.get.
        DismissReceiver dismissReceiver = new DismissReceiver(dialog,
                Dependency.get(BroadcastDispatcher.class),
                Dependency.get(DialogTransitionAnimator.class));
                Dependency.get(DialogTransitionAnimator.class),
                true /* shouldAcsdDismissDialog */);
        dialog.setOnDismissListener(d -> {
            dismissReceiver.unregister();
            if (dismissAction != null) dismissAction.run();
@@ -595,12 +613,7 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
    }

    private static class DismissReceiver extends BroadcastReceiver {
        private static final IntentFilter INTENT_FILTER = new IntentFilter();

        static {
            INTENT_FILTER.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            INTENT_FILTER.addAction(Intent.ACTION_SCREEN_OFF);
        }
        private final IntentFilter mIntentFilter = new IntentFilter();

        private final Dialog mDialog;
        private boolean mRegistered;
@@ -608,14 +621,20 @@ public class SystemUIDialog extends AlertDialog implements ViewRootImpl.ConfigCh
        private final DialogTransitionAnimator mDialogTransitionAnimator;

        DismissReceiver(Dialog dialog, BroadcastDispatcher broadcastDispatcher,
                DialogTransitionAnimator dialogTransitionAnimator) {
                DialogTransitionAnimator dialogTransitionAnimator,
                boolean shouldAcsdDismissDialog) {
            mDialog = dialog;
            mBroadcastDispatcher = broadcastDispatcher;
            mDialogTransitionAnimator = dialogTransitionAnimator;

            mIntentFilter.addAction(Intent.ACTION_SCREEN_OFF);
            if (shouldAcsdDismissDialog) {
                mIntentFilter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
            }
        }

        void register() {
            mBroadcastDispatcher.registerReceiver(this, INTENT_FILTER, null, UserHandle.CURRENT);
            mBroadcastDispatcher.registerReceiver(this, mIntentFilter, null, UserHandle.CURRENT);
            mRegistered = true;
        }