Loading packages/SystemUI/multivalentTests/src/com/android/systemui/haptics/qs/QSLongPressEffectTest.kt +18 −5 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase import com.android.systemui.animation.ActivityTransitionAnimator import com.android.systemui.animation.ActivityTransitionAnimator import com.android.systemui.classifier.falsingManager import com.android.systemui.haptics.fakeVibratorHelper import com.android.systemui.haptics.fakeVibratorHelper import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.testScope import com.android.systemui.log.core.FakeLogBuffer import com.android.systemui.log.core.FakeLogBuffer Loading Loading @@ -68,11 +69,13 @@ class QSLongPressEffectTest : SysuiTestCase() { vibratorHelper.primitiveDurations[VibrationEffect.Composition.PRIMITIVE_SPIN] = spinDuration vibratorHelper.primitiveDurations[VibrationEffect.Composition.PRIMITIVE_SPIN] = spinDuration whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(true) whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(true) kosmos.falsingManager.setFalseLongTap(false) longPressEffect = longPressEffect = QSLongPressEffect( QSLongPressEffect( vibratorHelper, vibratorHelper, kosmos.keyguardStateController, kosmos.keyguardStateController, kosmos.falsingManager, FakeLogBuffer.Factory.create(), FakeLogBuffer.Factory.create(), ) ) longPressEffect.callback = callback longPressEffect.callback = callback Loading Loading @@ -180,11 +183,7 @@ class QSLongPressEffectTest : SysuiTestCase() { // THEN the expected texture is played // THEN the expected texture is played val reverseHaptics = val reverseHaptics = LongPressHapticBuilder.createReversedEffect( LongPressHapticBuilder.createReversedEffect(progress, lowTickDuration, effectDuration) progress, lowTickDuration, effectDuration, ) assertThat(reverseHaptics).isNotNull() assertThat(reverseHaptics).isNotNull() assertThat(vibratorHelper.hasVibratedWithEffects(reverseHaptics!!)).isTrue() assertThat(vibratorHelper.hasVibratedWithEffects(reverseHaptics!!)).isTrue() } } Loading Loading @@ -223,6 +222,20 @@ class QSLongPressEffectTest : SysuiTestCase() { verify(callback, times(1)).onResetProperties() verify(callback, times(1)).onResetProperties() } } @Test fun onAnimationComplete_isFalseLongClick_effectEndsInIdleWithReset() = testWhileInState(QSLongPressEffect.State.RUNNING_FORWARD) { // GIVEN that the long-click is false kosmos.falsingManager.setFalseLongTap(true) // GIVEN that the animation completes longPressEffect.handleAnimationComplete() // THEN the long-press effect ends in the idle state and the properties are reset assertThat(longPressEffect.state).isEqualTo(QSLongPressEffect.State.IDLE) verify(callback, times(1)).onResetProperties() } @Test @Test fun onAnimationComplete_whenRunningBackwardsFromUp_endsWithFinishedReversingAndClick() = fun onAnimationComplete_whenRunningBackwardsFromUp_endsWithFinishedReversingAndClick() = testWhileInState(QSLongPressEffect.State.RUNNING_BACKWARDS_FROM_UP) { testWhileInState(QSLongPressEffect.State.RUNNING_BACKWARDS_FROM_UP) { Loading packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt +22 −8 Original line number Original line Diff line number Diff line Loading @@ -29,6 +29,7 @@ import com.android.systemui.animation.Expandable import com.android.systemui.log.LogBuffer import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.LogLevel import com.android.systemui.log.core.LogLevel import com.android.systemui.log.dagger.QSLog import com.android.systemui.log.dagger.QSLog import com.android.systemui.plugins.FalsingManager import com.android.systemui.plugins.qs.QSTile import com.android.systemui.plugins.qs.QSTile import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.statusbar.policy.KeyguardStateController Loading @@ -50,6 +51,7 @@ class QSLongPressEffect constructor( constructor( private val vibratorHelper: VibratorHelper?, private val vibratorHelper: VibratorHelper?, private val keyguardStateController: KeyguardStateController, private val keyguardStateController: KeyguardStateController, private val falsingManager: FalsingManager, @QSLog private val logBuffer: LogBuffer, @QSLog private val logBuffer: LogBuffer, ) { ) { Loading @@ -72,7 +74,7 @@ constructor( private val durations = private val durations = vibratorHelper?.getPrimitiveDurations( vibratorHelper?.getPrimitiveDurations( VibrationEffect.Composition.PRIMITIVE_LOW_TICK, VibrationEffect.Composition.PRIMITIVE_LOW_TICK, VibrationEffect.Composition.PRIMITIVE_SPIN VibrationEffect.Composition.PRIMITIVE_SPIN, ) ) private var longPressHint: VibrationEffect? = null private var longPressHint: VibrationEffect? = null Loading Loading @@ -152,15 +154,27 @@ constructor( logEvent(qsTile?.tileSpec, state, "animation completed") logEvent(qsTile?.tileSpec, state, "animation completed") when (state) { when (state) { State.RUNNING_FORWARD -> { State.RUNNING_FORWARD -> { val wasFalseLongTap = falsingManager.isFalseLongTap(FalsingManager.LOW_PENALTY) if (wasFalseLongTap) { callback?.onResetProperties() setState(State.IDLE) logEvent(qsTile?.tileSpec, state, "false long click. No action triggered") } else if (keyguardStateController.isUnlocked) { vibrate(snapEffect) vibrate(snapEffect) if (keyguardStateController.isUnlocked) { setState(State.LONG_CLICKED) setState(State.LONG_CLICKED) qsTile?.longClick(expandable) logEvent(qsTile?.tileSpec, state, "long click action triggered") } else { } else { vibrate(snapEffect) callback?.onResetProperties() callback?.onResetProperties() setState(State.IDLE) setState(State.IDLE) } logEvent(qsTile?.tileSpec, state, "long click action triggered") qsTile?.longClick(expandable) qsTile?.longClick(expandable) logEvent( qsTile?.tileSpec, state, "properties reset and long click action triggered", ) } } } State.RUNNING_BACKWARDS_FROM_UP -> { State.RUNNING_BACKWARDS_FROM_UP -> { callback?.onEffectFinishedReversing() callback?.onEffectFinishedReversing() Loading Loading @@ -236,7 +250,7 @@ constructor( LongPressHapticBuilder.createLongPressHint( LongPressHapticBuilder.createLongPressHint( durations?.get(0) ?: LongPressHapticBuilder.INVALID_DURATION, durations?.get(0) ?: LongPressHapticBuilder.INVALID_DURATION, durations?.get(1) ?: LongPressHapticBuilder.INVALID_DURATION, durations?.get(1) ?: LongPressHapticBuilder.INVALID_DURATION, effectDuration effectDuration, ) ) setState(State.IDLE) setState(State.IDLE) return true return true Loading Loading @@ -265,7 +279,7 @@ constructor( } } override fun dialogTransitionController( override fun dialogTransitionController( cuj: DialogCuj?, cuj: DialogCuj? ): DialogTransitionAnimator.Controller? = ): DialogTransitionAnimator.Controller? = DialogTransitionAnimator.Controller.fromView(view, cuj) DialogTransitionAnimator.Controller.fromView(view, cuj) } } Loading Loading @@ -298,7 +312,7 @@ constructor( str2 = event str2 = event str3 = state.name str3 = state.name }, }, { "[long-press effect on $str1 tile] $str2 on state: $str3" } { "[long-press effect on $str1 tile] $str2 on state: $str3" }, ) ) } } Loading packages/SystemUI/tests/utils/src/com/android/systemui/haptics/qs/QSLongPressEffectKosmos.kt +2 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.haptics.qs package com.android.systemui.haptics.qs import com.android.systemui.classifier.fakeFalsingManager import com.android.systemui.haptics.vibratorHelper import com.android.systemui.haptics.vibratorHelper import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.Kosmos import com.android.systemui.log.core.FakeLogBuffer import com.android.systemui.log.core.FakeLogBuffer Loading @@ -26,6 +27,7 @@ val Kosmos.qsLongPressEffect by QSLongPressEffect( QSLongPressEffect( vibratorHelper, vibratorHelper, keyguardStateController, keyguardStateController, fakeFalsingManager, FakeLogBuffer.Factory.create(), FakeLogBuffer.Factory.create(), ) ) } } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/haptics/qs/QSLongPressEffectTest.kt +18 −5 Original line number Original line Diff line number Diff line Loading @@ -23,6 +23,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase import com.android.systemui.animation.ActivityTransitionAnimator import com.android.systemui.animation.ActivityTransitionAnimator import com.android.systemui.classifier.falsingManager import com.android.systemui.haptics.fakeVibratorHelper import com.android.systemui.haptics.fakeVibratorHelper import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.testScope import com.android.systemui.log.core.FakeLogBuffer import com.android.systemui.log.core.FakeLogBuffer Loading Loading @@ -68,11 +69,13 @@ class QSLongPressEffectTest : SysuiTestCase() { vibratorHelper.primitiveDurations[VibrationEffect.Composition.PRIMITIVE_SPIN] = spinDuration vibratorHelper.primitiveDurations[VibrationEffect.Composition.PRIMITIVE_SPIN] = spinDuration whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(true) whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(true) kosmos.falsingManager.setFalseLongTap(false) longPressEffect = longPressEffect = QSLongPressEffect( QSLongPressEffect( vibratorHelper, vibratorHelper, kosmos.keyguardStateController, kosmos.keyguardStateController, kosmos.falsingManager, FakeLogBuffer.Factory.create(), FakeLogBuffer.Factory.create(), ) ) longPressEffect.callback = callback longPressEffect.callback = callback Loading Loading @@ -180,11 +183,7 @@ class QSLongPressEffectTest : SysuiTestCase() { // THEN the expected texture is played // THEN the expected texture is played val reverseHaptics = val reverseHaptics = LongPressHapticBuilder.createReversedEffect( LongPressHapticBuilder.createReversedEffect(progress, lowTickDuration, effectDuration) progress, lowTickDuration, effectDuration, ) assertThat(reverseHaptics).isNotNull() assertThat(reverseHaptics).isNotNull() assertThat(vibratorHelper.hasVibratedWithEffects(reverseHaptics!!)).isTrue() assertThat(vibratorHelper.hasVibratedWithEffects(reverseHaptics!!)).isTrue() } } Loading Loading @@ -223,6 +222,20 @@ class QSLongPressEffectTest : SysuiTestCase() { verify(callback, times(1)).onResetProperties() verify(callback, times(1)).onResetProperties() } } @Test fun onAnimationComplete_isFalseLongClick_effectEndsInIdleWithReset() = testWhileInState(QSLongPressEffect.State.RUNNING_FORWARD) { // GIVEN that the long-click is false kosmos.falsingManager.setFalseLongTap(true) // GIVEN that the animation completes longPressEffect.handleAnimationComplete() // THEN the long-press effect ends in the idle state and the properties are reset assertThat(longPressEffect.state).isEqualTo(QSLongPressEffect.State.IDLE) verify(callback, times(1)).onResetProperties() } @Test @Test fun onAnimationComplete_whenRunningBackwardsFromUp_endsWithFinishedReversingAndClick() = fun onAnimationComplete_whenRunningBackwardsFromUp_endsWithFinishedReversingAndClick() = testWhileInState(QSLongPressEffect.State.RUNNING_BACKWARDS_FROM_UP) { testWhileInState(QSLongPressEffect.State.RUNNING_BACKWARDS_FROM_UP) { Loading
packages/SystemUI/src/com/android/systemui/haptics/qs/QSLongPressEffect.kt +22 −8 Original line number Original line Diff line number Diff line Loading @@ -29,6 +29,7 @@ import com.android.systemui.animation.Expandable import com.android.systemui.log.LogBuffer import com.android.systemui.log.LogBuffer import com.android.systemui.log.core.LogLevel import com.android.systemui.log.core.LogLevel import com.android.systemui.log.dagger.QSLog import com.android.systemui.log.dagger.QSLog import com.android.systemui.plugins.FalsingManager import com.android.systemui.plugins.qs.QSTile import com.android.systemui.plugins.qs.QSTile import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.VibratorHelper import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.statusbar.policy.KeyguardStateController Loading @@ -50,6 +51,7 @@ class QSLongPressEffect constructor( constructor( private val vibratorHelper: VibratorHelper?, private val vibratorHelper: VibratorHelper?, private val keyguardStateController: KeyguardStateController, private val keyguardStateController: KeyguardStateController, private val falsingManager: FalsingManager, @QSLog private val logBuffer: LogBuffer, @QSLog private val logBuffer: LogBuffer, ) { ) { Loading @@ -72,7 +74,7 @@ constructor( private val durations = private val durations = vibratorHelper?.getPrimitiveDurations( vibratorHelper?.getPrimitiveDurations( VibrationEffect.Composition.PRIMITIVE_LOW_TICK, VibrationEffect.Composition.PRIMITIVE_LOW_TICK, VibrationEffect.Composition.PRIMITIVE_SPIN VibrationEffect.Composition.PRIMITIVE_SPIN, ) ) private var longPressHint: VibrationEffect? = null private var longPressHint: VibrationEffect? = null Loading Loading @@ -152,15 +154,27 @@ constructor( logEvent(qsTile?.tileSpec, state, "animation completed") logEvent(qsTile?.tileSpec, state, "animation completed") when (state) { when (state) { State.RUNNING_FORWARD -> { State.RUNNING_FORWARD -> { val wasFalseLongTap = falsingManager.isFalseLongTap(FalsingManager.LOW_PENALTY) if (wasFalseLongTap) { callback?.onResetProperties() setState(State.IDLE) logEvent(qsTile?.tileSpec, state, "false long click. No action triggered") } else if (keyguardStateController.isUnlocked) { vibrate(snapEffect) vibrate(snapEffect) if (keyguardStateController.isUnlocked) { setState(State.LONG_CLICKED) setState(State.LONG_CLICKED) qsTile?.longClick(expandable) logEvent(qsTile?.tileSpec, state, "long click action triggered") } else { } else { vibrate(snapEffect) callback?.onResetProperties() callback?.onResetProperties() setState(State.IDLE) setState(State.IDLE) } logEvent(qsTile?.tileSpec, state, "long click action triggered") qsTile?.longClick(expandable) qsTile?.longClick(expandable) logEvent( qsTile?.tileSpec, state, "properties reset and long click action triggered", ) } } } State.RUNNING_BACKWARDS_FROM_UP -> { State.RUNNING_BACKWARDS_FROM_UP -> { callback?.onEffectFinishedReversing() callback?.onEffectFinishedReversing() Loading Loading @@ -236,7 +250,7 @@ constructor( LongPressHapticBuilder.createLongPressHint( LongPressHapticBuilder.createLongPressHint( durations?.get(0) ?: LongPressHapticBuilder.INVALID_DURATION, durations?.get(0) ?: LongPressHapticBuilder.INVALID_DURATION, durations?.get(1) ?: LongPressHapticBuilder.INVALID_DURATION, durations?.get(1) ?: LongPressHapticBuilder.INVALID_DURATION, effectDuration effectDuration, ) ) setState(State.IDLE) setState(State.IDLE) return true return true Loading Loading @@ -265,7 +279,7 @@ constructor( } } override fun dialogTransitionController( override fun dialogTransitionController( cuj: DialogCuj?, cuj: DialogCuj? ): DialogTransitionAnimator.Controller? = ): DialogTransitionAnimator.Controller? = DialogTransitionAnimator.Controller.fromView(view, cuj) DialogTransitionAnimator.Controller.fromView(view, cuj) } } Loading Loading @@ -298,7 +312,7 @@ constructor( str2 = event str2 = event str3 = state.name str3 = state.name }, }, { "[long-press effect on $str1 tile] $str2 on state: $str3" } { "[long-press effect on $str1 tile] $str2 on state: $str3" }, ) ) } } Loading
packages/SystemUI/tests/utils/src/com/android/systemui/haptics/qs/QSLongPressEffectKosmos.kt +2 −0 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.haptics.qs package com.android.systemui.haptics.qs import com.android.systemui.classifier.fakeFalsingManager import com.android.systemui.haptics.vibratorHelper import com.android.systemui.haptics.vibratorHelper import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.Kosmos import com.android.systemui.log.core.FakeLogBuffer import com.android.systemui.log.core.FakeLogBuffer Loading @@ -26,6 +27,7 @@ val Kosmos.qsLongPressEffect by QSLongPressEffect( QSLongPressEffect( vibratorHelper, vibratorHelper, keyguardStateController, keyguardStateController, fakeFalsingManager, FakeLogBuffer.Factory.create(), FakeLogBuffer.Factory.create(), ) ) } }