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

Commit 2e145921 authored by Luca Zuccarini's avatar Luca Zuccarini
Browse files

Remove flicker from Communal widget launches.

Note that this is a sub-optimal implementation, as it relies on
scheduling the scene change with the animation duration instea of just
doing it in the moment when the animation ends. However, due to a bug
with STL, this flicker is currently inevitable if we rely on the end of
animation callback.

Bug: 333717642
Flag: com.android.systemui.communal_hub
Test: atest LegacyActivityStarterInternalImplTest CommunalTransitionAnimatorController
Change-Id: I2c664879f371afddc116a2d0baa5bc30b1222233
parent 93d3f9a9
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.truth.Truth
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
@@ -34,6 +36,7 @@ import org.junit.runner.RunWith
import org.mockito.kotlin.mock
import org.mockito.kotlin.verify

@ExperimentalCoroutinesApi
@SmallTest
@RunWith(AndroidJUnit4::class)
class CommunalTransitionAnimatorControllerTest : SysuiTestCase() {
@@ -66,7 +69,7 @@ class CommunalTransitionAnimatorControllerTest : SysuiTestCase() {
    }

    @Test
    fun animationCancelled_launchingWidgetStateIsClearedAndSceneIsNotChanged() {
    fun animationCancelled_launchingWidgetStateIsCleared() {
        with(kosmos) {
            testScope.runTest {
                val launching by collectLastValue(communalSceneInteractor.isLaunchingWidget)
@@ -81,9 +84,12 @@ class CommunalTransitionAnimatorControllerTest : SysuiTestCase() {
                assertTrue(launching!!)
                verify(controller).onIntentStarted(willAnimate = true)

                underTest.onTransitionAnimationStart(isExpandingFullyAbove = true)
                assertTrue(launching!!)
                verify(controller).onTransitionAnimationStart(isExpandingFullyAbove = true)

                underTest.onTransitionAnimationCancelled(newKeyguardOccludedState = true)
                assertFalse(launching!!)
                Truth.assertThat(scene).isEqualTo(CommunalScenes.Communal)
                verify(controller).onTransitionAnimationCancelled(newKeyguardOccludedState = true)
            }
        }
@@ -105,6 +111,12 @@ class CommunalTransitionAnimatorControllerTest : SysuiTestCase() {
                assertTrue(launching!!)
                verify(controller).onIntentStarted(willAnimate = true)

                underTest.onTransitionAnimationStart(isExpandingFullyAbove = true)
                assertTrue(launching!!)
                verify(controller).onTransitionAnimationStart(isExpandingFullyAbove = true)

                testScope.advanceTimeBy(ActivityTransitionAnimator.TIMINGS.totalDuration)

                underTest.onTransitionAnimationEnd(isExpandingFullyAbove = true)
                assertFalse(launching!!)
                Truth.assertThat(scene).isEqualTo(CommunalScenes.Blank)
+9 −1
Original line number Diff line number Diff line
@@ -37,13 +37,21 @@ class CommunalTransitionAnimatorController(
        delegate.onIntentStarted(willAnimate)
    }

    override fun onTransitionAnimationStart(isExpandingFullyAbove: Boolean) {
        delegate.onTransitionAnimationStart(isExpandingFullyAbove)
        // TODO(b/330672236): move this to onTransitionAnimationEnd() without the delay.
        communalSceneInteractor.snapToScene(
            CommunalScenes.Blank,
            ActivityTransitionAnimator.TIMINGS.totalDuration
        )
    }

    override fun onTransitionAnimationCancelled(newKeyguardOccludedState: Boolean?) {
        communalSceneInteractor.setIsLaunchingWidget(false)
        delegate.onTransitionAnimationCancelled(newKeyguardOccludedState)
    }

    override fun onTransitionAnimationEnd(isExpandingFullyAbove: Boolean) {
        communalSceneInteractor.snapToScene(CommunalScenes.Blank)
        communalSceneInteractor.setIsLaunchingWidget(false)
        delegate.onTransitionAnimationEnd(isExpandingFullyAbove)
    }
+0 −7
Original line number Diff line number Diff line
@@ -40,7 +40,6 @@ import com.android.systemui.assist.AssistManager
import com.android.systemui.camera.CameraIntents
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.DisplayId
import com.android.systemui.dagger.qualifiers.Main
@@ -562,12 +561,6 @@ constructor(

                override fun onTransitionAnimationStart(isExpandingFullyAbove: Boolean) {
                    super.onTransitionAnimationStart(isExpandingFullyAbove)
                    if (communalSettingsInteractor.isCommunalFlagEnabled()) {
                        communalSceneInteractor.snapToScene(
                            CommunalScenes.Blank,
                            ActivityTransitionAnimator.TIMINGS.totalDuration
                        )
                    }
                    // Double check that the keyguard is still showing and not going
                    // away, but if so set the keyguard occluded. Typically, WM will let
                    // KeyguardViewMediator know directly, but we're overriding that to