Loading packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt +7 −21 Original line number Diff line number Diff line Loading @@ -29,10 +29,8 @@ 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 Loading @@ -57,11 +55,7 @@ constructor( if (event.handleAction()) { when (event.keyCode) { KeyEvent.KEYCODE_MENU -> return dispatchMenuKeyEvent() KeyEvent.KEYCODE_SPACE, KeyEvent.KEYCODE_ENTER -> if (isDeviceAwake()) { return collapseShadeLockedOrShowPrimaryBouncer() } KeyEvent.KEYCODE_SPACE -> return dispatchSpaceEvent() } } return false Loading Loading @@ -97,25 +91,17 @@ constructor( (statusBarStateController.state != StatusBarState.SHADE) && statusBarKeyguardViewManager.shouldDismissOnMenuPressed() if (shouldUnlockOnMenuPressed) { return collapseShadeLockedOrShowPrimaryBouncer() shadeController.animateCollapseShadeForced() return true } return false } private fun collapseShadeLockedOrShowPrimaryBouncer(): Boolean { when (statusBarStateController.state) { StatusBarState.SHADE -> return false StatusBarState.SHADE_LOCKED -> { private fun dispatchSpaceEvent(): Boolean { if (isDeviceAwake() && statusBarStateController.state != StatusBarState.SHADE) { shadeController.animateCollapseShadeForced() return true } StatusBarState.KEYGUARD -> { if (!statusBarKeyguardViewManager.primaryBouncerIsShowing()) { statusBarKeyguardViewManager.showPrimaryBouncer(true) return true } } } return false } Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt +27 −82 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ 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 Loading @@ -47,7 +46,6 @@ import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.junit.MockitoJUnit @ExperimentalCoroutinesApi @SmallTest @RunWith(AndroidJUnit4::class) class KeyguardKeyEventInteractorTest : SysuiTestCase() { Loading Loading @@ -130,73 +128,58 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() { } @Test fun dispatchKeyEvent_menuActionUp_awakeKeyguard_showsPrimaryBouncer() { fun dispatchKeyEvent_menuActionUp_interactiveKeyguard_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true) verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_MENU) val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU) assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue() verify(shadeController).animateCollapseShadeForced() } @Test fun dispatchKeyEvent_menuActionUp_awakeShadeLocked_collapsesShade() { fun dispatchKeyEvent_menuActionUp_interactiveShadeLocked_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED) whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true) verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_MENU) // 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() } @Test fun dispatchKeyEvent_menuActionUp_asleepKeyguard_neverCollapsesShade() { fun dispatchKeyEvent_menuActionUp_nonInteractiveKeyguard_neverCollapsesShade() { powerInteractor.setAsleepForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true) verifyActionsDoNothing(KeyEvent.KEYCODE_MENU) } @Test fun dispatchKeyEvent_spaceActionUp_awakeKeyguard_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) whenever(statusBarKeyguardViewManager.primaryBouncerIsShowing()).thenReturn(false) verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_SPACE) } @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(statusBarKeyguardViewManager.primaryBouncerIsShowing()).thenReturn(false) whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_ENTER) val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU) assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isFalse() verify(shadeController, never()).animateCollapseShadeForced() } @Test fun dispatchKeyEvent_enterActionUp_awakeKeyguard_primaryBouncerAlreadyShowing() { fun dispatchKeyEvent_spaceActionUp_interactiveKeyguard_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarKeyguardViewManager.primaryBouncerIsShowing()).thenReturn(true) whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) verifyActionsDoNothing(KeyEvent.KEYCODE_ENTER) } @Test fun dispatchKeyEvent_enterActionUp_shadeLocked_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED) // 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() verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_ENTER) // action up: collapses the shade val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE) assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue() verify(shadeController).animateCollapseShadeForced() } @Test Loading Loading @@ -266,42 +249,4 @@ 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()) } } Loading
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt +7 −21 Original line number Diff line number Diff line Loading @@ -29,10 +29,8 @@ 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 Loading @@ -57,11 +55,7 @@ constructor( if (event.handleAction()) { when (event.keyCode) { KeyEvent.KEYCODE_MENU -> return dispatchMenuKeyEvent() KeyEvent.KEYCODE_SPACE, KeyEvent.KEYCODE_ENTER -> if (isDeviceAwake()) { return collapseShadeLockedOrShowPrimaryBouncer() } KeyEvent.KEYCODE_SPACE -> return dispatchSpaceEvent() } } return false Loading Loading @@ -97,25 +91,17 @@ constructor( (statusBarStateController.state != StatusBarState.SHADE) && statusBarKeyguardViewManager.shouldDismissOnMenuPressed() if (shouldUnlockOnMenuPressed) { return collapseShadeLockedOrShowPrimaryBouncer() shadeController.animateCollapseShadeForced() return true } return false } private fun collapseShadeLockedOrShowPrimaryBouncer(): Boolean { when (statusBarStateController.state) { StatusBarState.SHADE -> return false StatusBarState.SHADE_LOCKED -> { private fun dispatchSpaceEvent(): Boolean { if (isDeviceAwake() && statusBarStateController.state != StatusBarState.SHADE) { shadeController.animateCollapseShadeForced() return true } StatusBarState.KEYGUARD -> { if (!statusBarKeyguardViewManager.primaryBouncerIsShowing()) { statusBarKeyguardViewManager.showPrimaryBouncer(true) return true } } } return false } Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt +27 −82 Original line number Diff line number Diff line Loading @@ -35,7 +35,6 @@ 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 Loading @@ -47,7 +46,6 @@ import org.mockito.Mockito.never import org.mockito.Mockito.verify import org.mockito.junit.MockitoJUnit @ExperimentalCoroutinesApi @SmallTest @RunWith(AndroidJUnit4::class) class KeyguardKeyEventInteractorTest : SysuiTestCase() { Loading Loading @@ -130,73 +128,58 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() { } @Test fun dispatchKeyEvent_menuActionUp_awakeKeyguard_showsPrimaryBouncer() { fun dispatchKeyEvent_menuActionUp_interactiveKeyguard_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true) verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_MENU) val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU) assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue() verify(shadeController).animateCollapseShadeForced() } @Test fun dispatchKeyEvent_menuActionUp_awakeShadeLocked_collapsesShade() { fun dispatchKeyEvent_menuActionUp_interactiveShadeLocked_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED) whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true) verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_MENU) // 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() } @Test fun dispatchKeyEvent_menuActionUp_asleepKeyguard_neverCollapsesShade() { fun dispatchKeyEvent_menuActionUp_nonInteractiveKeyguard_neverCollapsesShade() { powerInteractor.setAsleepForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) whenever(statusBarKeyguardViewManager.shouldDismissOnMenuPressed()).thenReturn(true) verifyActionsDoNothing(KeyEvent.KEYCODE_MENU) } @Test fun dispatchKeyEvent_spaceActionUp_awakeKeyguard_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) whenever(statusBarKeyguardViewManager.primaryBouncerIsShowing()).thenReturn(false) verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_SPACE) } @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(statusBarKeyguardViewManager.primaryBouncerIsShowing()).thenReturn(false) whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_ENTER) val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU) assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isFalse() verify(shadeController, never()).animateCollapseShadeForced() } @Test fun dispatchKeyEvent_enterActionUp_awakeKeyguard_primaryBouncerAlreadyShowing() { fun dispatchKeyEvent_spaceActionUp_interactiveKeyguard_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarKeyguardViewManager.primaryBouncerIsShowing()).thenReturn(true) whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) verifyActionsDoNothing(KeyEvent.KEYCODE_ENTER) } @Test fun dispatchKeyEvent_enterActionUp_shadeLocked_collapsesShade() { powerInteractor.setAwakeForTest() whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED) // 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() verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_ENTER) // action up: collapses the shade val actionUpMenuKeyEvent = KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SPACE) assertThat(underTest.dispatchKeyEvent(actionUpMenuKeyEvent)).isTrue() verify(shadeController).animateCollapseShadeForced() } @Test Loading Loading @@ -266,42 +249,4 @@ 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()) } }