Instrument jank of CUJ take screen shot

Bug: 226526041
Test: see the reference trace in the bug
Change-Id: Ia25f0ebb965ada1006a00b68bfee90106f2a9573
This commit is contained in:
Ahan Wu
2022-04-13 11:45:40 +00:00
parent 6474aed2f5
commit 9a083dde2c
4 changed files with 65 additions and 1 deletions

View File

@@ -71,6 +71,7 @@ import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_IN
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SUW_LOADING_TO_NEXT_FLOW;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SUW_LOADING_TO_SHOW_INFO_WITH_ACTIONS;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SUW_SHOW_FUNCTION_SCREEN_WITH_ACTIONS;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__TAKE_SCREENSHOT;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__UNFOLD_ANIM;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__USER_SWITCH;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__WALLPAPER_TRANSITION;
@@ -194,6 +195,7 @@ public class InteractionJankMonitor {
public static final int CUJ_LOCKSCREEN_LAUNCH_CAMERA = 51; // reserved.
public static final int CUJ_SPLIT_SCREEN_RESIZE = 52;
public static final int CUJ_SETTINGS_SLIDER = 53;
public static final int CUJ_TAKE_SCREENSHOT = 54;
private static final int NO_STATSD_LOGGING = -1;
@@ -256,6 +258,7 @@ public class InteractionJankMonitor {
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__LOCKSCREEN_LAUNCH_CAMERA,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLIT_SCREEN_RESIZE,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SETTINGS_SLIDER,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__TAKE_SCREENSHOT,
};
private static volatile InteractionJankMonitor sInstance;
@@ -330,6 +333,7 @@ public class InteractionJankMonitor {
CUJ_LOCKSCREEN_LAUNCH_CAMERA,
CUJ_SPLIT_SCREEN_RESIZE,
CUJ_SETTINGS_SLIDER,
CUJ_TAKE_SCREENSHOT,
})
@Retention(RetentionPolicy.SOURCE)
public @interface CujType {
@@ -756,6 +760,8 @@ public class InteractionJankMonitor {
return "CUJ_SPLIT_SCREEN_RESIZE";
case CUJ_SETTINGS_SLIDER:
return "SETTINGS_SLIDER";
case CUJ_TAKE_SCREENSHOT:
return "TAKE_SCREENSHOT";
}
return "UNKNOWN";
}

View File

@@ -484,6 +484,7 @@ public class ScreenshotController {
setWindowFocusable(false);
}
});
mScreenshotView.setDefaultTimeoutMillis(mScreenshotHandler.getDefaultTimeoutMillis());
mScreenshotView.setOnKeyListener((v, keyCode, event) -> {
if (keyCode == KeyEvent.KEYCODE_BACK) {

View File

@@ -18,6 +18,7 @@ package com.android.systemui.screenshot;
import static android.content.res.Configuration.ORIENTATION_PORTRAIT;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_TAKE_SCREENSHOT;
import static com.android.systemui.screenshot.LogConfig.DEBUG_ANIM;
import static com.android.systemui.screenshot.LogConfig.DEBUG_DISMISS;
import static com.android.systemui.screenshot.LogConfig.DEBUG_INPUT;
@@ -83,6 +84,7 @@ import android.widget.LinearLayout;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.R;
import com.android.systemui.screenshot.ScreenshotController.SavedImageData.ActionTransition;
@@ -167,6 +169,9 @@ public class ScreenshotView extends FrameLayout implements
private final ArrayList<OverlayActionChip> mSmartChips = new ArrayList<>();
private PendingInteraction mPendingInteraction;
private final InteractionJankMonitor mInteractionJankMonitor;
private long mDefaultTimeoutOfTimeoutHandler;
private enum PendingInteraction {
PREVIEW,
EDIT,
@@ -190,6 +195,7 @@ public class ScreenshotView extends FrameLayout implements
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
mResources = mContext.getResources();
mInteractionJankMonitor = getInteractionJankMonitorInstance();
mFixedSize = mResources.getDimensionPixelSize(R.dimen.overlay_x_scale);
@@ -230,6 +236,14 @@ public class ScreenshotView extends FrameLayout implements
});
}
private InteractionJankMonitor getInteractionJankMonitorInstance() {
return InteractionJankMonitor.getInstance();
}
void setDefaultTimeoutMillis(long timeout) {
mDefaultTimeoutOfTimeoutHandler = timeout;
}
public void hideScrollChip() {
mScrollChip.setVisibility(View.GONE);
}
@@ -406,6 +420,9 @@ public class ScreenshotView extends FrameLayout implements
@Override
public void onDismissComplete() {
if (mInteractionJankMonitor.isInstrumenting(CUJ_TAKE_SCREENSHOT)) {
mInteractionJankMonitor.end(CUJ_TAKE_SCREENSHOT);
}
mCallbacks.onDismiss();
}
});
@@ -605,6 +622,20 @@ public class ScreenshotView extends FrameLayout implements
dropInAnimation.play(borderFadeIn).after(toCorner);
dropInAnimation.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
mInteractionJankMonitor.cancel(CUJ_TAKE_SCREENSHOT);
}
@Override
public void onAnimationStart(Animator animation) {
InteractionJankMonitor.Configuration.Builder builder =
InteractionJankMonitor.Configuration.Builder.withView(
CUJ_TAKE_SCREENSHOT, mScreenshotPreview)
.setTag("DropIn");
mInteractionJankMonitor.begin(builder);
}
@Override
public void onAnimationEnd(Animator animation) {
if (DEBUG_ANIM) {
@@ -631,7 +662,7 @@ public class ScreenshotView extends FrameLayout implements
mScreenshotPreview.setX(finalPos.x - mScreenshotPreview.getWidth() / 2f);
mScreenshotPreview.setY(finalPos.y - mScreenshotPreview.getHeight() / 2f);
requestLayout();
mInteractionJankMonitor.end(CUJ_TAKE_SCREENSHOT);
createScreenshotActionsShadeAnimation().start();
}
});
@@ -702,6 +733,28 @@ public class ScreenshotView extends FrameLayout implements
mActionsContainer.setVisibility(View.VISIBLE);
mActionsContainerBackground.setVisibility(View.VISIBLE);
animator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
mInteractionJankMonitor.cancel(CUJ_TAKE_SCREENSHOT);
}
@Override
public void onAnimationEnd(Animator animation) {
mInteractionJankMonitor.end(CUJ_TAKE_SCREENSHOT);
}
@Override
public void onAnimationStart(Animator animation) {
InteractionJankMonitor.Configuration.Builder builder =
InteractionJankMonitor.Configuration.Builder.withView(
CUJ_TAKE_SCREENSHOT, mScreenshotStatic)
.setTag("Actions")
.setTimeout(mDefaultTimeoutOfTimeoutHandler);
mInteractionJankMonitor.begin(builder);
}
});
animator.addUpdateListener(animation -> {
float t = animation.getAnimatedFraction();
mBackgroundProtection.setAlpha(t);

View File

@@ -72,6 +72,10 @@ public class TimeoutHandler extends Handler {
mDefaultTimeout = timeout;
}
int getDefaultTimeoutMillis() {
return mDefaultTimeout;
}
/**
* Cancel the current timeout, if any. To reset the delayed runnable use resetTimeout instead.
*/