Loading packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt +17 −7 Original line number Diff line number Diff line Loading @@ -54,7 +54,11 @@ constructor( if (event.handleAction()) { when (event.keyCode) { KeyEvent.KEYCODE_MENU -> return dispatchMenuKeyEvent() KeyEvent.KEYCODE_SPACE -> return dispatchSpaceEvent() KeyEvent.KEYCODE_SPACE, KeyEvent.KEYCODE_ENTER -> if (isDeviceInteractive()) { return collapseShadeLockedOrShowPrimaryBouncer() } } } return false Loading Loading @@ -90,17 +94,23 @@ constructor( (statusBarStateController.state != StatusBarState.SHADE) && statusBarKeyguardViewManager.shouldDismissOnMenuPressed() if (shouldUnlockOnMenuPressed) { shadeController.animateCollapseShadeForced() return true return collapseShadeLockedOrShowPrimaryBouncer() } return false } private fun dispatchSpaceEvent(): Boolean { if (isDeviceInteractive() && 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 } Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt +68 −26 Original line number Diff line number Diff line Loading @@ -131,14 +131,12 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() { } @Test fun dispatchKeyEvent_menuActionUp_interactiveKeyguard_collapsesShade() { fun dispatchKeyEvent_menuActionUp_interactiveKeyguard_showsPrimaryBouncer() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) 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 Loading @@ -147,42 +145,48 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() { 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_nonInteractiveKeyguard_doNothing() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(asleepWakefulnessMode) 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_interactiveKeyguard_showsPrimaryBouncer() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) 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() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED) verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_SPACE) } @Test fun dispatchKeyEvent_enterActionUp_interactiveKeyguard_showsPrimaryBouncer() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_ENTER) } @Test fun dispatchKeyEvent_enterActionUp_shadeLocked_collapsesShade() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED) verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_ENTER) } @Test Loading Loading @@ -252,4 +256,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()) } } Loading
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractor.kt +17 −7 Original line number Diff line number Diff line Loading @@ -54,7 +54,11 @@ constructor( if (event.handleAction()) { when (event.keyCode) { KeyEvent.KEYCODE_MENU -> return dispatchMenuKeyEvent() KeyEvent.KEYCODE_SPACE -> return dispatchSpaceEvent() KeyEvent.KEYCODE_SPACE, KeyEvent.KEYCODE_ENTER -> if (isDeviceInteractive()) { return collapseShadeLockedOrShowPrimaryBouncer() } } } return false Loading Loading @@ -90,17 +94,23 @@ constructor( (statusBarStateController.state != StatusBarState.SHADE) && statusBarKeyguardViewManager.shouldDismissOnMenuPressed() if (shouldUnlockOnMenuPressed) { shadeController.animateCollapseShadeForced() return true return collapseShadeLockedOrShowPrimaryBouncer() } return false } private fun dispatchSpaceEvent(): Boolean { if (isDeviceInteractive() && 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 } Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardKeyEventInteractorTest.kt +68 −26 Original line number Diff line number Diff line Loading @@ -131,14 +131,12 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() { } @Test fun dispatchKeyEvent_menuActionUp_interactiveKeyguard_collapsesShade() { fun dispatchKeyEvent_menuActionUp_interactiveKeyguard_showsPrimaryBouncer() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) 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 Loading @@ -147,42 +145,48 @@ class KeyguardKeyEventInteractorTest : SysuiTestCase() { 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_nonInteractiveKeyguard_doNothing() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(asleepWakefulnessMode) 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_interactiveKeyguard_showsPrimaryBouncer() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) 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() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED) verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_SPACE) } @Test fun dispatchKeyEvent_enterActionUp_interactiveKeyguard_showsPrimaryBouncer() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) whenever(statusBarStateController.state).thenReturn(StatusBarState.KEYGUARD) verifyActionUpShowsPrimaryBouncer(KeyEvent.KEYCODE_ENTER) } @Test fun dispatchKeyEvent_enterActionUp_shadeLocked_collapsesShade() { keyguardInteractorWithDependencies.repository.setWakefulnessModel(awakeWakefulnessMode) whenever(statusBarStateController.state).thenReturn(StatusBarState.SHADE_LOCKED) verifyActionUpCollapsesTheShade(KeyEvent.KEYCODE_ENTER) } @Test Loading Loading @@ -252,4 +256,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()) } }