diff options
5 files changed, 66 insertions, 23 deletions
diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt index 3ccf5e4fbdd0..5fec4cccda6c 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt @@ -53,8 +53,12 @@ open class GhostedViewLaunchAnimatorController( private val ghostedView: View, /** The [InteractionJankMonitor.CujType] associated to this animation. */ - private val cujType: Int? = null + private val cujType: Int? = null, + private var interactionJankMonitor: InteractionJankMonitor? = null ) : ActivityLaunchAnimator.Controller { + + constructor(view: View, type: Int) : this(view, type, null) + /** The container to which we will add the ghost view and expanding background. */ override var launchContainer = ghostedView.rootView as ViewGroup private val launchContainerOverlay: ViewGroupOverlay @@ -170,7 +174,7 @@ open class GhostedViewLaunchAnimatorController( val matrix = ghostView?.animationMatrix ?: Matrix.IDENTITY_MATRIX matrix.getValues(initialGhostViewMatrixValues) - cujType?.let { InteractionJankMonitor.getInstance().begin(ghostedView, it) } + cujType?.let { interactionJankMonitor?.begin(ghostedView, it) } } override fun onLaunchAnimationProgress( @@ -251,7 +255,7 @@ open class GhostedViewLaunchAnimatorController( return } - cujType?.let { InteractionJankMonitor.getInstance().end(it) } + cujType?.let { interactionJankMonitor?.end(it) } backgroundDrawable?.wrapped?.alpha = startBackgroundAlpha diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java index fb7ab60c50ba..fbc9ba605000 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/KeyguardViewMediator.java @@ -821,6 +821,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, private final KeyguardStateController mKeyguardStateController; private final Lazy<KeyguardUnlockAnimationController> mKeyguardUnlockAnimationControllerLazy; + private final InteractionJankMonitor mInteractionJankMonitor; private boolean mWallpaperSupportsAmbientMode; /** @@ -846,7 +847,8 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, KeyguardStateController keyguardStateController, Lazy<KeyguardUnlockAnimationController> keyguardUnlockAnimationControllerLazy, UnlockedScreenOffAnimationController unlockedScreenOffAnimationController, - Lazy<NotificationShadeDepthController> notificationShadeDepthController) { + Lazy<NotificationShadeDepthController> notificationShadeDepthController, + InteractionJankMonitor interactionJankMonitor) { super(context); mFalsingCollector = falsingCollector; mLockPatternUtils = lockPatternUtils; @@ -883,6 +885,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, mKeyguardStateController = keyguardStateController; mKeyguardUnlockAnimationControllerLazy = keyguardUnlockAnimationControllerLazy; mUnlockedScreenOffAnimationController = unlockedScreenOffAnimationController; + mInteractionJankMonitor = interactionJankMonitor; } public void userActivity() { @@ -2246,8 +2249,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, onKeyguardExitFinished(); mKeyguardViewControllerLazy.get().hide(0 /* startTime */, 0 /* fadeoutDuration */); - InteractionJankMonitor.getInstance() - .end(CUJ_LOCKSCREEN_UNLOCK_ANIMATION); + mInteractionJankMonitor.end(CUJ_LOCKSCREEN_UNLOCK_ANIMATION); } @Override @@ -2256,7 +2258,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, } }; try { - InteractionJankMonitor.getInstance().begin( + mInteractionJankMonitor.begin( createInteractionJankMonitorConf("RunRemoteAnimation")); runner.onAnimationStart(WindowManager.TRANSIT_KEYGUARD_GOING_AWAY, apps, wallpapers, nonApps, callback); @@ -2272,14 +2274,14 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, mSurfaceBehindRemoteAnimationFinishedCallback = finishedCallback; mSurfaceBehindRemoteAnimationRunning = true; - InteractionJankMonitor.getInstance().begin( + mInteractionJankMonitor.begin( createInteractionJankMonitorConf("DismissPanel")); // Pass the surface and metadata to the unlock animation controller. mKeyguardUnlockAnimationControllerLazy.get().notifyStartKeyguardExitAnimation( apps[0], startTime, mSurfaceBehindRemoteAnimationRequested); } else { - InteractionJankMonitor.getInstance().begin( + mInteractionJankMonitor.begin( createInteractionJankMonitorConf("RemoteAnimationDisabled")); mKeyguardViewControllerLazy.get().hide(startTime, fadeoutDuration); @@ -2289,7 +2291,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, // supported, so it's always null. mContext.getMainExecutor().execute(() -> { if (finishedCallback == null) { - InteractionJankMonitor.getInstance().end(CUJ_LOCKSCREEN_UNLOCK_ANIMATION); + mInteractionJankMonitor.end(CUJ_LOCKSCREEN_UNLOCK_ANIMATION); return; } @@ -2317,8 +2319,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, } catch (RemoteException e) { Slog.e(TAG, "RemoteException"); } finally { - InteractionJankMonitor.getInstance() - .end(CUJ_LOCKSCREEN_UNLOCK_ANIMATION); + mInteractionJankMonitor.end(CUJ_LOCKSCREEN_UNLOCK_ANIMATION); } } @@ -2329,8 +2330,7 @@ public class KeyguardViewMediator extends CoreStartable implements Dumpable, } catch (RemoteException e) { Slog.e(TAG, "RemoteException"); } finally { - InteractionJankMonitor.getInstance() - .cancel(CUJ_LOCKSCREEN_UNLOCK_ANIMATION); + mInteractionJankMonitor.cancel(CUJ_LOCKSCREEN_UNLOCK_ANIMATION); } } }); diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java index cae9feeb62eb..8d23e9f6a12b 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java +++ b/packages/SystemUI/src/com/android/systemui/keyguard/dagger/KeyguardModule.java @@ -22,6 +22,7 @@ import android.content.Context; import android.content.pm.PackageManager; import android.os.PowerManager; +import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.KeyguardDisplayManager; import com.android.keyguard.KeyguardUpdateMonitor; @@ -97,7 +98,8 @@ public class KeyguardModule { KeyguardStateController keyguardStateController, Lazy<KeyguardUnlockAnimationController> keyguardUnlockAnimationController, UnlockedScreenOffAnimationController unlockedScreenOffAnimationController, - Lazy<NotificationShadeDepthController> notificationShadeDepthController) { + Lazy<NotificationShadeDepthController> notificationShadeDepthController, + InteractionJankMonitor interactionJankMonitor) { return new KeyguardViewMediator( context, falsingCollector, @@ -120,7 +122,8 @@ public class KeyguardModule { keyguardStateController, keyguardUnlockAnimationController, unlockedScreenOffAnimationController, - notificationShadeDepthController + notificationShadeDepthController, + interactionJankMonitor ); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/animation/GhostedViewLaunchAnimatorControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/animation/GhostedViewLaunchAnimatorControllerTest.kt index 58e0cb259bb2..3696ec540baf 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/animation/GhostedViewLaunchAnimatorControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/animation/GhostedViewLaunchAnimatorControllerTest.kt @@ -16,22 +16,53 @@ package com.android.systemui.animation +import android.graphics.drawable.Drawable import android.testing.AndroidTestingRunner import android.testing.TestableLooper -import android.widget.LinearLayout +import android.view.View +import android.view.ViewGroup +import android.view.ViewParent import androidx.test.filters.SmallTest +import com.android.internal.jank.InteractionJankMonitor import com.android.systemui.SysuiTestCase +import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mockito.ArgumentMatchers.any +import org.mockito.ArgumentMatchers.anyInt +import org.mockito.Mock +import org.mockito.Mockito.`when` as whenever +import org.mockito.MockitoAnnotations @SmallTest @RunWith(AndroidTestingRunner::class) @TestableLooper.RunWithLooper class GhostedViewLaunchAnimatorControllerTest : SysuiTestCase() { + @Mock lateinit var interactionJankMonitor: InteractionJankMonitor + @Mock lateinit var view: View + @Mock lateinit var rootView: ViewGroup + @Mock lateinit var viewParent: ViewParent + @Mock lateinit var drawable: Drawable + lateinit var controller: GhostedViewLaunchAnimatorController + + @Before + fun setup() { + MockitoAnnotations.initMocks(this) + whenever(view.rootView).thenReturn(rootView) + whenever(view.background).thenReturn(drawable) + whenever(view.height).thenReturn(0) + whenever(view.width).thenReturn(0) + whenever(view.parent).thenReturn(viewParent) + whenever(view.visibility).thenReturn(View.VISIBLE) + whenever(view.invalidate()).then { /* NO-OP */ } + whenever(view.getLocationOnScreen(any())).then { /* NO-OP */ } + whenever(interactionJankMonitor.begin(any(), anyInt())).thenReturn(true) + whenever(interactionJankMonitor.end(anyInt())).thenReturn(true) + controller = GhostedViewLaunchAnimatorController(view, 0, interactionJankMonitor) + } + @Test fun animatingOrphanViewDoesNotCrash() { - val ghostedView = LinearLayout(mContext) - val controller = GhostedViewLaunchAnimatorController(ghostedView) val state = LaunchAnimator.State(top = 0, bottom = 0, left = 0, right = 0) controller.onIntentStarted(willAnimate = true) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java index 6d8645e44fb0..b774daf157c7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/KeyguardViewMediatorTest.java @@ -41,6 +41,7 @@ import android.testing.TestableLooper; import androidx.test.filters.SmallTest; +import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.policy.IKeyguardDrawnCallback; import com.android.internal.widget.LockPatternUtils; import com.android.keyguard.KeyguardDisplayManager; @@ -64,9 +65,6 @@ import com.android.systemui.util.DeviceConfigProxyFake; import com.android.systemui.util.concurrency.FakeExecutor; import com.android.systemui.util.time.FakeSystemClock; -import java.util.Optional; -import java.util.function.Function; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -75,6 +73,9 @@ import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import java.util.Optional; +import java.util.function.Function; + @RunWith(AndroidTestingRunner.class) @TestableLooper.RunWithLooper @SmallTest @@ -103,6 +104,7 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { private @Mock KeyguardUnlockAnimationController mKeyguardUnlockAnimationController; private @Mock UnlockedScreenOffAnimationController mUnlockedScreenOffAnimationController; private @Mock IKeyguardDrawnCallback mKeyguardDrawnCallback; + private @Mock InteractionJankMonitor mInteractionJankMonitor; private DeviceConfigProxy mDeviceConfig = new DeviceConfigProxyFake(); private FakeExecutor mUiBgExecutor = new FakeExecutor(new FakeSystemClock()); @@ -121,6 +123,8 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { .thenReturn(mUnfoldAnimationOptional); when(mUnfoldAnimationOptional.isPresent()).thenReturn(true); when(mUnfoldAnimationOptional.get()).thenReturn(mUnfoldAnimation); + when(mInteractionJankMonitor.begin(any(), anyInt())).thenReturn(true); + when(mInteractionJankMonitor.end(anyInt())).thenReturn(true); mViewMediator = new KeyguardViewMediator( mContext, @@ -144,7 +148,8 @@ public class KeyguardViewMediatorTest extends SysuiTestCase { mKeyguardStateController, () -> mKeyguardUnlockAnimationController, mUnlockedScreenOffAnimationController, - () -> mNotificationShadeDepthController); + () -> mNotificationShadeDepthController, + mInteractionJankMonitor); mViewMediator.start(); } |