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

Commit 5712c7cd authored by Aurélien Pomini's avatar Aurélien Pomini Committed by Android (Google) Code Review
Browse files

Merge "Accelerate wallpaper unlock transition" into main

parents 2ab41b20 7c643455
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -188,3 +188,9 @@ flag {
   bug: "305049544"
}

flag {
   name: "fast_unlock_transition"
   namespace: "systemui"
   description: "Faster wallpaper unlock transition"
   bug: "298186160"
}
+64 −16
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import com.android.keyguard.KeyguardViewController
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.Flags.fastUnlockTransition
import com.android.systemui.plugins.BcSmartspaceDataPlugin
import com.android.systemui.shared.recents.utilities.Utilities
import com.android.systemui.shared.system.ActivityManagerWrapper
@@ -98,7 +99,8 @@ const val DISMISS_AMOUNT_EXIT_KEYGUARD_THRESHOLD = 0.3f
 * from a tap on the unlock icon, or from the bouncer. This is not relevant if the lockscreen is
 * swiped away via a touch gesture, or when it's flinging expanded/collapsed after a swipe.
 */
const val UNLOCK_ANIMATION_DURATION_MS = 200L
const val LEGACY_UNLOCK_ANIMATION_DURATION_MS = 200L
const val UNLOCK_ANIMATION_DURATION_MS = 167L

/**
 * How long the in-window launcher icon animation takes. This is used if the launcher is underneath
@@ -112,19 +114,22 @@ const val LAUNCHER_ICONS_ANIMATION_DURATION_MS = 633L
/**
 * How long to wait for the shade to get out of the way before starting the canned unlock animation.
 */
const val CANNED_UNLOCK_START_DELAY = 100L
const val LEGACY_CANNED_UNLOCK_START_DELAY = 100L
const val CANNED_UNLOCK_START_DELAY = 67L

/**
 * Duration for the alpha animation on the surface behind. This plays to fade in the surface during
 * a swipe to unlock (and to fade it back out if the swipe is cancelled).
 */
const val SURFACE_BEHIND_SWIPE_FADE_DURATION_MS = 175L
const val LEGACY_SURFACE_BEHIND_SWIPE_FADE_DURATION_MS = 175L
const val SURFACE_BEHIND_FADE_OUT_DURATION_MS = 83L

/**
 * Start delay for the surface behind animation, used so that the lockscreen can get out of the way
 * before the surface begins appearing.
 */
const val UNLOCK_ANIMATION_SURFACE_BEHIND_START_DELAY_MS = 75L
const val LEGACY_UNLOCK_ANIMATION_SURFACE_BEHIND_START_DELAY_MS = 75L
const val SURFACE_BEHIND_FADE_OUT_START_DELAY_MS = 0L

/**
 * Initiates, controls, and ends the keyguard unlock animation.
@@ -327,7 +332,7 @@ class KeyguardUnlockAnimationController @Inject constructor(

    init {
        with(surfaceBehindAlphaAnimator) {
            duration = SURFACE_BEHIND_SWIPE_FADE_DURATION_MS
            duration = surfaceBehindFadeOutDurationMs()
            interpolator = Interpolators.LINEAR
            addUpdateListener { valueAnimator: ValueAnimator ->
                surfaceBehindAlpha = valueAnimator.animatedValue as Float
@@ -355,8 +360,10 @@ class KeyguardUnlockAnimationController @Inject constructor(
        }

        with(wallpaperCannedUnlockAnimator) {
            duration = LAUNCHER_ICONS_ANIMATION_DURATION_MS
            interpolator = Interpolators.ALPHA_OUT
            duration = if (fastUnlockTransition()) UNLOCK_ANIMATION_DURATION_MS
                    else LAUNCHER_ICONS_ANIMATION_DURATION_MS
            interpolator = if (fastUnlockTransition()) Interpolators.LINEAR
                    else Interpolators.ALPHA_OUT
            addUpdateListener { valueAnimator: ValueAnimator ->
                setWallpaperAppearAmount(valueAnimator.animatedValue as Float)
            }
@@ -370,8 +377,8 @@ class KeyguardUnlockAnimationController @Inject constructor(
        }

        with(surfaceBehindEntryAnimator) {
            duration = UNLOCK_ANIMATION_DURATION_MS
            startDelay = UNLOCK_ANIMATION_SURFACE_BEHIND_START_DELAY_MS
            duration = unlockAnimationDurationMs()
            startDelay = surfaceBehindFadeOutStartDelayMs()
            interpolator = Interpolators.TOUCH_RESPONSE
            addUpdateListener { valueAnimator: ValueAnimator ->
                surfaceBehindAlpha = valueAnimator.animatedValue as Float
@@ -573,7 +580,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
                try {
                    launcherUnlockController?.playUnlockAnimation(
                            true,
                            UNLOCK_ANIMATION_DURATION_MS + CANNED_UNLOCK_START_DELAY,
                            unlockAnimationDurationMs() + cannedUnlockStartDelayMs(),
                            0 /* startDelay */)
                } catch (e: DeadObjectException) {
                    // Hello! If you are here investigating a bug where Launcher is blank (no icons)
@@ -602,12 +609,15 @@ class KeyguardUnlockAnimationController @Inject constructor(
        // Notify if waking from AOD only
        val isWakeAndUnlockNotFromDream = biometricUnlockControllerLazy.get().isWakeAndUnlock &&
            biometricUnlockControllerLazy.get().mode != MODE_WAKE_AND_UNLOCK_FROM_DREAM

        val duration = if (fastUnlockTransition()) UNLOCK_ANIMATION_DURATION_MS
                else LAUNCHER_ICONS_ANIMATION_DURATION_MS
        listeners.forEach {
            it.onUnlockAnimationStarted(
                playingCannedUnlockAnimation /* playingCannedAnimation */,
                isWakeAndUnlockNotFromDream /* isWakeAndUnlockNotFromDream */,
                CANNED_UNLOCK_START_DELAY /* unlockStartDelay */,
                LAUNCHER_ICONS_ANIMATION_DURATION_MS /* unlockAnimationDuration */) }
                cannedUnlockStartDelayMs() /* unlockStartDelay */,
                duration /* unlockAnimationDuration */) }

        // Finish the keyguard remote animation if the dismiss amount has crossed the threshold.
        // Check it here in case there is no more change to the dismiss amount after the last change
