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

Commit 292b2409 authored by Maria Petrisor's avatar Maria Petrisor Committed by Android (Google) Code Review
Browse files

Merge "Show Lock button only when device is unlocked" into main

parents e5e3442e cb3ec459
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -1477,8 +1477,10 @@ public class GlobalActionsDialogLite implements DialogInterface.OnDismissListene


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


+32 −1
Original line number Original line Diff line number Diff line
@@ -1006,6 +1006,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isUnlocked();
        doCallRealMethod()
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
@@ -1036,6 +1037,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isUnlocked();
        doCallRealMethod()
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
@@ -1063,6 +1065,7 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isMethodSecure();
        doReturn(true).when(mKeyguardStateController).isUnlocked();
        doCallRealMethod()
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
@@ -1090,6 +1093,35 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(4).when(mGlobalActionsDialogLite).getMaxShownPowerItems();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(true).when(mGlobalActionsDialogLite).shouldDisplayEmergency();
        doReturn(false).when(mKeyguardStateController).isMethodSecure();
        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()
        doCallRealMethod()
                .when(mGlobalActionsDialogLite)
                .when(mGlobalActionsDialogLite)
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
                .shouldShowAction(any(GlobalActionsDialogLite.LockAction.class));
@@ -1113,6 +1145,5 @@ public class GlobalActionsDialogLiteTest extends SysuiTestCase {


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

    }
    }
}
}