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

Commit 9b9999a0 authored by Chandru S's avatar Chandru S
Browse files

Fix race condition between app launch animation and shade expansion

Whenever an app is launched from shade, ActivityTransitionAnimator#onTransitionAnimationStart sets blursDisabledForAppLaunch to true
This is reset to false when ActivityTransitionAnimator#onTransitionAnimationEnd is invoked.

When ActivityTransitionAnimator#onTransitionAnimationEnd is invoked before shadeExpansion becomes 0, a non-zero blur radius is computed and applied, this causes a one frame flicker when we launch an app from shade on an unlocked device.

Flag: com.android.systemui.bouncer_ui_revamp
Test: verified manually
Bug: 396054791
Change-Id: I35e33fc0200e9cd176fc9c622e826dd8765d2e2e
parent 81abb3be
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -110,6 +110,10 @@ constructor(
    private var prevTimestamp: Long = -1
    private var prevShadeDirection = 0
    private var prevShadeVelocity = 0f
    // tracks whether app launch transition is in progress. This involves two independent factors
    // that control blur, shade expansion and app launch animation from outside sysui.
    // They can complete out of order, this flag will be reset by the animation that finishes later.
    private var appLaunchTransitionIsInProgress = false

    // Only for dumpsys
    private var lastAppliedBlur = 0
@@ -158,6 +162,18 @@ constructor(
            if (field == value) {
                return
            }
            // Set this to true now, this will be reset when the next shade expansion finishes or
            // when the app launch finishes, whichever happens later.
            if (value) {
                appLaunchTransitionIsInProgress = true
            } else {
                // App was launching and now it has finished launching
                if (shadeExpansion == 0.0f) {
                    // this means shade expansion finished before app launch was done.
                    // reset the flag here
                    appLaunchTransitionIsInProgress = false
                }
            }
            field = value
            scheduleUpdate()

@@ -172,6 +188,12 @@ constructor(
            shadeAnimation.animateTo(0)
            shadeAnimation.finishIfRunning()
        }
        @Deprecated(
            message =
                "This might get reset to false before shade expansion is fully done, " +
                    "consider using areBlursDisabledForAppLaunch"
        )
        get() = field

    private var zoomOutCalculatedFromShadeRadius: Float = 0.0f

@@ -183,6 +205,11 @@ constructor(
            scheduleUpdate()
        }

    private val areBlursDisabledForAppLaunch: Boolean
        get() =
            blursDisabledForAppLaunch ||
                (Flags.bouncerUiRevamp() && appLaunchTransitionIsInProgress)

    /** Force stop blur effect when necessary. */
    private var scrimsVisible: Boolean = false
        set(value) {
@@ -221,7 +248,7 @@ constructor(
        combinedBlur = max(combinedBlur, blurUtils.blurRadiusOfRatio(transitionToFullShadeProgress))
        var shadeRadius = max(combinedBlur, wakeAndUnlockBlurRadius)

        if (blursDisabledForAppLaunch || blursDisabledForUnlock) {
        if (areBlursDisabledForAppLaunch || blursDisabledForUnlock) {
            shadeRadius = 0f
        }

@@ -259,7 +286,7 @@ constructor(
    private val shouldBlurBeOpaque: Boolean
        get() =
            if (Flags.notificationShadeBlur()) false
            else scrimsVisible && !blursDisabledForAppLaunch
            else scrimsVisible && !areBlursDisabledForAppLaunch

    /** Callback that updates the window blur value and is called only once per frame. */
    @VisibleForTesting
@@ -442,6 +469,13 @@ constructor(
        val shadeDirection = sign(diff).toInt()
        val shadeVelocity =
            MathUtils.constrain(VELOCITY_SCALE * diff / deltaTime, MIN_VELOCITY, MAX_VELOCITY)
        if (expansion == 0.0f && appLaunchTransitionIsInProgress && !blursDisabledForAppLaunch) {
            // Shade expansion finished but the app launch is already done, then this should mark
            // the transition as done.
            Log.d(TAG, "appLaunchTransitionIsInProgress is now false from shade expansion event")
            appLaunchTransitionIsInProgress = false
        }

        updateShadeAnimationBlur(expansion, tracking, shadeVelocity, shadeDirection)

        prevShadeDirection = shadeDirection
@@ -553,6 +587,7 @@ constructor(
            it.println("brightnessMirrorRadius: ${brightnessMirrorSpring.radius}")
            it.println("wakeAndUnlockBlur: $wakeAndUnlockBlurRadius")
            it.println("blursDisabledForAppLaunch: $blursDisabledForAppLaunch")
            it.println("appLaunchTransitionIsInProgress: $appLaunchTransitionIsInProgress")
            it.println("qsPanelExpansion: $qsPanelExpansion")
            it.println("transitionToFullShadeProgress: $transitionToFullShadeProgress")
            it.println("lastAppliedBlur: $lastAppliedBlur")