@@ -675,7 +685,7 @@ class KeyguardUnlockAnimationController @Inject constructor(
            launcherUnlockController?.playUnlockAnimation(
                    true /* unlocked */,
                    LAUNCHER_ICONS_ANIMATION_DURATION_MS /* duration */,
                    CANNED_UNLOCK_START_DELAY /* startDelay */)
                    cannedUnlockStartDelayMs() /* startDelay */)
        } catch (e: DeadObjectException) {
            // Hello! If you are here investigating a bug where Launcher is blank (no icons)
            // then the below assumption about Launcher's destruction was incorrect. This
@@ -696,9 +706,10 @@ class KeyguardUnlockAnimationController @Inject constructor(
            lockscreenSmartspace?.visibility = View.INVISIBLE
        }

        // As soon as the shade has animated out of the way, start the canned unlock animation,
        // As soon as the shade starts animating out of the way, start the canned unlock animation,
        // which will finish keyguard exit when it completes. The in-window animations in the
        // Launcher window will end on their own.
        if (fastUnlockTransition()) hideKeyguardViewAfterRemoteAnimation()
        handler.postDelayed({
            if (keyguardViewMediator.get().isShowingAndNotOccluded &&
                !keyguardStateController.isKeyguardGoingAway) {
@@ -709,12 +720,12 @@ class KeyguardUnlockAnimationController @Inject constructor(

            if ((wallpaperTargets?.isNotEmpty() == true)) {
                fadeInWallpaper()
                hideKeyguardViewAfterRemoteAnimation()
                if (!fastUnlockTransition()) hideKeyguardViewAfterRemoteAnimation()
            } else {
                keyguardViewMediator.get().exitKeyguardAndFinishSurfaceBehindRemoteAnimation(
                    false /* cancelled */)
            }
        }, CANNED_UNLOCK_START_DELAY)
        }, cannedUnlockStartDelayMs())
    }

    /**
@@ -1130,6 +1141,43 @@ class KeyguardUnlockAnimationController @Inject constructor(
                ?: false
    }

    /**
     * Temporary method for b/298186160
     * TODO (b/298186160) replace references with the constant itself when flag is removed
     */
    private fun cannedUnlockStartDelayMs(): Long {
        return if (fastUnlockTransition()) CANNED_UNLOCK_START_DELAY
                else LEGACY_CANNED_UNLOCK_START_DELAY
    }

    /**
     * Temporary method for b/298186160
     * TODO (b/298186160) replace references with the constant itself when flag is removed
     */
    private fun unlockAnimationDurationMs(): Long {
        return if (fastUnlockTransition()) UNLOCK_ANIMATION_DURATION_MS
                else LEGACY_UNLOCK_ANIMATION_DURATION_MS
    }

    /**
     * Temporary method for b/298186160
     * TODO (b/298186160) replace references with the constant itself when flag is removed
     */
    private fun surfaceBehindFadeOutDurationMs(): Long {
        return if (fastUnlockTransition()) SURFACE_BEHIND_FADE_OUT_DURATION_MS
                else LEGACY_SURFACE_BEHIND_SWIPE_FADE_DURATION_MS
    }

    /**
     * Temporary method for b/298186160
     * TODO (b/298186160) replace references with the constant itself when flag is removed
     */
    private fun surfaceBehindFadeOutStartDelayMs(): Long {
        return if (fastUnlockTransition()) SURFACE_BEHIND_FADE_OUT_START_DELAY_MS
                else LEGACY_UNLOCK_ANIMATION_SURFACE_BEHIND_START_DELAY_MS
    }


    companion object {

        fun isFoldable(context: Context): Boolean {