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

Commit 2fc80ac0 authored by Josh Tsuji's avatar Josh Tsuji Committed by Automerger Merge Worker
Browse files

Merge "Override alpha to 0f if we're no longer interactive." into tm-qpr-dev...

Merge "Override alpha to 0f if we're no longer interactive." into tm-qpr-dev am: f62bbd6f am: 64353780

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20805798



Change-Id: Ib2b10369fdb0bc0f639100c7cd92aaa4950c183d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 2e145ac5 64353780
Loading
Loading
Loading
Loading
+12 −5
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Context
import android.graphics.Matrix
import android.graphics.Matrix
import android.graphics.Rect
import android.graphics.Rect
import android.os.Handler
import android.os.Handler
import android.os.PowerManager
import android.os.RemoteException
import android.os.RemoteException
import android.util.Log
import android.util.Log
import android.view.RemoteAnimationTarget
import android.view.RemoteAnimationTarget
@@ -145,7 +146,8 @@ class KeyguardUnlockAnimationController @Inject constructor(
    private val featureFlags: FeatureFlags,
    private val featureFlags: FeatureFlags,
    private val biometricUnlockControllerLazy: Lazy<BiometricUnlockController>,
    private val biometricUnlockControllerLazy: Lazy<BiometricUnlockController>,
    private val statusBarStateController: SysuiStatusBarStateController,
    private val statusBarStateController: SysuiStatusBarStateController,
    private val notificationShadeWindowController: NotificationShadeWindowController
    private val notificationShadeWindowController: NotificationShadeWindowController,
    private val powerManager: PowerManager
) : KeyguardStateController.Callback, ISysuiUnlockAnimationController.Stub() {
) : KeyguardStateController.Callback, ISysuiUnlockAnimationController.Stub() {


    interface KeyguardUnlockAnimationListener {
    interface KeyguardUnlockAnimationListener {
@@ -779,10 +781,15 @@ class KeyguardUnlockAnimationController @Inject constructor(
                    surfaceHeight * SURFACE_BEHIND_SCALE_PIVOT_Y
                    surfaceHeight * SURFACE_BEHIND_SCALE_PIVOT_Y
            )
            )



            val animationAlpha = when {
                // If we're snapping the keyguard back, immediately begin fading it out.
                // If we're snapping the keyguard back, immediately begin fading it out.
            val animationAlpha =
                keyguardStateController.isSnappingKeyguardBackAfterSwipe -> amount
                    if (keyguardStateController.isSnappingKeyguardBackAfterSwipe) amount
                // If the screen has turned back off, the unlock animation is going to be cancelled,
                    else surfaceBehindAlpha
                // so set the surface alpha to 0f so it's no longer visible.
                !powerManager.isInteractive -> 0f
                else -> surfaceBehindAlpha
            }


            // SyncRtSurfaceTransactionApplier cannot apply transaction when the target view is
            // SyncRtSurfaceTransactionApplier cannot apply transaction when the target view is
            // unable to draw
            // unable to draw
+65 −8
Original line number Original line Diff line number Diff line
@@ -4,6 +4,7 @@ import android.app.ActivityManager
import android.app.WindowConfiguration
import android.app.WindowConfiguration
import android.graphics.Point
import android.graphics.Point
import android.graphics.Rect
import android.graphics.Rect
import android.os.PowerManager
import android.testing.AndroidTestingRunner
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper.RunWithLooper
import android.testing.TestableLooper.RunWithLooper
import android.view.RemoteAnimationTarget
import android.view.RemoteAnimationTarget
@@ -19,15 +20,16 @@ import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.SysuiStatusBarStateController
import com.android.systemui.statusbar.phone.BiometricUnlockController
import com.android.systemui.statusbar.phone.BiometricUnlockController
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.util.mockito.whenever
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertEquals
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertTrue
import junit.framework.Assert.assertTrue
import org.junit.After
import org.junit.Before
import org.junit.Before
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor.forClass
import org.mockito.ArgumentCaptor.forClass
import org.mockito.Mock
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.Mockito.mock
import org.mockito.Mockito.mock
import org.mockito.Mockito.times
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import org.mockito.Mockito.verify
@@ -56,6 +58,8 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
    private lateinit var statusBarStateController: SysuiStatusBarStateController
    private lateinit var statusBarStateController: SysuiStatusBarStateController
    @Mock
    @Mock
    private lateinit var notificationShadeWindowController: NotificationShadeWindowController
    private lateinit var notificationShadeWindowController: NotificationShadeWindowController
    @Mock
    private lateinit var powerManager: PowerManager


    @Mock
    @Mock
    private lateinit var launcherUnlockAnimationController: ILauncherUnlockAnimationController.Stub
    private lateinit var launcherUnlockAnimationController: ILauncherUnlockAnimationController.Stub
@@ -79,12 +83,13 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
        keyguardUnlockAnimationController = KeyguardUnlockAnimationController(
        keyguardUnlockAnimationController = KeyguardUnlockAnimationController(
            context, keyguardStateController, { keyguardViewMediator }, keyguardViewController,
            context, keyguardStateController, { keyguardViewMediator }, keyguardViewController,
            featureFlags, { biometricUnlockController }, statusBarStateController,
            featureFlags, { biometricUnlockController }, statusBarStateController,
            notificationShadeWindowController
            notificationShadeWindowController, powerManager
        )
        )
        keyguardUnlockAnimationController.setLauncherUnlockController(
        keyguardUnlockAnimationController.setLauncherUnlockController(
            launcherUnlockAnimationController)
            launcherUnlockAnimationController)


        `when`(keyguardViewController.viewRootImpl).thenReturn(mock(ViewRootImpl::class.java))
        whenever(keyguardViewController.viewRootImpl).thenReturn(mock(ViewRootImpl::class.java))
        whenever(powerManager.isInteractive).thenReturn(true)


        // All of these fields are final, so we can't mock them, but are needed so that the surface
        // All of these fields are final, so we can't mock them, but are needed so that the surface
        // appear amount setter doesn't short circuit.
        // appear amount setter doesn't short circuit.
@@ -96,6 +101,12 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
        keyguardUnlockAnimationController.surfaceTransactionApplier = surfaceTransactionApplier
        keyguardUnlockAnimationController.surfaceTransactionApplier = surfaceTransactionApplier
    }
    }


    @After
    fun tearDown() {
        keyguardUnlockAnimationController.surfaceBehindEntryAnimator.cancel()
        keyguardUnlockAnimationController.surfaceBehindAlphaAnimator.cancel()
    }

    /**
    /**
     * If we're wake and unlocking, we are animating from the black/AOD screen to the app/launcher
     * If we're wake and unlocking, we are animating from the black/AOD screen to the app/launcher
     * underneath. The LightRevealScrim will animate circularly from the fingerprint reader,
     * underneath. The LightRevealScrim will animate circularly from the fingerprint reader,
@@ -104,7 +115,7 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
     */
     */
    @Test
    @Test
    fun noSurfaceAnimation_ifWakeAndUnlocking() {
    fun noSurfaceAnimation_ifWakeAndUnlocking() {
        `when`(biometricUnlockController.isWakeAndUnlock).thenReturn(true)
        whenever(biometricUnlockController.isWakeAndUnlock).thenReturn(true)


        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
            remoteAnimationTargets,
            remoteAnimationTargets,
@@ -135,7 +146,7 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
     */
     */
    @Test
    @Test
    fun surfaceAnimation_ifNotWakeAndUnlocking() {
    fun surfaceAnimation_ifNotWakeAndUnlocking() {
        `when`(biometricUnlockController.isWakeAndUnlock).thenReturn(false)
        whenever(biometricUnlockController.isWakeAndUnlock).thenReturn(false)


        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
            remoteAnimationTargets,
            remoteAnimationTargets,
@@ -159,7 +170,7 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
     */
     */
    @Test
    @Test
    fun fadeInSurfaceBehind_ifRequestedShowSurface_butNotFlinging() {
    fun fadeInSurfaceBehind_ifRequestedShowSurface_butNotFlinging() {
        `when`(keyguardStateController.isFlingingToDismissKeyguard).thenReturn(false)
        whenever(keyguardStateController.isFlingingToDismissKeyguard).thenReturn(false)


        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
            remoteAnimationTargets,
            remoteAnimationTargets,
@@ -181,7 +192,7 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
     */
     */
    @Test
    @Test
    fun playCannedUnlockAnimation_ifRequestedShowSurface_andFlinging() {
    fun playCannedUnlockAnimation_ifRequestedShowSurface_andFlinging() {
        `when`(keyguardStateController.isFlingingToDismissKeyguard).thenReturn(true)
        whenever(keyguardStateController.isFlingingToDismissKeyguard).thenReturn(true)


        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
            remoteAnimationTargets,
            remoteAnimationTargets,
@@ -215,7 +226,7 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {


    @Test
    @Test
    fun doNotPlayCannedUnlockAnimation_ifLaunchingApp() {
    fun doNotPlayCannedUnlockAnimation_ifLaunchingApp() {
        `when`(notificationShadeWindowController.isLaunchingActivity).thenReturn(true)
        whenever(notificationShadeWindowController.isLaunchingActivity).thenReturn(true)


        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
            remoteAnimationTargets,
            remoteAnimationTargets,
@@ -275,4 +286,50 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() {
        verify(keyguardViewMediator, times(0)).exitKeyguardAndFinishSurfaceBehindRemoteAnimation(
        verify(keyguardViewMediator, times(0)).exitKeyguardAndFinishSurfaceBehindRemoteAnimation(
                false /* cancelled */)
                false /* cancelled */)
    }
    }

    @Test
    fun surfaceBehindAlphaOverriddenTo0_ifNotInteractive() {
        whenever(powerManager.isInteractive).thenReturn(false)

        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
                remoteAnimationTargets,
                0 /* startTime */,
                false /* requestedShowSurfaceBehindKeyguard */
        )

        keyguardUnlockAnimationController.setSurfaceBehindAppearAmount(1f)

        val captor = forClass(SyncRtSurfaceTransactionApplier.SurfaceParams::class.java)
        verify(surfaceTransactionApplier, times(1)).scheduleApply(captor.capture())

        val params = captor.value

        // We expect that we've set the surface behind to alpha = 0f since we're not interactive.
        assertEquals(params.alpha, 0f)
        assertTrue(params.matrix.isIdentity)

        verifyNoMoreInteractions(surfaceTransactionApplier)
    }

    @Test
    fun surfaceBehindAlphaNotOverriddenTo0_ifInteractive() {
        whenever(powerManager.isInteractive).thenReturn(true)

        keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation(
                remoteAnimationTargets,
                0 /* startTime */,
                false /* requestedShowSurfaceBehindKeyguard */
        )

        keyguardUnlockAnimationController.setSurfaceBehindAppearAmount(1f)

        val captor = forClass(SyncRtSurfaceTransactionApplier.SurfaceParams::class.java)
        verify(surfaceTransactionApplier, times(1)).scheduleApply(captor.capture())

        val params = captor.value
        assertEquals(params.alpha, 1f)
        assertTrue(params.matrix.isIdentity)

        verifyNoMoreInteractions(surfaceTransactionApplier)
    }
}
}