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

Commit 96c898ba authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Dismiss power menu when user switches." into main

parents 19566c82 02b83645
Loading
Loading
Loading
Loading
+37 −25
Original line number Diff line number Diff line
@@ -147,14 +147,14 @@ import com.android.systemui.util.RingerModeTracker;
import com.android.systemui.util.settings.GlobalSettings;
import com.android.systemui.util.settings.SecureSettings;

import dagger.Lazy;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;

import javax.inject.Inject;

import dagger.Lazy;

/**
 * Helper to show the global actions dialog.  Each item is an {@link Action} that may show depending
 * on whether the keyguard is showing, and whether the device is provisioned.
@@ -270,6 +270,16 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
    private final UserLogoutInteractor mLogoutInteractor;
    private final GlobalActionsInteractor mInteractor;
    private final Lazy<DisplayWindowPropertiesRepository> mDisplayWindowPropertiesRepositoryLazy;
    private final Handler mHandler;

    private final UserTracker.Callback mOnUserSwitched = new UserTracker.Callback() {
        @Override
        public void onBeforeUserSwitching(int newUser) {
            // Dismiss the dialog as soon as we start switching. This will schedule a message
            // in a handler so it will be pretty quick.
            dismissDialog();
        }
    };

    @VisibleForTesting
    public enum GlobalActionsEvent implements UiEventLogger.UiEventEnum {
@@ -425,6 +435,29 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
        mInteractor = interactor;
        mDisplayWindowPropertiesRepositoryLazy = displayWindowPropertiesRepository;

        mHandler = new Handler(mMainHandler.getLooper()) {
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case MESSAGE_DISMISS:
                        if (mDialog != null) {
                            if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
                                // Hide instantly.
                                mDialog.hide();
                                mDialog.dismiss();
                            } else {
                                mDialog.dismiss();
                            }
                            mDialog = null;
                        }
                        break;
                    case MESSAGE_REFRESH:
                        refreshSilentMode();
                        mAdapter.notifyDataSetChanged();
                        break;
                }
            }
        };

        // receive broadcasts
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
@@ -537,6 +570,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
                expandable != null ? expandable.dialogTransitionController(
                        new DialogCuj(InteractionJankMonitor.CUJ_SHADE_DIALOG_OPEN,
                                INTERACTION_JANK_TAG)) : null;
        mUserTracker.addCallback(mOnUserSwitched, mBackgroundExecutor);
        if (controller != null) {
            mDialogTransitionAnimator.show(mDialog, controller);
        } else {
@@ -1404,6 +1438,7 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
        mWindowManagerFuncs.onGlobalActionsHidden();
        mLifecycle.setCurrentState(Lifecycle.State.CREATED);
        mInteractor.onDismissed();
        mUserTracker.removeCallback(mOnUserSwitched);
    }

    /**
@@ -2228,29 +2263,6 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene
        mDialogPressDelay = 0; // ms
    }

    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case MESSAGE_DISMISS:
                    if (mDialog != null) {
                        if (SYSTEM_DIALOG_REASON_DREAM.equals(msg.obj)) {
                            // Hide instantly.
                            mDialog.hide();
                            mDialog.dismiss();
                        } else {
                            mDialog.dismiss();
                        }
                        mDialog = null;
                    }
                    break;
                case MESSAGE_REFRESH:
                    refreshSilentMode();
                    mAdapter.notifyDataSetChanged();
                    break;
            }
        }
    };

    private void onAirplaneModeChanged() {
        // Let the service state callbacks handle the state.
        if (mHasTelephony || mAirplaneModeOn == null) return;
+27 −1
Original line number Diff line number Diff line
@@ -134,7 +134,6 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
    @Mock private RingerModeTracker mRingerModeTracker;
    @Mock private RingerModeLiveData mRingerModeLiveData;
    @Mock private PackageManager mPackageManager;
    @Mock private Handler mHandler;
    @Mock private UserContextProvider mUserContextProvider;
    @Mock private VibratorHelper mVibratorHelper;
    @Mock private ShadeController mShadeController;
@@ -148,6 +147,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
    private TestableLooper mTestableLooper;
    private KosmosJavaAdapter mKosmos = new KosmosJavaAdapter(this);
    private GlobalActionsInteractor mInteractor;
    private Handler mHandler;

    @Before
    public void setUp() throws Exception {
@@ -166,6 +166,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        mGlobalSettings = new FakeGlobalSettings();
        mSecureSettings = new FakeSettings();
        mInteractor = mKosmos.getGlobalActionsInteractor();
        mHandler = new Handler(mTestableLooper.getLooper());

        mGlobalActionsDialogLite = new GlobalActionsDialogLite(mContext,
                mWindowManagerFuncs,
@@ -771,6 +772,31 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        mGlobalActionsDialogLite.showOrHideDialog(false, false, null, Display.DEFAULT_DISPLAY);
    }

    @Test
    public void userSwitching_dismissDialog() {
        String[] actions = {
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
        };
        doReturn(actions).when(mResources)
                .getStringArray(com.android.internal.R.array.config_globalActionsList);

        mGlobalActionsDialogLite.showOrHideDialog(false, true, null, Display.DEFAULT_DISPLAY);
        mTestableLooper.processAllMessages();

        assertThat(mGlobalActionsDialogLite.mDialog.isShowing()).isTrue();

        ArgumentCaptor<UserTracker.Callback> captor =
                ArgumentCaptor.forClass(UserTracker.Callback.class);

        verify(mUserTracker).addCallback(captor.capture(), any());

        captor.getValue().onBeforeUserSwitching(100);
        mTestableLooper.processAllMessages();

        assertThat(mGlobalActionsDialogLite.mDialog).isNull();
    }

    private UserInfo mockCurrentUser(int flags) {
        return new UserInfo(10, "A User", flags);