From 66e5325d6fed28028aa6e7822ac364b5e7b09269 Mon Sep 17 00:00:00 2001 From: Eric Sum Date: Fri, 14 Mar 2025 17:16:57 -0700 Subject: [PATCH] Add ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE latency (launcher). This measures the delay from when the user closes or minimizes the last open window in desktop mode until the animation to exit desktop mode draws its first frame. Flag: EXEMPT metric change Bug: 390544490 Test: Run `statsd_testdrive 306` and ensure that latency metric is reported. Change-Id: If4923b50feade20ba74560ed7b8d14ea2bb6f71e --- .../launcher3/QuickstepTransitionManager.java | 29 +++++++++++++++---- .../DesktopVisibilityController.kt | 20 +++++++++++-- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java index 548fbefcae..6aa4ba4766 100644 --- a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java +++ b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java @@ -40,6 +40,7 @@ import static com.android.app.animation.Interpolators.DECELERATE_1_5; import static com.android.app.animation.Interpolators.DECELERATE_1_7; import static com.android.app.animation.Interpolators.EXAGGERATED_EASE; import static com.android.app.animation.Interpolators.LINEAR; +import static com.android.internal.util.LatencyTracker.ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE; import static com.android.launcher3.BaseActivity.EVENT_DESTROYED; import static com.android.launcher3.BaseActivity.INVISIBLE_ALL; import static com.android.launcher3.BaseActivity.INVISIBLE_BY_APP_TRANSITIONS; @@ -122,6 +123,7 @@ import androidx.core.graphics.ColorUtils; import com.android.app.animation.Animations; import com.android.internal.jank.Cuj; +import com.android.internal.util.LatencyTracker; import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; import com.android.launcher3.LauncherAnimationRunner.RemoteAnimationFactory; import com.android.launcher3.anim.AnimationSuccessListener; @@ -263,6 +265,7 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener private RemoteTransition mLauncherOpenTransition; private final RemoteAnimationCoordinateTransfer mCoordinateTransfer; + private final LatencyTracker mLatencyTracker; private LauncherBackAnimationController mBackAnimationController; private final AnimatorListenerAdapter mForceInvisibleListener = new AnimatorListenerAdapter() { @@ -317,6 +320,7 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener mOpeningInterpolator = AnimationUtils.loadInterpolator(context, R.interpolator.emphasized_interpolator); mCoordinateTransfer = new RemoteAnimationCoordinateTransfer(mLauncher); + mLatencyTracker = LatencyTracker.getInstance(context); } @Override @@ -1630,14 +1634,20 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener } private void addCujInstrumentation(Animator anim, int cuj) { - anim.addListener(getCujAnimationSuccessListener(cuj)); + anim.addListener(getCujAnimationSuccessListener(cuj, /* cujPreStartCallback= */null)); + } + + private void addCujInstrumentation(Animator anim, int cuj, Runnable cujPreStartCallback) { + anim.addListener(getCujAnimationSuccessListener(cuj, cujPreStartCallback)); } private void addCujInstrumentation(RectFSpringAnim anim, int cuj) { - anim.addAnimatorListener(getCujAnimationSuccessListener(cuj)); + anim.addAnimatorListener( + getCujAnimationSuccessListener(cuj, /* cujPreStartCallback= */null)); } - private AnimationSuccessListener getCujAnimationSuccessListener(int cuj) { + private AnimationSuccessListener getCujAnimationSuccessListener( + int cuj, Runnable cujPreStartCallback) { return new AnimationSuccessListener() { @Override public void onAnimationStart(Animator animation) { @@ -1651,7 +1661,9 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener return; } mHandled = true; - + if (cujPreStartCallback != null) { + cujPreStartCallback.run(); + } InteractionJankMonitorWrapper.begin(mDragLayer, cuj); mDragLayer.post(() -> @@ -1803,8 +1815,13 @@ public class QuickstepTransitionManager implements OnDeviceProfileChangeListener addCujInstrumentation(rectFSpringAnim, Cuj.CUJ_LAUNCHER_APP_CLOSE_TO_HOME); } else { if (isFreeformAnimation(appTargets)) { - addCujInstrumentation(anim, - Cuj.CUJ_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE); + addCujInstrumentation( + anim, + Cuj.CUJ_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE, + /* cujPreStartCallback= */ () -> { + mLatencyTracker.onActionEnd( + ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE); + }); } addCujInstrumentation(anim, playFallBackAnimation ? Cuj.CUJ_LAUNCHER_APP_CLOSE_TO_HOME_FALLBACK diff --git a/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt b/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt index 1ac2d7c13e..6bce2caff8 100644 --- a/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt +++ b/quickstep/src/com/android/launcher3/statehandlers/DesktopVisibilityController.kt @@ -23,6 +23,7 @@ import android.util.SparseArray import android.view.Display.DEFAULT_DISPLAY import android.window.DesktopModeFlags.ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY import androidx.core.util.forEach +import com.android.internal.util.LatencyTracker import com.android.launcher3.LauncherState import com.android.launcher3.dagger.ApplicationContext import com.android.launcher3.dagger.LauncherAppComponent @@ -175,7 +176,7 @@ constructor( private var desktopTaskListener: DesktopTaskListenerImpl? init { - desktopTaskListener = DesktopTaskListenerImpl(this, context, context.displayId) + desktopTaskListener = DesktopTaskListenerImpl(this, context) systemUiProxy.setDesktopTaskListener(desktopTaskListener) lifecycleTracker.addCloseable { @@ -645,9 +646,9 @@ constructor( private class DesktopTaskListenerImpl( controller: DesktopVisibilityController, @ApplicationContext private val context: Context, - private val displayId: Int, ) : Stub() { private val controller = WeakReference(controller) + private val displayId = context.displayId override fun onListenerConnected( displayDeskStates: Array, @@ -710,7 +711,10 @@ constructor( // TODO: b/402496827 - The multi-desks backend needs to be updated to call this API only // once, not between desk switches. - override fun onExitDesktopModeTransitionStarted(transitionDuration: Int) { + override fun onExitDesktopModeTransitionStarted( + transitionDuration: Int, + shouldEndUpAtHome: Boolean, + ) { val controller = controller.get() ?: return MAIN_EXECUTOR.execute { Log.d( @@ -719,6 +723,16 @@ constructor( "duration= " + transitionDuration), ) + // If shouldEndUpAtHome is true, desktop mode is ending from the user + // closing/minimizing the last open window. If it's false, the display is + // probably transitioning to an app's full screen mode instead so this metric + // should not be logged. + if (shouldEndUpAtHome) { + LatencyTracker.getInstance(context) + .onActionStart( + LatencyTracker.ACTION_DESKTOP_MODE_EXIT_MODE_ON_LAST_WINDOW_CLOSE + ) + } if (enableMultipleDesktops(context)) { controller.notifyTaskbarDesktopModeListenersForExit(transitionDuration) } else if (controller.isInDesktopModeDeprecated) {