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

Commit 28efafc2 authored by Eric Sum's avatar Eric Sum
Browse files

Add ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU latency.

This measures the delay from when the user requests to enter
desktop mode by pressing the desktop mode button in an app
handle's menu until the animation to enter desktop mode
begins.

This period is consumed by launching the home activity and
creating app headers for each desktop window, both of which
have been expensive in the past.

Flag: EXEMPT metric change
Bug: 390555563
Test: Put tangorpro in HSUM mode:
      `adb shell cmd user set-system-user-mode-emulation headless`
      Run `statsd_testdrive 306` and ensure that latency metric is
      reported. This was done with
      `enable_desktop_wallpaper_activity_for_system_user` enabled and
      disabled. The latency was close to 1 second with that flag
      disabled and ~100 milliseconds with that flag enabled. This is
      expected.
Change-Id: Ic8a1131063d16f9080bc338298cb3b497206a2f8
parent e38d077b
Loading
Loading
Loading
Loading
+24 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPOR
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_CHECK_CREDENTIAL;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_CHECK_CREDENTIAL_UNLOCKED;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_EXPAND_PANEL;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_FACE_WAKE_AND_UNLOCK;
import static com.android.internal.util.FrameworkStatsLog.UIACTION_LATENCY_REPORTED__ACTION__ACTION_FINGERPRINT_WAKE_AND_UNLOCK;
@@ -268,14 +269,27 @@ public class LatencyTracker {
    public static final int ACTION_SHADE_WINDOW_DISPLAY_CHANGE = 29;

    /**
     * Applicable when the user drags a full screen app's handle into the desktop drop zone to enter
     * desktop mode. This measure the time from when the user releases their finger in the drop zone
     * to when the animation for entering desktop mode visually begins. During this period, the
     * home task and app headers for each window are initialized. Both have historically been
     * expensive. See b/381396057 and b/360452034 respectively.
     * Time it takes for the "enter desktop" mode animation to begin when initiated by dragging the
     * app's handle into the desktop drop zone.
     * <p>
     * This measure the time from when the user releases their finger in the drop zone to when the
     * animation for entering desktop mode visually begins. During this period, the home task and
     * app headers for each window are initialized. Both have historically been expensive. See
     * b/381396057 and b/360452034 respectively.
     */
    public static final int ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG = 30;

    /**
     * Time it takes for the "enter desktop" mode animation to begin when initiated via the app
     * handle's menu.
     * <p>
     * This measures the time from when the menu option is clicked/tapped to when the animation for
     * entering desktop mode visually begins. During this period, the home task and app headers for
     * each window are initialized. Both have historically been expensive. See b/381396057 and
     * b/360452034 respectively.
     */
    public static final int ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU = 31;

    private static final int[] ACTIONS_ALL = {
        ACTION_EXPAND_PANEL,
        ACTION_TOGGLE_RECENTS,
@@ -308,6 +322,7 @@ public class LatencyTracker {
        ACTION_KEYGUARD_FACE_UNLOCK_TO_HOME,
        ACTION_SHADE_WINDOW_DISPLAY_CHANGE,
        ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG,
        ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU,
    };

    /** @hide */
@@ -343,6 +358,7 @@ public class LatencyTracker {
        ACTION_KEYGUARD_FACE_UNLOCK_TO_HOME,
        ACTION_SHADE_WINDOW_DISPLAY_CHANGE,
        ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG,
        ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Action {}
@@ -380,6 +396,7 @@ public class LatencyTracker {
            UIACTION_LATENCY_REPORTED__ACTION__ACTION_KEYGUARD_FACE_UNLOCK_TO_HOME,
            UIACTION_LATENCY_REPORTED__ACTION__ACTION_SHADE_WINDOW_DISPLAY_CHANGE,
            UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG,
            UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU,
    };

    private final Object mLock = new Object();
@@ -582,6 +599,8 @@ public class LatencyTracker {
                return "ACTION_SHADE_WINDOW_DISPLAY_CHANGE";
            case UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG:
                return "ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_DRAG";
            case UIACTION_LATENCY_REPORTED__ACTION__ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU:
                return "ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU";
            default:
                throw new IllegalArgumentException("Invalid action");
        }
+5 −2
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import androidx.annotation.OptIn;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.LatencyTracker;
import com.android.launcher3.icons.IconProvider;
import com.android.window.flags.Flags;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
@@ -1073,8 +1074,10 @@ public abstract class WMShellModule {
    static EnterDesktopTaskTransitionHandler provideEnterDesktopModeTaskTransitionHandler(
            Transitions transitions,
            Optional<DesktopTasksLimiter> desktopTasksLimiter,
            InteractionJankMonitor interactionJankMonitor) {
        return new EnterDesktopTaskTransitionHandler(transitions, interactionJankMonitor);
            InteractionJankMonitor interactionJankMonitor,
            LatencyTracker latencyTracker) {
        return new EnterDesktopTaskTransitionHandler(
                transitions, interactionJankMonitor, latencyTracker);
    }

    @WMSingleton
+15 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.util.LatencyTracker;
import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.windowdecor.OnTaskResizeAnimationListener;
@@ -63,20 +64,25 @@ public class EnterDesktopTaskTransitionHandler implements Transitions.Transition

    private final List<IBinder> mPendingTransitionTokens = new ArrayList<>();
    private final InteractionJankMonitor mInteractionJankMonitor;
    private final LatencyTracker mLatencyTracker;

    private OnTaskResizeAnimationListener mOnTaskResizeAnimationListener;

    public EnterDesktopTaskTransitionHandler(
            Transitions transitions, InteractionJankMonitor interactionJankMonitor) {
        this(transitions, interactionJankMonitor, SurfaceControl.Transaction::new);
            Transitions transitions,
            InteractionJankMonitor interactionJankMonitor,
            LatencyTracker latencyTracker) {
        this(transitions, interactionJankMonitor, latencyTracker, SurfaceControl.Transaction::new);
    }

    public EnterDesktopTaskTransitionHandler(
            Transitions transitions,
            InteractionJankMonitor interactionJankMonitor,
            LatencyTracker latencyTracker,
            Supplier<SurfaceControl.Transaction> supplier) {
        mTransitions = transitions;
        mInteractionJankMonitor = interactionJankMonitor;
        mLatencyTracker = latencyTracker;
        mTransactionSupplier = supplier;
    }

@@ -122,6 +128,13 @@ public class EnterDesktopTaskTransitionHandler implements Transitions.Transition
            }
        }

        if (transitionHandled
                && info.getType()
                        == DesktopModeTransitionTypes
                                .TRANSIT_ENTER_DESKTOP_FROM_APP_HANDLE_MENU_BUTTON) {
            mLatencyTracker.onActionEnd(LatencyTracker.ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU);
        }

        mPendingTransitionTokens.remove(transition);

        return transitionHandled;
+13 −2
Original line number Diff line number Diff line
@@ -92,6 +92,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.jank.Cuj;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.protolog.ProtoLog;
import com.android.internal.util.LatencyTracker;
import com.android.window.flags.Flags;
import com.android.wm.shell.R;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
@@ -260,6 +261,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
    private final DesktopModeCompatPolicy mDesktopModeCompatPolicy;
    private final DesktopTilingDecorViewModel mDesktopTilingDecorViewModel;
    private final MultiDisplayDragMoveIndicatorController mMultiDisplayDragMoveIndicatorController;
    private final LatencyTracker mLatencyTracker;

    public DesktopModeWindowDecorViewModel(
            Context context,
@@ -466,6 +468,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
        mDesktopTilingDecorViewModel = desktopTilingDecorViewModel;
        mDesktopTasksController.setSnapEventHandler(this);
        mMultiDisplayDragMoveIndicatorController = multiDisplayDragMoveIndicatorController;
        mLatencyTracker = LatencyTracker.getInstance(mContext);
        shellInit.addInitCallback(this::onInit, this);
    }

@@ -764,11 +767,19 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        mInteractionJankMonitor.begin(decoration.mTaskSurface, mContext, mMainHandler,
                CUJ_DESKTOP_MODE_ENTER_MODE_APP_HANDLE_MENU);
        mLatencyTracker.onActionStart(LatencyTracker.ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU);
        // App sometimes draws before the insets from WindowDecoration#relayout have
        // been added, so they must be added here
        decoration.addCaptionInset(wct);
        mDesktopTasksController.moveTaskToDefaultDeskAndActivate(taskId, wct, source,
                /* remoteTransition= */ null, /* moveToDesktopCallback */ null);
        if (!mDesktopTasksController.moveTaskToDefaultDeskAndActivate(
                taskId,
                wct,
                source,
                /* remoteTransition= */ null,
                /* moveToDesktopCallback= */ null)) {
            mLatencyTracker.onActionCancel(
                    LatencyTracker.ACTION_DESKTOP_MODE_ENTER_APP_HANDLE_MENU);
        }
        decoration.closeHandleMenu();

        if (source == DesktopModeTransitionSource.APP_HANDLE_MENU_BUTTON) {