From a952ca89b6b0dec7451b5c926d5a332dc3f8f031 Mon Sep 17 00:00:00 2001 From: Beverly Date: Wed, 7 Sep 2022 17:49:12 +0000 Subject: [PATCH] Add null-check for lockscreenSmartspace There's no guarantee in unlockToLauncherWithInWindowAnimations, that lockscreenSmartspace isn't null. Let's protect against this. Fixes: 234858774 Test: atest KeyguardUnlockAnimationControllerTest Change-Id: Ib9f973d189e3935b019f5295ca0a87a56a09b27c --- .../KeyguardUnlockAnimationController.kt | 13 +++++++------ .../KeyguardUnlockAnimationControllerTest.kt | 18 ++++++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardUnlockAnimationController.kt b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardUnlockAnimationController.kt index c944e509c5f13..bd75ab2adb549 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardUnlockAnimationController.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardUnlockAnimationController.kt @@ -282,7 +282,8 @@ class KeyguardUnlockAnimationController @Inject constructor( * window like any other app. This can be true while [willUnlockWithSmartspaceTransition] is * false, if the smartspace is not available or was not ready in time. */ - private var willUnlockWithInWindowLauncherAnimations: Boolean = false + @VisibleForTesting + var willUnlockWithInWindowLauncherAnimations: Boolean = false /** * Whether we decided in [prepareForInWindowLauncherAnimations] that we are able to and want to @@ -484,8 +485,8 @@ class KeyguardUnlockAnimationController @Inject constructor( // surface behind the keyguard to finish unlocking. if (keyguardStateController.isFlingingToDismissKeyguard) { playCannedUnlockAnimation() - } else if (keyguardStateController.isDismissingFromSwipe - && willUnlockWithInWindowLauncherAnimations) { + } else if (keyguardStateController.isDismissingFromSwipe && + willUnlockWithInWindowLauncherAnimations) { // If we're swiping to unlock to the Launcher, and can play in-window animations, // make the launcher surface fully visible and play the in-window unlock animation // on the launcher icons. System UI will remain locked, using the swipe-to-unlock @@ -574,7 +575,7 @@ class KeyguardUnlockAnimationController @Inject constructor( // Now that the Launcher surface (with its smartspace positioned identically to ours) is // visible, hide our smartspace. - lockscreenSmartspace!!.visibility = View.INVISIBLE + lockscreenSmartspace?.visibility = View.INVISIBLE // As soon as the shade has animated out of the way, finish the keyguard exit animation. The // in-window animations in the Launcher window will end on their own. @@ -727,8 +728,8 @@ class KeyguardUnlockAnimationController @Inject constructor( // If we're dismissing via swipe to the Launcher, we'll play in-window scale animations, so // don't also scale the window. - if (keyguardStateController.isDismissingFromSwipe - && willUnlockWithInWindowLauncherAnimations) { + if (keyguardStateController.isDismissingFromSwipe && + willUnlockWithInWindowLauncherAnimations) { scaleFactor = 1f } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardUnlockAnimationControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardUnlockAnimationControllerTest.kt index a4d223853b128..eecbee56d203d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardUnlockAnimationControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardUnlockAnimationControllerTest.kt @@ -27,11 +27,11 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentCaptor.forClass import org.mockito.Mock -import org.mockito.Mockito.`when` import org.mockito.Mockito.mock import org.mockito.Mockito.times import org.mockito.Mockito.verify import org.mockito.Mockito.verifyNoMoreInteractions +import org.mockito.Mockito.`when` import org.mockito.MockitoAnnotations @RunWith(AndroidTestingRunner::class) @@ -218,4 +218,18 @@ class KeyguardUnlockAnimationControllerTest : SysuiTestCase() { assertFalse(keyguardUnlockAnimationController.canPerformInWindowLauncherAnimations()) assertFalse(keyguardUnlockAnimationController.isPlayingCannedUnlockAnimation()) } -} \ No newline at end of file + + @Test + fun playCannedUnlockAnimation_nullSmartspaceView_doesNotThrowExecption() { + keyguardUnlockAnimationController.lockscreenSmartspace = null + keyguardUnlockAnimationController.willUnlockWithInWindowLauncherAnimations = true + + keyguardUnlockAnimationController.notifyStartSurfaceBehindRemoteAnimation( + remoteAnimationTarget, + 0 /* startTime */, + false /* requestedShowSurfaceBehindKeyguard */ + ) + + assertTrue(keyguardUnlockAnimationController.isPlayingCannedUnlockAnimation()) + } +}