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

Commit 8336cb3a authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "On keycode confirmKey (ENTER/SPACE) on keyguard, show primaryBouncer" into main

parents db4be112 d7511c7e
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -65,15 +65,23 @@ public class KeyguardPasswordViewController
    private boolean mPaused;

    private final OnEditorActionListener mOnEditorActionListener = (v, actionId, event) -> {
        // Check if this was the result of hitting the enter key
        // Check if this was the result of hitting the IME done action
        final boolean isSoftImeEvent = event == null
                && (actionId == EditorInfo.IME_NULL
                || actionId == EditorInfo.IME_ACTION_DONE
                || actionId == EditorInfo.IME_ACTION_NEXT);
        final boolean isKeyboardEnterKey = event != null
                && KeyEvent.isConfirmKey(event.getKeyCode())
                && event.getAction() == KeyEvent.ACTION_DOWN;
        if (isSoftImeEvent || isKeyboardEnterKey) {
        if (isSoftImeEvent) {
            verifyPasswordAndUnlock();
            return true;
        }
        return false;
    };

    private final View.OnKeyListener mKeyListener = (v, keyCode, keyEvent) -> {
        final boolean isKeyboardEnterKey = keyEvent != null
                && KeyEvent.isConfirmKey(keyCode)
                && keyEvent.getAction() == KeyEvent.ACTION_UP;
        if (isKeyboardEnterKey) {
            verifyPasswordAndUnlock();
            return true;
        }
@@ -140,15 +148,16 @@ public class KeyguardPasswordViewController
                | InputType.TYPE_TEXT_VARIATION_PASSWORD);

        mView.onDevicePostureChanged(mPostureController.getDevicePosture());

        mPostureController.addCallback(mPostureCallback);

        // Set selected property on so the view can send accessibility events.
        mPasswordEntry.setSelected(true);
        mPasswordEntry.setOnEditorActionListener(mOnEditorActionListener);
        mPasswordEntry.setOnKeyListener(mKeyListener);
        mPasswordEntry.addTextChangedListener(mTextWatcher);
        // Poke the wakelock any time the text is selected or modified
        mPasswordEntry.setOnClickListener(v -> mKeyguardSecurityCallback.userActivity());

        mSwitchImeButton.setOnClickListener(v -> {
            mKeyguardSecurityCallback.userActivity(); // Leave the screen on a bit longer
            // Do not show auxiliary subtypes in password lock screen.
+10 −4
Original line number Diff line number Diff line
@@ -89,10 +89,7 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (KeyEvent.isConfirmKey(keyCode)) {
            mOkButton.performClick();
            return true;
        } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (keyCode == KeyEvent.KEYCODE_DEL) {
            mDeleteButton.performClick();
            return true;
        }
@@ -109,6 +106,15 @@ public abstract class KeyguardPinBasedInputView extends KeyguardAbsKeyInputView
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        if (KeyEvent.isConfirmKey(keyCode)) {
            mOkButton.performClick();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }

    @Override
    protected int getPromptReasonStringRes(int reason) {
        switch (reason) {
+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ public abstract class KeyguardPinBasedInputViewController<T extends KeyguardPinB
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            return mView.onKeyDown(keyCode, event);
        }
        if (event.getAction() == KeyEvent.ACTION_UP) {
            return mView.onKeyUp(keyCode, event);
        }
        return false;
    };

+20 −7
Original line number Diff line number Diff line
@@ -29,8 +29,10 @@ import com.android.systemui.shade.ShadeController
import com.android.systemui.statusbar.StatusBarState
import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
import javax.inject.Inject
import kotlinx.coroutines.ExperimentalCoroutinesApi

/** Handles key events arriving when the keyguard is showing or device is dozing. */
@ExperimentalCoroutinesApi
@SysUISingleton
class KeyguardKeyEventInteractor
@Inject
@@ -53,9 +55,14 @@ constructor(
        }

        if (event.handleAction()) {
            if (KeyEvent.isConfirmKey(event.keyCode)) {
                if (isDeviceAwake()) {
                    return collapseShadeLockedOrShowPrimaryBouncer()
                }
            }

            when (event.keyCode) {
                KeyEvent.KEYCODE_MENU -> return dispatchMenuKeyEvent()
                KeyEvent.KEYCODE_SPACE -> return dispatchSpaceEvent()
            }
        }
        return false
@@ -91,17 +98,23 @@ constructor(
                (statusBarStateController.state != StatusBarState.SHADE) &&
                statusBarKeyguardViewManager.shouldDismissOnMenuPressed()
        if (shouldUnlockOnMenuPressed) {
            shadeController.animateCollapseShadeForced()
            return true
            return collapseShadeLockedOrShowPrimaryBouncer()
        }
        return false
    }

    private fun dispatchSpaceEvent(): Boolean {
        if (isDeviceAwake() && statusBarStateController.state != StatusBarState.SHADE) {
    private fun collapseShadeLockedOrShowPrimaryBouncer(): Boolean {
        when (statusBarStateController.state) {
            StatusBarState.SHADE -> return false
            StatusBarState.SHADE_LOCKED -> {
                shadeController.animateCollapseShadeForced()
                return true
            }
            StatusBarState.KEYGUARD -> {
                statusBarKeyguardViewManager.showPrimaryBouncer(true)
                return true
            }
        }
        return false
    }

+71 −27
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -46,6 +47,7 @@ import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnit

@ExperimentalCoroutinesApi
@SmallTest
@RunWith(AndroidJUnit4::class)
class KeyguardKeyEventInteractorTest : SysuiTestCase() {
@@ -128,58 +130,62 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() {
    }

    @Test
    fun dispatchKeyEvent_menuActionUp_interactiveKeyguard_collapsesShade() {
    fun dispatchKeyEvent_menuActionUp_awakeKeyguard_showsPrimaryBouncer() {
        powerInteractor.setAwakeForTest()
        whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD)
        whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true)

        val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU)
        assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue()
        verify(shadeController).animateCollapseShadeForced()
        verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_MENU)
    }

    @Test
    fun dispatchKeyEvent_menuActionUp_interactiveShadeLocked_collapsesShade() {
    fun dispatchKeyEvent_menuActionUp_awakeShadeLocked_collapsesShade() {
        powerInteractor.setAwakeForTest()
        whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED)
        whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true)

        // action down: does NOT collapse the shade
        val actionDownMenuKeyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU)
        assertThat(underTest.dispatchKeyEvent(actionDownMenuKeyEvent)).isFalse()
        verify(shadeController, never()).animateCollapseShadeForced()

        // action up: collapses the shade
        val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU)
        assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue()
        verify(shadeController).animateCollapseShadeForced()
        verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_MENU)
    }

    @Test
    fun dispatchKeyEvent_menuActionUp_nonInteractiveKeyguard_neverCollapsesShade() {
    fun dispatchKeyEvent_menuActionUp_asleepKeyguard_neverCollapsesShade() {
        powerInteractor.setAsleepForTest()
        whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD)
        whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true)

        val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU)
        assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isFalse()
        verify(shadeController, never()).animateCollapseShadeForced()
        verifyActionsDoNothing(KeyEvent.KEYCODE_MENU)
    }

    @Test
    fun dispatchKeyEvent_spaceActionUp_interactiveKeyguard_collapsesShade() {
    fun dispatchKeyEvent_spaceActionUp_awakeKeyguard_collapsesShade() {
        powerInteractor.setAwakeForTest()
        whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD)

        // action down: does NOT collapse the shade
        val actionDownMenuKeyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SPACE)
        assertThat(underTest.dispatchKeyEvent(actionDownMenuKeyEvent)).isFalse()
        verify(shadeController, never()).animateCollapseShadeForced()
        verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_SPACE)
    }

        // action up: collapses the shade
        val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE)
        assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue()
        verify(shadeController).animateCollapseShadeForced()
    @Test
    fun dispatchKeyEvent_spaceActionUp_shadeLocked_collapsesShade() {
        powerInteractor.setAwakeForTest()
        whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED)

        verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_SPACE)
    }

    @Test
    fun dispatchKeyEvent_enterActionUp_awakeKeyguard_showsPrimaryBouncer() {
        powerInteractor.setAwakeForTest()
        whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD)

        verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_ENTER)
    }

    @Test
    fun dispatchKeyEvent_enterActionUp_shadeLocked_collapsesShade() {
        powerInteractor.setAwakeForTest()
        whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED)

        verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_ENTER)
    }

    @Test
