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

Commit 4c9e2772 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Android (Google) Code Review
Browse files

Merge "Log.wtf WM timeouts only after 5s" into main

parents 0f38790f 1c815a00
Loading
Loading
Loading
Loading
+45 −16
Original line number Diff line number Diff line
@@ -114,7 +114,13 @@ class ActivityLaunchAnimator(
        private val NAV_FADE_OUT_INTERPOLATOR = PathInterpolator(0.2f, 0f, 1f, 1f)

        /** The time we wait before timing out the remote animation after starting the intent. */
        private const val LAUNCH_TIMEOUT = 1000L
        private const val LAUNCH_TIMEOUT = 1_000L

        /**
         * The time we wait before we Log.wtf because the remote animation was neither started or
         * cancelled by WM.
         */
        private const val LONG_LAUNCH_TIMEOUT = 5_000L

        private fun createPositionXInterpolator(): Interpolator {
            val path =
@@ -247,7 +253,7 @@ class ActivityLaunchAnimator(
        // If we expect an animation, post a timeout to cancel it in case the remote animation is
        // never started.
        if (willAnimate) {
            runnerDelegate.postTimeout()
            runnerDelegate.postTimeouts()

            // Hide the keyguard using the launch animation instead of the default unlock animation.
            if (hideKeyguardWithAnimation) {
@@ -578,21 +584,41 @@ class ActivityLaunchAnimator(
        private var cancelled = false
        private var animation: LaunchAnimator.Animation? = null

        // A timeout to cancel the remote animation if it is not started within X milliseconds after
        // the intent was started.
        //
        // Note that this is important to keep this a Runnable (and not a Kotlin lambda), otherwise
        // it will be automatically converted when posted and we wouldn't be able to remove it after
        // posting it.
        /**
         * A timeout to cancel the launch animation if the remote animation is not started or
         * cancelled within [LAUNCH_TIMEOUT] milliseconds after the intent was started.
         *
         * Note that this is important to keep this a Runnable (and not a Kotlin lambda), otherwise
         * it will be automatically converted when posted and we wouldn't be able to remove it after
         * posting it.
         */
        private var onTimeout = Runnable { onAnimationTimedOut() }

        /**
         * A long timeout to Log.wtf (signaling a bug in WM) when the remote animation wasn't
         * started or cancelled within [LONG_LAUNCH_TIMEOUT] milliseconds after the intent was
         * started.
         */
        private var onLongTimeout = Runnable {
            Log.wtf(
                TAG,
                "The remote animation was neither cancelled or started within $LONG_LAUNCH_TIMEOUT"
            )
        }

        @UiThread
        internal fun postTimeout() {
            timeoutHandler?.postDelayed(onTimeout, LAUNCH_TIMEOUT)
        internal fun postTimeouts() {
            if (timeoutHandler != null) {
                timeoutHandler.postDelayed(onTimeout, LAUNCH_TIMEOUT)
                timeoutHandler.postDelayed(onLongTimeout, LONG_LAUNCH_TIMEOUT)
            }
        }

        private fun removeTimeout() {
            timeoutHandler?.removeCallbacks(onTimeout)
        private fun removeTimeouts() {
            if (timeoutHandler != null) {
                timeoutHandler.removeCallbacks(onTimeout)
                timeoutHandler.removeCallbacks(onLongTimeout)
            }
        }

        @UiThread
@@ -603,7 +629,7 @@ class ActivityLaunchAnimator(
            nonApps: Array<out RemoteAnimationTarget>?,
            callback: IRemoteAnimationFinishedCallback?
        ) {
            removeTimeout()
            removeTimeouts()

            // The animation was started too late and we already notified the controller that it
            // timed out.
@@ -653,7 +679,6 @@ class ActivityLaunchAnimator(
            val window = findRootTaskIfPossible(apps)
            if (window == null) {
                Log.i(TAG, "Aborting the animation as no window is opening")
                removeTimeout()
                iCallback?.invoke()

                if (DEBUG_LAUNCH_ANIMATION) {
@@ -890,11 +915,13 @@ class ActivityLaunchAnimator(
        }

        private fun onAnimationTimedOut() {
            // The remote animation was cancelled by WM, so we already cancelled the launch
            // animation.
            if (cancelled) {
                return
            }

            Log.wtf(TAG, "Remote animation timed out")
            Log.w(TAG, "Remote animation timed out")
            timedOut = true

            if (DEBUG_LAUNCH_ANIMATION) {
@@ -906,13 +933,15 @@ class ActivityLaunchAnimator(

        @UiThread
        override fun onAnimationCancelled() {
            removeTimeouts()

            // The short timeout happened, so we already cancelled the launch animation.
            if (timedOut) {
                return
            }

            Log.i(TAG, "Remote animation was cancelled")
            cancelled = true
            removeTimeout()

            animation?.cancel()