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

Commit cb3ec459 authored by Maria Petrisor's avatar Maria Petrisor
Browse files

Show Lock button only when device is unlocked

The Lock Power Menu button on desktop is mistakenly displayed when
the Power Menu is started from the Quick Settings when already on
the lock screen. This case is apparently not covered by the
"mKeyguardShowing" check.

Add a more generic check for the device to be unlocked to display
the Lock button in the Power Menu.

Bug: 435162937
Test: atest GlobalActionsDialogLiteTest
Test: manual verification on desktop device
Flag: NONE. The global action will only be configured for desktop
Change-Id: I258261462450713574ae91fcc5f2ef2244e52312
parent bccdec5e
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1477,8 +1477,10 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene

        @Override
        public boolean shouldShow() {
            // Only show the lock button when the device can show a lock screen.
            return mKeyguardStateController.isMethodSecure();
            // Only show the lock button when the device can show a lock screen and the device is
            // unlocked.
            return mKeyguardStateController.isMethodSecure()
                && mKeyguardStateController.isUnlocked();
        }
    }

+32 −1
Original line number Diff line number Diff line
@@ -1006,6 +1006,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isUnlocked();
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
@@ -1036,6 +1037,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isUnlocked();
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
@@ -1063,6 +1065,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isUnlocked();
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
@@ -1090,6 +1093,35 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(false).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isUnlocked();
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
        String[] actions = {
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_EMERGENCY,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_LOCK,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_POWER,
                GlobalActionsDialogLite.GLOBAL_ACTION_KEY_RESTART,
        };
        doReturn(actions).when(mGlobalActionsDialogLite).getDefaultActions();

        mGlobalActionsDialogLite.showOrHideDialog(
            /* keyguardShowing= */ false,
            /* isDeviceProvisioned= */ true,
            /* expandable= */ null,
            /* displayId= */ Display.DEFAULT_DISPLAY);

        assertNoItemsOfType(mGlobalActionsDialogLite.mItems,
                GlobalActionsDialogLite.LockAction.class);
    }

    @Test
    public void testCreateActionItems_deviceLocked_doesNotShowLock() {
        mGlobalActionsDialogLite = spy(mGlobalActionsDialogLite);
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(false).when(mKeyguardStateController).isUnlocked();
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
@@ -1113,6 +1145,5 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {

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

    }
}