@@ -249,4 +255,42 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() {
            .isFalse()
        verify(statusBarKeyguardViewManager, never()).interceptMediaKey(any())
    }

    private fun verifyActionUpCollapsesTheShade(keycode: Int) {
        // action down: does NOT collapse the shade
        val actionDownMenuKeyEvent = KeyEvent(KeyEvent.ACTION_DOWN, keycode)
        assertThat(underTest.dispatchKeyEvent(actionDownMenuKeyEvent)).isFalse()
        verify(shadeController, never()).animateCollapseShadeForced()

        // action up: collapses the shade
        val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, keycode)
        assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue()
        verify(shadeController).animateCollapseShadeForced()
    }

    private fun verifyActionUpShowsPrimaryBouncer(keycode: Int) {
        // action down: does NOT collapse the shade
        val actionDownMenuKeyEvent = KeyEvent(KeyEvent.ACTION_DOWN, keycode)
        assertThat(underTest.dispatchKeyEvent(actionDownMenuKeyEvent)).isFalse()
        verify(statusBarKeyguardViewManager, never()).showPrimaryBouncer(any())

        // action up: collapses the shade
        val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, keycode)
        assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue()
        verify(statusBarKeyguardViewManager).showPrimaryBouncer(eq(true))
    }

    private fun verifyActionsDoNothing(keycode: Int) {
        // action down: does nothing
        val actionDownMenuKeyEvent = KeyEvent(KeyEvent.ACTION_DOWN, keycode)
        assertThat(underTest.dispatchKeyEvent(actionDownMenuKeyEvent)).isFalse()
        verify(shadeController, never()).animateCollapseShadeForced()
        verify(statusBarKeyguardViewManager, never()).showPrimaryBouncer(any())

        // action up: doesNothing
        val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, keycode)
        assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isFalse()
        verify(shadeController, never()).animateCollapseShadeForced()
        verify(statusBarKeyguardViewManager, never()).showPrimaryBouncer(any())
    }
}