From 08da44e16dfb02ec5410cc5d2610b4d65cd784e3 Mon Sep 17 00:00:00 2001 From: Tony Huang Date: Mon, 25 Apr 2022 16:18:04 +0800 Subject: [PATCH] Add jank monitor trace for divider dragging Bug: 203439850 Test: build passed Test: verified with systrace dump Change-Id: If2d5b836415f1e4f4a7aa11a23f1f39ef32fa26c --- .../common/InteractionJankMonitorUtils.java | 20 +++++++++++++++++++ .../wm/shell/common/split/DividerView.java | 6 +++++- .../wm/shell/common/split/SplitLayout.java | 17 ++++++++++++---- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/InteractionJankMonitorUtils.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/InteractionJankMonitorUtils.java index fd3aa05cfc06c..ec344d3451391 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/InteractionJankMonitorUtils.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/InteractionJankMonitorUtils.java @@ -18,7 +18,9 @@ package com.android.wm.shell.common; import android.annotation.NonNull; import android.annotation.Nullable; +import android.content.Context; import android.text.TextUtils; +import android.view.SurfaceControl; import android.view.View; import com.android.internal.jank.InteractionJankMonitor; @@ -43,6 +45,24 @@ public class InteractionJankMonitorUtils { InteractionJankMonitor.getInstance().begin(builder); } + /** + * Begin a trace session. + * + * @param cujType the specific {@link InteractionJankMonitor.CujType}. + * @param context the context + * @param surface the surface to trace + * @param tag the tag to distinguish different flow of same type CUJ. + */ + public static void beginTracing(@InteractionJankMonitor.CujType int cujType, + @NonNull Context context, @NonNull SurfaceControl surface, @Nullable String tag) { + final InteractionJankMonitor.Configuration.Builder builder = + InteractionJankMonitor.Configuration.Builder.withSurface(cujType, context, surface); + if (!TextUtils.isEmpty(tag)) { + builder.setTag(tag); + } + InteractionJankMonitor.getInstance().begin(builder); + } + /** * End a trace session. * diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java index 6305959bb6ac1..5ebe384d84b71 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/DividerView.java @@ -286,6 +286,7 @@ public class DividerView extends FrameLayout implements View.OnTouchListener { setTouching(); mStartPos = touchPos; mMoving = false; + mSplitLayout.onStartDragging(); break; case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(event); @@ -301,7 +302,10 @@ public class DividerView extends FrameLayout implements View.OnTouchListener { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: releaseTouching(); - if (!mMoving) break; + if (!mMoving) { + mSplitLayout.onDraggingCancelled(); + break; + } mVelocityTracker.addMovement(event); mVelocityTracker.computeCurrentVelocity(1000 /* units */); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java index c94455d9151a0..a60c9acf7af5c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/common/split/SplitLayout.java @@ -24,6 +24,7 @@ import static android.view.WindowManager.DOCKED_LEFT; import static android.view.WindowManager.DOCKED_RIGHT; import static android.view.WindowManager.DOCKED_TOP; +import static com.android.internal.jank.InteractionJankMonitor.CUJ_SPLIT_SCREEN_RESIZE; import static com.android.internal.policy.DividerSnapAlgorithm.SnapTarget.FLAG_DISMISS_END; import static com.android.internal.policy.DividerSnapAlgorithm.SnapTarget.FLAG_DISMISS_START; import static com.android.wm.shell.animation.Interpolators.DIM_INTERPOLATOR; @@ -55,7 +56,6 @@ import android.window.WindowContainerTransaction; import androidx.annotation.Nullable; import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.jank.InteractionJankMonitor; import com.android.internal.policy.DividerSnapAlgorithm; import com.android.internal.policy.DockedDividerUtils; import com.android.wm.shell.R; @@ -407,6 +407,15 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange } } + void onStartDragging() { + InteractionJankMonitorUtils.beginTracing(CUJ_SPLIT_SCREEN_RESIZE, mContext, + getDividerLeash(), null /* tag */); + } + + void onDraggingCancelled() { + InteractionJankMonitorUtils.cancelTracing(CUJ_SPLIT_SCREEN_RESIZE); + } + void onDoubleTappedDivider() { mSplitLayoutHandler.onDoubleTappedDivider(); } @@ -438,10 +447,10 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange if (from == to) { // No animation run, still callback to stop resizing. mSplitLayoutHandler.onLayoutSizeChanged(this); + InteractionJankMonitorUtils.endTracing( + CUJ_SPLIT_SCREEN_RESIZE); return; } - InteractionJankMonitorUtils.beginTracing(InteractionJankMonitor.CUJ_SPLIT_SCREEN_RESIZE, - mSplitWindowManager.getDividerView(), "Divider fling"); ValueAnimator animator = ValueAnimator .ofInt(from, to) .setDuration(250); @@ -455,7 +464,7 @@ public final class SplitLayout implements DisplayInsetsController.OnInsetsChange flingFinishedCallback.run(); } InteractionJankMonitorUtils.endTracing( - InteractionJankMonitor.CUJ_SPLIT_SCREEN_RESIZE); + CUJ_SPLIT_SCREEN_RESIZE); } @Override