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

Commit de2fbade authored by Shan Huang's avatar Shan Huang Committed by Android (Google) Code Review
Browse files

Merge "Add Predictive Back CUJs." into main

parents 18e335e2 3b9a072c
Loading
Loading
Loading
Loading
+23 −1
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_IN
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__ONE_HANDED_ENTER_TRANSITION;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__ONE_HANDED_EXIT_TRANSITION;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__PIP_TRANSITION;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__PREDICTIVE_BACK_CROSS_ACTIVITY;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__PREDICTIVE_BACK_CROSS_TASK;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__PREDICTIVE_BACK_HOME;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__RECENTS_SCROLLING;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SCREEN_OFF;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SCREEN_OFF_SHOW_AOD;
@@ -276,7 +279,11 @@ public class InteractionJankMonitor {

    public static final int CUJ_LAUNCHER_UNFOLD_ANIM = 83;

    private static final int LAST_CUJ = CUJ_LAUNCHER_UNFOLD_ANIM;
    public static final int CUJ_PREDICTIVE_BACK_CROSS_ACTIVITY = 84;
    public static final int CUJ_PREDICTIVE_BACK_CROSS_TASK = 85;
    public static final int CUJ_PREDICTIVE_BACK_HOME = 86;

    private static final int LAST_CUJ = CUJ_PREDICTIVE_BACK_HOME;
    private static final int NO_STATSD_LOGGING = -1;

    // Used to convert CujType to InteractionType enum value for statsd logging.
@@ -370,6 +377,12 @@ public class InteractionJankMonitor {
        CUJ_TO_STATSD_INTERACTION_TYPE[CUJ_IME_INSETS_HIDE_ANIMATION] = UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__IME_INSETS_HIDE_ANIMATION;
        CUJ_TO_STATSD_INTERACTION_TYPE[CUJ_SPLIT_SCREEN_DOUBLE_TAP_DIVIDER] = UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLIT_SCREEN_DOUBLE_TAP_DIVIDER;
        CUJ_TO_STATSD_INTERACTION_TYPE[CUJ_LAUNCHER_UNFOLD_ANIM] = UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__LAUNCHER_UNFOLD_ANIM;
        CUJ_TO_STATSD_INTERACTION_TYPE[CUJ_PREDICTIVE_BACK_CROSS_ACTIVITY] =
            UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__PREDICTIVE_BACK_CROSS_ACTIVITY;
        CUJ_TO_STATSD_INTERACTION_TYPE[CUJ_PREDICTIVE_BACK_CROSS_TASK] =
            UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__PREDICTIVE_BACK_CROSS_TASK;
        CUJ_TO_STATSD_INTERACTION_TYPE[CUJ_PREDICTIVE_BACK_HOME] =
            UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__PREDICTIVE_BACK_HOME;
    }

    private static class InstanceHolder {
@@ -473,6 +486,9 @@ public class InteractionJankMonitor {
            CUJ_IME_INSETS_HIDE_ANIMATION,
            CUJ_SPLIT_SCREEN_DOUBLE_TAP_DIVIDER,
            CUJ_LAUNCHER_UNFOLD_ANIM,
            CUJ_PREDICTIVE_BACK_CROSS_ACTIVITY,
            CUJ_PREDICTIVE_BACK_CROSS_TASK,
            CUJ_PREDICTIVE_BACK_HOME,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface CujType {
@@ -1108,6 +1124,12 @@ public class InteractionJankMonitor {
                return "SPLIT_SCREEN_DOUBLE_TAP_DIVIDER";
            case CUJ_LAUNCHER_UNFOLD_ANIM:
                return "LAUNCHER_UNFOLD_ANIM";
            case CUJ_PREDICTIVE_BACK_CROSS_ACTIVITY:
                return "PREDICTIVE_BACK_CROSS_ACTIVITY";
            case CUJ_PREDICTIVE_BACK_CROSS_TASK:
                return "PREDICTIVE_BACK_CROSS_TASK";
            case CUJ_PREDICTIVE_BACK_HOME:
                return "PREDICTIVE_BACK_HOME";
        }
        return "UNKNOWN";
    }
+6 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.wm.shell.back;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_PREDICTIVE_BACK_HOME;
import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW;
import static com.android.wm.shell.sysui.ShellSharedConstants.KEY_EXTRA_SHELL_BACK_ANIMATION;
@@ -70,7 +71,6 @@ import com.android.wm.shell.common.annotations.ShellMainThread;
import com.android.wm.shell.sysui.ShellController;
import com.android.wm.shell.sysui.ShellInit;


import java.util.concurrent.atomic.AtomicBoolean;

/**
@@ -317,7 +317,11 @@ public class BackAnimationController implements RemoteCallable<BackAnimationCont
            executeRemoteCallWithTaskPermission(mController, "setBackToLauncherCallback",
                    (controller) -> controller.registerAnimation(
                            BackNavigationInfo.TYPE_RETURN_TO_HOME,
                            new BackAnimationRunner(callback, runner)));
                            new BackAnimationRunner(
                                    callback,
                                    runner,
                                    controller.mContext,
                                    CUJ_PREDICTIVE_BACK_HOME)));
        }

        @Override
+31 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.back;
import static android.view.WindowManager.TRANSIT_OLD_UNSET;

import android.annotation.NonNull;
import android.content.Context;
import android.os.RemoteException;
import android.util.Log;
import android.view.IRemoteAnimationFinishedCallback;
@@ -27,16 +28,22 @@ import android.view.RemoteAnimationTarget;
import android.window.IBackAnimationRunner;
import android.window.IOnBackInvokedCallback;

import com.android.internal.jank.InteractionJankMonitor;
import com.android.wm.shell.common.InteractionJankMonitorUtils;

/**
 * Used to register the animation callback and runner, it will trigger result if gesture was finish
 * before it received IBackAnimationRunner#onAnimationStart, so the controller could continue
 * trigger the real back behavior.
 */
public class BackAnimationRunner {
    private static final int NO_CUJ = -1;
    private static final String TAG = "ShellBackPreview";

    private final IOnBackInvokedCallback mCallback;
    private final IRemoteAnimationRunner mRunner;
    private final @InteractionJankMonitor.CujType int mCujType;
    private final Context mContext;

    // Whether we are waiting to receive onAnimationStart
    private boolean mWaitingAnimation;
@@ -45,9 +52,21 @@ public class BackAnimationRunner {
    private boolean mAnimationCancelled;

    public BackAnimationRunner(
            @NonNull IOnBackInvokedCallback callback, @NonNull IRemoteAnimationRunner runner) {
            @NonNull IOnBackInvokedCallback callback,
            @NonNull IRemoteAnimationRunner runner,
            @NonNull Context context,
            @InteractionJankMonitor.CujType int cujType) {
        mCallback = callback;
        mRunner = runner;
        mCujType = cujType;
        mContext = context;
    }

    public BackAnimationRunner(
            @NonNull IOnBackInvokedCallback callback,
            @NonNull IRemoteAnimationRunner runner,
            @NonNull Context context) {
        this(callback, runner, context, NO_CUJ);
    }

    /** Returns the registered animation runner */
@@ -70,10 +89,17 @@ public class BackAnimationRunner {
                new IRemoteAnimationFinishedCallback.Stub() {
                    @Override
                    public void onAnimationFinished() {
                        if (shouldMonitorCUJ(apps)) {
                            InteractionJankMonitorUtils.endTracing(mCujType);
                        }
                        finishedCallback.run();
                    }
                };
        mWaitingAnimation = false;
        if (shouldMonitorCUJ(apps)) {
            InteractionJankMonitorUtils.beginTracing(
                    mCujType, mContext, apps[0].leash, /* tag */ null);
        }
        try {
            getRunner().onAnimationStart(TRANSIT_OLD_UNSET, apps, wallpapers,
                    nonApps, callback);
@@ -82,6 +108,10 @@ public class BackAnimationRunner {
        }
    }

    private boolean shouldMonitorCUJ(RemoteAnimationTarget[] apps) {
        return apps.length > 0 && mCujType != NO_CUJ;
    }

    void startGesture() {
        mWaitingAnimation = true;
        mAnimationCancelled = false;
+3 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.back;
import static android.view.RemoteAnimationTarget.MODE_CLOSING;
import static android.view.RemoteAnimationTarget.MODE_OPENING;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_PREDICTIVE_BACK_CROSS_ACTIVITY;
import static com.android.wm.shell.back.BackAnimationConstants.PROGRESS_COMMIT_THRESHOLD;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW;

@@ -135,7 +136,8 @@ public class CrossActivityAnimation extends ShellBackAnimation {
    @Inject
    public CrossActivityAnimation(Context context, BackAnimationBackground background) {
        mCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context);
        mBackAnimationRunner = new BackAnimationRunner(new Callback(), new Runner());
        mBackAnimationRunner = new BackAnimationRunner(
                new Callback(), new Runner(), context, CUJ_PREDICTIVE_BACK_CROSS_ACTIVITY);
        mBackground = background;
        mEnteringProgressSpring = new SpringAnimation(this, ENTER_PROGRESS_PROP);
        mEnteringProgressSpring.setSpring(new SpringForce()
+5 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.view.RemoteAnimationTarget.MODE_CLOSING;
import static android.view.RemoteAnimationTarget.MODE_OPENING;
import static android.window.BackEvent.EDGE_RIGHT;

import static com.android.internal.jank.InteractionJankMonitor.CUJ_PREDICTIVE_BACK_CROSS_TASK;
import static com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_BACK_PREVIEW;

import android.animation.Animator;
@@ -108,6 +109,7 @@ public class CrossTaskBackAnimation extends ShellBackAnimation {
    private final float[] mTmpTranslate = {0, 0, 0};
    private final BackAnimationRunner mBackAnimationRunner;
    private final BackAnimationBackground mBackground;
    private final Context mContext;
    private RemoteAnimationTarget mEnteringTarget;
    private RemoteAnimationTarget mClosingTarget;
    private SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction();
@@ -120,8 +122,10 @@ public class CrossTaskBackAnimation extends ShellBackAnimation {

    @Inject
    public CrossTaskBackAnimation(Context context, BackAnimationBackground background) {
        mContext = context;
        mCornerRadius = ScreenDecorationsUtils.getWindowCornerRadius(context);
        mBackAnimationRunner = new BackAnimationRunner(new Callback(), new Runner());
        mBackAnimationRunner = new BackAnimationRunner(
                new Callback(), new Runner(), context, CUJ_PREDICTIVE_BACK_CROSS_TASK);
        mBackground = background;
    }

Loading