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

Commit 8533764c authored by Johannes Gallmann's avatar Johannes Gallmann Committed by Android Build Coastguard Worker
Browse files

Fix wrong Choreographer used for setting vsyncId in cross-activity predictive back

The constructor of CrossActivityBackAnimation is not called from the wmshell.main thread. Therefore we should not set the Choreographer from the constructor.

Bug: 343039961
Flag: com.android.window.flags.predictive_back_system_anims
Test: Manual, i.e. logging Choreographer instances and veryfying that they're accessed from wmshell.main thread. Also verified in perfetto that traces look smooth now.
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:21b9fd55f7b50bc40a6fe9b5b6c6cd88d24b4346)
Merged-In: Iead236279ea0f46acde23f16bb230ff324f453f3
Change-Id: Iead236279ea0f46acde23f16bb230ff324f453f3
parent cda995f6
Loading
Loading
Loading
Loading
+5 −4
Original line number Original line Diff line number Diff line
@@ -61,8 +61,7 @@ abstract class CrossActivityBackAnimation(
    private val context: Context,
    private val context: Context,
    private val background: BackAnimationBackground,
    private val background: BackAnimationBackground,
    private val rootTaskDisplayAreaOrganizer: RootTaskDisplayAreaOrganizer,
    private val rootTaskDisplayAreaOrganizer: RootTaskDisplayAreaOrganizer,
    protected val transaction: SurfaceControl.Transaction,
    protected val transaction: SurfaceControl.Transaction
    private val choreographer: Choreographer
) : ShellBackAnimation() {
) : ShellBackAnimation() {


    protected val startClosingRect = RectF()
    protected val startClosingRect = RectF()
@@ -269,7 +268,9 @@ abstract class CrossActivityBackAnimation(
            .setSpring(postCommitFlingSpring)
            .setSpring(postCommitFlingSpring)
        flingAnimation.start()
        flingAnimation.start()
        // do an animation-frame immediately to prevent idle frame
        // do an animation-frame immediately to prevent idle frame
        flingAnimation.doAnimationFrame(choreographer.lastFrameTimeNanos / TimeUtils.NANOS_PER_MS)
        flingAnimation.doAnimationFrame(
            Choreographer.getInstance().lastFrameTimeNanos / TimeUtils.NANOS_PER_MS
        )


        val valueAnimator =
        val valueAnimator =
            ValueAnimator.ofFloat(1f, 0f).setDuration(getPostCommitAnimationDuration())
            ValueAnimator.ofFloat(1f, 0f).setDuration(getPostCommitAnimationDuration())
@@ -362,7 +363,7 @@ abstract class CrossActivityBackAnimation(
    }
    }


    protected fun applyTransaction() {
    protected fun applyTransaction() {
        transaction.setFrameTimelineVsync(choreographer.vsyncId)
        transaction.setFrameTimelineVsync(Choreographer.getInstance().vsyncId)
        transaction.apply()
        transaction.apply()
    }
    }


+1 −7
Original line number Original line Diff line number Diff line
@@ -19,7 +19,6 @@ import android.content.Context
import android.graphics.Rect
import android.graphics.Rect
import android.graphics.RectF
import android.graphics.RectF
import android.util.MathUtils
import android.util.MathUtils
import android.view.Choreographer
import android.view.SurfaceControl
import android.view.SurfaceControl
import android.view.animation.Animation
import android.view.animation.Animation
import android.view.animation.Transformation
import android.view.animation.Transformation
@@ -31,27 +30,23 @@ import com.android.internal.policy.TransitionAnimation
import com.android.internal.protolog.common.ProtoLog
import com.android.internal.protolog.common.ProtoLog
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.protolog.ShellProtoLogGroup
import com.android.wm.shell.protolog.ShellProtoLogGroup
import com.android.wm.shell.shared.annotations.ShellMainThread
import javax.inject.Inject
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.max
import kotlin.math.min
import kotlin.math.min


/** Class that handles customized predictive cross activity back animations. */
/** Class that handles customized predictive cross activity back animations. */
@ShellMainThread
class CustomCrossActivityBackAnimation(
class CustomCrossActivityBackAnimation(
    context: Context,
    context: Context,
    background: BackAnimationBackground,
    background: BackAnimationBackground,
    rootTaskDisplayAreaOrganizer: RootTaskDisplayAreaOrganizer,
    rootTaskDisplayAreaOrganizer: RootTaskDisplayAreaOrganizer,
    transaction: SurfaceControl.Transaction,
    transaction: SurfaceControl.Transaction,
    choreographer: Choreographer,
    private val customAnimationLoader: CustomAnimationLoader
    private val customAnimationLoader: CustomAnimationLoader
) :
) :
    CrossActivityBackAnimation(
    CrossActivityBackAnimation(
        context,
        context,
        background,
        background,
        rootTaskDisplayAreaOrganizer,
        rootTaskDisplayAreaOrganizer,
        transaction,
        transaction
        choreographer
    ) {
    ) {


    private var enterAnimation: Animation? = null
    private var enterAnimation: Animation? = null
@@ -70,7 +65,6 @@ class CustomCrossActivityBackAnimation(
        background,
        background,
        rootTaskDisplayAreaOrganizer,
        rootTaskDisplayAreaOrganizer,
        SurfaceControl.Transaction(),
        SurfaceControl.Transaction(),
        Choreographer.getInstance(),
        CustomAnimationLoader(
        CustomAnimationLoader(
            TransitionAnimation(context, false /* debug */, "CustomCrossActivityBackAnimation")
            TransitionAnimation(context, false /* debug */, "CustomCrossActivityBackAnimation")
        )
        )
+1 −5
Original line number Original line Diff line number Diff line
@@ -16,18 +16,15 @@
package com.android.wm.shell.back
package com.android.wm.shell.back


import android.content.Context
import android.content.Context
import android.view.Choreographer
import android.view.SurfaceControl
import android.view.SurfaceControl
import android.window.BackEvent
import android.window.BackEvent
import com.android.wm.shell.R
import com.android.wm.shell.R
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.animation.Interpolators
import com.android.wm.shell.animation.Interpolators
import com.android.wm.shell.shared.annotations.ShellMainThread
import javax.inject.Inject
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.max


/** Class that defines cross-activity animation. */
/** Class that defines cross-activity animation. */
@ShellMainThread
class DefaultCrossActivityBackAnimation
class DefaultCrossActivityBackAnimation
@Inject
@Inject
constructor(
constructor(
@@ -39,8 +36,7 @@ constructor(
        context,
        context,
        background,
        background,
        rootTaskDisplayAreaOrganizer,
        rootTaskDisplayAreaOrganizer,
        SurfaceControl.Transaction(),
        SurfaceControl.Transaction()
        Choreographer.getInstance()
    ) {
    ) {


    private val postCommitInterpolator = Interpolators.EMPHASIZED
    private val postCommitInterpolator = Interpolators.EMPHASIZED
+2 −5
Original line number Original line Diff line number Diff line
@@ -25,7 +25,6 @@ import android.graphics.Rect
import android.os.RemoteException
import android.os.RemoteException
import android.testing.AndroidTestingRunner
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.testing.TestableLooper
import android.view.Choreographer
import android.view.RemoteAnimationTarget
import android.view.RemoteAnimationTarget
import android.view.SurfaceControl
import android.view.SurfaceControl
import android.view.SurfaceControl.Transaction
import android.view.SurfaceControl.Transaction
@@ -37,8 +36,6 @@ import androidx.test.filters.SmallTest
import com.android.internal.policy.TransitionAnimation
import com.android.internal.policy.TransitionAnimation
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.RootTaskDisplayAreaOrganizer
import com.android.wm.shell.ShellTestCase
import com.android.wm.shell.ShellTestCase
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertEquals
import org.junit.Assert
import org.junit.Assert
import org.junit.Before
import org.junit.Before
@@ -50,12 +47,13 @@ import org.mockito.ArgumentMatchers.anyFloat
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.eq
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mock
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.never
import org.mockito.Mockito.times
import org.mockito.Mockito.times
import org.mockito.kotlin.spy
import org.mockito.kotlin.spy
import org.mockito.kotlin.verify
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.mockito.kotlin.whenever
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit


@SmallTest
@SmallTest
@TestableLooper.RunWithLooper
@TestableLooper.RunWithLooper
@@ -82,7 +80,6 @@ class CustomCrossActivityBackAnimationTest : ShellTestCase() {
                backAnimationBackground,
                backAnimationBackground,
                rootTaskDisplayAreaOrganizer,
                rootTaskDisplayAreaOrganizer,
                transaction,
                transaction,
                mock(Choreographer::class.java),
                customAnimationLoader
                customAnimationLoader
            )
            )