Instrument jank of splash screen AVD and exit animation

Add jank instrument support for splash screen avd and exit animation.

Bug: 195736656
Test: see trace in comment
Change-Id: I1fdb9e14145bcf519eea99e440de74238e3c765c
This commit is contained in:
Wu Ahan
2021-10-19 11:46:00 +00:00
parent fdf0378b8d
commit 61cd0b63c4
4 changed files with 64 additions and 2 deletions

View File

@@ -20,6 +20,10 @@ import static android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACK
import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
import static android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_SPLASHSCREEN_AVD;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -54,6 +58,7 @@ import android.widget.FrameLayout;
import android.widget.ImageView;
import com.android.internal.R;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.policy.DecorView;
import com.android.internal.util.ContrastColorUtil;
@@ -487,6 +492,23 @@ public final class SplashScreenView extends FrameLayout {
}
IconAnimateListener aniDrawable = (IconAnimateListener) iconDrawable;
aniDrawable.prepareAnimate(duration, this::animationStartCallback);
aniDrawable.setAnimationJankMonitoring(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
InteractionJankMonitor.getInstance().cancel(CUJ_SPLASHSCREEN_AVD);
}
@Override
public void onAnimationEnd(Animator animation) {
InteractionJankMonitor.getInstance().end(CUJ_SPLASHSCREEN_AVD);
}
@Override
public void onAnimationStart(Animator animation) {
InteractionJankMonitor.getInstance().begin(
SplashScreenView.this, CUJ_SPLASHSCREEN_AVD);
}
});
}
private void animationStartCallback() {
@@ -669,6 +691,12 @@ public final class SplashScreenView extends FrameLayout {
* Stop animation.
*/
void stopAnimation();
/**
* Provides a chance to start interaction jank monitoring in avd animation.
* @param listener a listener to start jank monitoring
*/
default void setAnimationJankMonitoring(AnimatorListenerAdapter listener) {}
}
/**

View File

@@ -58,6 +58,8 @@ import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_IN
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SHADE_ROW_EXPAND;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SHADE_ROW_SWIPE;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SHADE_SCROLL_FLING;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLASHSCREEN_AVD;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLASHSCREEN_EXIT_ANIM;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__STATUS_BAR_APP_LAUNCH_FROM_CALL_CHIP;
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;
@@ -173,6 +175,8 @@ public class InteractionJankMonitor {
public static final int CUJ_PIP_TRANSITION = 35;
public static final int CUJ_WALLPAPER_TRANSITION = 36;
public static final int CUJ_USER_SWITCH = 37;
public static final int CUJ_SPLASHSCREEN_AVD = 38;
public static final int CUJ_SPLASHSCREEN_EXIT_ANIM = 39;
private static final int NO_STATSD_LOGGING = -1;
@@ -219,6 +223,8 @@ public class InteractionJankMonitor {
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__PIP_TRANSITION,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__WALLPAPER_TRANSITION,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__USER_SWITCH,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLASHSCREEN_AVD,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLASHSCREEN_EXIT_ANIM,
};
private static volatile InteractionJankMonitor sInstance;
@@ -276,6 +282,8 @@ public class InteractionJankMonitor {
CUJ_PIP_TRANSITION,
CUJ_WALLPAPER_TRANSITION,
CUJ_USER_SWITCH,
CUJ_SPLASHSCREEN_AVD,
CUJ_SPLASHSCREEN_EXIT_ANIM,
})
@Retention(RetentionPolicy.SOURCE)
public @interface CujType {
@@ -648,6 +656,10 @@ public class InteractionJankMonitor {
return "WALLPAPER_TRANSITION";
case CUJ_USER_SWITCH:
return "USER_SWITCH";
case CUJ_SPLASHSCREEN_AVD:
return "SPLASHSCREEN_AVD";
case CUJ_SPLASHSCREEN_EXIT_ANIM:
return "SPLASHSCREEN_EXIT_ANIM";
}
return "UNKNOWN";
}

View File

@@ -18,6 +18,8 @@ package com.android.wm.shell.startingsurface;
import static android.view.Choreographer.CALLBACK_COMMIT;
import static android.view.View.GONE;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_SPLASHSCREEN_EXIT_ANIM;
import android.animation.Animator;
import android.animation.ValueAnimator;
import android.content.Context;
@@ -42,6 +44,7 @@ import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;
import android.window.SplashScreenView;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.wm.shell.R;
import com.android.wm.shell.animation.Interpolators;
import com.android.wm.shell.common.TransactionPool;
@@ -311,17 +314,19 @@ public class SplashScreenExitAnimation implements Animator.AnimatorListener {
@Override
public void onAnimationStart(Animator animation) {
// ignore
InteractionJankMonitor.getInstance().begin(mSplashScreenView, CUJ_SPLASHSCREEN_EXIT_ANIM);
}
@Override
public void onAnimationEnd(Animator animation) {
reset();
InteractionJankMonitor.getInstance().end(CUJ_SPLASHSCREEN_EXIT_ANIM);
}
@Override
public void onAnimationCancel(Animator animation) {
reset();
InteractionJankMonitor.getInstance().cancel(CUJ_SPLASHSCREEN_EXIT_ANIM);
}
@Override

View File

@@ -19,6 +19,7 @@ package com.android.wm.shell.startingsurface;
import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.ColorInt;
import android.annotation.NonNull;
@@ -263,17 +264,23 @@ public class SplashscreenIconDrawableFactory {
* A lightweight AdaptiveIconDrawable which support foreground to be Animatable, and keep this
* drawable masked by config_icon_mask.
*/
private static class AnimatableIconAnimateListener extends AdaptiveForegroundDrawable
public static class AnimatableIconAnimateListener extends AdaptiveForegroundDrawable
implements SplashScreenView.IconAnimateListener {
private Animatable mAnimatableIcon;
private Animator mIconAnimator;
private boolean mAnimationTriggered;
private AnimatorListenerAdapter mJankMonitoringListener;
AnimatableIconAnimateListener(@NonNull Drawable foregroundDrawable) {
super(foregroundDrawable);
mForegroundDrawable.setCallback(mCallback);
}
@Override
public void setAnimationJankMonitoring(AnimatorListenerAdapter listener) {
mJankMonitoringListener = listener;
}
@Override
public boolean prepareAnimate(long duration, Runnable startListener) {
mAnimatableIcon = (Animatable) mForegroundDrawable;
@@ -286,6 +293,9 @@ public class SplashscreenIconDrawableFactory {
startListener.run();
}
try {
if (mJankMonitoringListener != null) {
mJankMonitoringListener.onAnimationStart(animation);
}
mAnimatableIcon.start();
} catch (Exception ex) {
Log.e(TAG, "Error while running the splash screen animated icon", ex);
@@ -296,11 +306,17 @@ public class SplashscreenIconDrawableFactory {
@Override
public void onAnimationEnd(Animator animation) {
mAnimatableIcon.stop();
if (mJankMonitoringListener != null) {
mJankMonitoringListener.onAnimationEnd(animation);
}
}
@Override
public void onAnimationCancel(Animator animation) {
mAnimatableIcon.stop();
if (mJankMonitoringListener != null) {
mJankMonitoringListener.onAnimationCancel(animation);
}
}
@Override
@@ -316,6 +332,7 @@ public class SplashscreenIconDrawableFactory {
public void stopAnimation() {
if (mIconAnimator != null) {
mIconAnimator.end();
mJankMonitoringListener = null;
}
}