Merge "Instrument CUJ_VOLUME_CONTROL with Trace tag" into tm-dev

This commit is contained in:
Lucas Dupin
2022-05-13 19:11:24 +00:00
committed by Android (Google) Code Review
4 changed files with 71 additions and 6 deletions

View File

@@ -74,6 +74,7 @@ import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_IN
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__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__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__USER_SWITCH;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__VOLUME_CONTROL;
import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__WALLPAPER_TRANSITION; import static com.android.internal.util.FrameworkStatsLog.UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__WALLPAPER_TRANSITION;
import android.annotation.IntDef; import android.annotation.IntDef;
@@ -196,6 +197,7 @@ public class InteractionJankMonitor {
public static final int CUJ_SPLIT_SCREEN_RESIZE = 52; public static final int CUJ_SPLIT_SCREEN_RESIZE = 52;
public static final int CUJ_SETTINGS_SLIDER = 53; public static final int CUJ_SETTINGS_SLIDER = 53;
public static final int CUJ_TAKE_SCREENSHOT = 54; public static final int CUJ_TAKE_SCREENSHOT = 54;
public static final int CUJ_VOLUME_CONTROL = 55;
private static final int NO_STATSD_LOGGING = -1; private static final int NO_STATSD_LOGGING = -1;
@@ -259,6 +261,7 @@ public class InteractionJankMonitor {
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLIT_SCREEN_RESIZE, UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SPLIT_SCREEN_RESIZE,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SETTINGS_SLIDER, UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__SETTINGS_SLIDER,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__TAKE_SCREENSHOT, UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__TAKE_SCREENSHOT,
UIINTERACTION_FRAME_INFO_REPORTED__INTERACTION_TYPE__VOLUME_CONTROL,
}; };
private static volatile InteractionJankMonitor sInstance; private static volatile InteractionJankMonitor sInstance;
@@ -334,6 +337,7 @@ public class InteractionJankMonitor {
CUJ_SPLIT_SCREEN_RESIZE, CUJ_SPLIT_SCREEN_RESIZE,
CUJ_SETTINGS_SLIDER, CUJ_SETTINGS_SLIDER,
CUJ_TAKE_SCREENSHOT, CUJ_TAKE_SCREENSHOT,
CUJ_VOLUME_CONTROL,
}) })
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
public @interface CujType { public @interface CujType {
@@ -762,6 +766,8 @@ public class InteractionJankMonitor {
return "SETTINGS_SLIDER"; return "SETTINGS_SLIDER";
case CUJ_TAKE_SCREENSHOT: case CUJ_TAKE_SCREENSHOT:
return "TAKE_SCREENSHOT"; return "TAKE_SCREENSHOT";
case CUJ_VOLUME_CONTROL:
return "VOLUME_CONTROL";
} }
return "UNKNOWN"; return "UNKNOWN";
} }

View File

@@ -32,6 +32,8 @@ import static android.view.View.LAYOUT_DIRECTION_RTL;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_VOLUME_CONTROL;
import static com.android.internal.jank.InteractionJankMonitor.Configuration.Builder;
import static com.android.systemui.volume.Events.DISMISS_REASON_SETTINGS_CLICKED; import static com.android.systemui.volume.Events.DISMISS_REASON_SETTINGS_CLICKED;
import android.animation.Animator; import android.animation.Animator;
@@ -68,6 +70,7 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Message; import android.os.Message;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.Trace;
import android.os.VibrationEffect; import android.os.VibrationEffect;
import android.provider.Settings; import android.provider.Settings;
import android.provider.Settings.Global; import android.provider.Settings.Global;
@@ -101,9 +104,11 @@ import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.android.internal.graphics.drawable.BackgroundBlurDrawable; import com.android.internal.graphics.drawable.BackgroundBlurDrawable;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.internal.view.RotationPolicy; import com.android.internal.view.RotationPolicy;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import com.android.systemui.Prefs; import com.android.systemui.Prefs;
@@ -149,6 +154,13 @@ public class VolumeDialogImpl implements VolumeDialog,
private static final int DRAWER_ANIMATION_DURATION_SHORT = 175; private static final int DRAWER_ANIMATION_DURATION_SHORT = 175;
private static final int DRAWER_ANIMATION_DURATION = 250; private static final int DRAWER_ANIMATION_DURATION = 250;
/** Shows volume dialog show animation. */
private static final String TYPE_SHOW = "show";
/** Dismiss volume dialog animation. */
private static final String TYPE_DISMISS = "dismiss";
/** Volume dialog slider animation. */
private static final String TYPE_UPDATE = "update";
private final int mDialogShowAnimationDurationMs; private final int mDialogShowAnimationDurationMs;
private final int mDialogHideAnimationDurationMs; private final int mDialogHideAnimationDurationMs;
private int mDialogWidth; private int mDialogWidth;
@@ -258,6 +270,7 @@ public class VolumeDialogImpl implements VolumeDialog,
private final boolean mUseBackgroundBlur; private final boolean mUseBackgroundBlur;
private Consumer<Boolean> mCrossWindowBlurEnabledListener; private Consumer<Boolean> mCrossWindowBlurEnabledListener;
private BackgroundBlurDrawable mDialogRowsViewBackground; private BackgroundBlurDrawable mDialogRowsViewBackground;
private final InteractionJankMonitor mInteractionJankMonitor;
public VolumeDialogImpl( public VolumeDialogImpl(
Context context, Context context,
@@ -266,7 +279,8 @@ public class VolumeDialogImpl implements VolumeDialog,
DeviceProvisionedController deviceProvisionedController, DeviceProvisionedController deviceProvisionedController,
ConfigurationController configurationController, ConfigurationController configurationController,
MediaOutputDialogFactory mediaOutputDialogFactory, MediaOutputDialogFactory mediaOutputDialogFactory,
ActivityStarter activityStarter) { ActivityStarter activityStarter,
InteractionJankMonitor interactionJankMonitor) {
mContext = mContext =
new ContextThemeWrapper(context, R.style.volume_dialog_theme); new ContextThemeWrapper(context, R.style.volume_dialog_theme);
mController = volumeDialogController; mController = volumeDialogController;
@@ -290,6 +304,7 @@ public class VolumeDialogImpl implements VolumeDialog,
mContext.getResources().getInteger(R.integer.config_dialogHideAnimationDurationMs); mContext.getResources().getInteger(R.integer.config_dialogHideAnimationDurationMs);
mUseBackgroundBlur = mUseBackgroundBlur =
mContext.getResources().getBoolean(R.bool.config_volumeDialogUseBackgroundBlur); mContext.getResources().getBoolean(R.bool.config_volumeDialogUseBackgroundBlur);
mInteractionJankMonitor = interactionJankMonitor;
if (mUseBackgroundBlur) { if (mUseBackgroundBlur) {
final int dialogRowsViewColorAboveBlur = mContext.getColor( final int dialogRowsViewColorAboveBlur = mContext.getColor(
@@ -422,6 +437,7 @@ public class VolumeDialogImpl implements VolumeDialog,
.alpha(1) .alpha(1)
.translationX(0) .translationX(0)
.setDuration(mDialogShowAnimationDurationMs) .setDuration(mDialogShowAnimationDurationMs)
.setListener(getJankListener(getDialogView(), TYPE_SHOW, DIALOG_TIMEOUT_MILLIS))
.setInterpolator(new SystemUIInterpolators.LogDecelerateInterpolator()) .setInterpolator(new SystemUIInterpolators.LogDecelerateInterpolator())
.withEndAction(() -> { .withEndAction(() -> {
if (!Prefs.getBoolean(mContext, Prefs.Key.TOUCHED_RINGER_TOGGLE, false)) { if (!Prefs.getBoolean(mContext, Prefs.Key.TOUCHED_RINGER_TOGGLE, false)) {
@@ -692,7 +708,7 @@ public class VolumeDialogImpl implements VolumeDialog,
final int m = seekBar.getMax(); final int m = seekBar.getMax();
final int n = m / 100 - 1; final int n = m / 100 - 1;
final int level = progress == 0 ? 0 final int level = progress == 0 ? 0
: progress == m ? (m / 100) : (1 + (int)((progress / (float) m) * n)); : progress == m ? (m / 100) : (1 + (int) ((progress / (float) m) * n));
return level; return level;
} }
@@ -1251,7 +1267,33 @@ public class VolumeDialogImpl implements VolumeDialog,
mHandler.obtainMessage(H.DISMISS, reason, 0).sendToTarget(); mHandler.obtainMessage(H.DISMISS, reason, 0).sendToTarget();
} }
private Animator.AnimatorListener getJankListener(View v, String type, long timeout) {
return new Animator.AnimatorListener() {
@Override
public void onAnimationStart(@NonNull Animator animation) {
mInteractionJankMonitor.begin(Builder.withView(CUJ_VOLUME_CONTROL, v).setTag(type)
.setTimeout(timeout));
}
@Override
public void onAnimationEnd(@NonNull Animator animation) {
mInteractionJankMonitor.end(CUJ_VOLUME_CONTROL);
}
@Override
public void onAnimationCancel(@NonNull Animator animation) {
mInteractionJankMonitor.cancel(CUJ_VOLUME_CONTROL);
}
@Override
public void onAnimationRepeat(@NonNull Animator animation) {
// no-op
}
};
}
private void showH(int reason) { private void showH(int reason) {
Trace.beginSection("VolumeDialogImpl#showH");
if (D.BUG) Log.d(TAG, "showH r=" + Events.SHOW_REASONS[reason]); if (D.BUG) Log.d(TAG, "showH r=" + Events.SHOW_REASONS[reason]);
mHandler.removeMessages(H.SHOW); mHandler.removeMessages(H.SHOW);
mHandler.removeMessages(H.DISMISS); mHandler.removeMessages(H.DISMISS);
@@ -1272,6 +1314,7 @@ public class VolumeDialogImpl implements VolumeDialog,
mController.getCaptionsComponentState(false); mController.getCaptionsComponentState(false);
checkODICaptionsTooltip(false); checkODICaptionsTooltip(false);
updateBackgroundForDrawerClosedAmount(); updateBackgroundForDrawerClosedAmount();
Trace.endSection();
} }
protected void rescheduleTimeoutH() { protected void rescheduleTimeoutH() {
@@ -1305,6 +1348,7 @@ public class VolumeDialogImpl implements VolumeDialog,
} }
protected void dismissH(int reason) { protected void dismissH(int reason) {
Trace.beginSection("VolumeDialogImpl#dismissH");
if (D.BUG) { if (D.BUG) {
Log.d(TAG, "mDialog.dismiss() reason: " + Events.DISMISS_REASONS[reason] Log.d(TAG, "mDialog.dismiss() reason: " + Events.DISMISS_REASONS[reason]
+ " from: " + Debug.getCaller()); + " from: " + Debug.getCaller());
@@ -1335,7 +1379,8 @@ public class VolumeDialogImpl implements VolumeDialog,
hideRingerDrawer(); hideRingerDrawer();
}, 50)); }, 50));
if (!shouldSlideInVolumeTray()) animator.translationX(mDialogView.getWidth() / 2.0f); if (!shouldSlideInVolumeTray()) animator.translationX(mDialogView.getWidth() / 2.0f);
animator.start(); animator.setListener(getJankListener(getDialogView(), TYPE_DISMISS,
mDialogHideAnimationDurationMs)).start();
checkODICaptionsTooltip(true); checkODICaptionsTooltip(true);
mController.notifyVisible(false); mController.notifyVisible(false);
synchronized (mSafetyWarningLock) { synchronized (mSafetyWarningLock) {
@@ -1344,6 +1389,7 @@ public class VolumeDialogImpl implements VolumeDialog,
mSafetyWarning.dismiss(); mSafetyWarning.dismiss();
} }
} }
Trace.endSection();
} }
private boolean showActiveStreamOnly() { private boolean showActiveStreamOnly() {
@@ -1383,6 +1429,7 @@ public class VolumeDialogImpl implements VolumeDialog,
} }
private void updateRowsH(final VolumeRow activeRow) { private void updateRowsH(final VolumeRow activeRow) {
Trace.beginSection("VolumeDialogImpl#updateRowsH");
if (D.BUG) Log.d(TAG, "updateRowsH"); if (D.BUG) Log.d(TAG, "updateRowsH");
if (!mShowing) { if (!mShowing) {
trimObsoleteH(); trimObsoleteH();
@@ -1446,6 +1493,7 @@ public class VolumeDialogImpl implements VolumeDialog,
} }
updateBackgroundForDrawerClosedAmount(); updateBackgroundForDrawerClosedAmount();
Trace.endSection();
} }
protected void updateRingerH() { protected void updateRingerH() {
@@ -1730,7 +1778,9 @@ public class VolumeDialogImpl implements VolumeDialog,
final boolean enableSlider = !zenMuted; final boolean enableSlider = !zenMuted;
final int vlevel = row.ss.muted && (!isRingStream && !zenMuted) ? 0 final int vlevel = row.ss.muted && (!isRingStream && !zenMuted) ? 0
: row.ss.level; : row.ss.level;
Trace.beginSection("VolumeDialogImpl#updateVolumeRowSliderH");
updateVolumeRowSliderH(row, enableSlider, vlevel); updateVolumeRowSliderH(row, enableSlider, vlevel);
Trace.endSection();
if (row.number != null) row.number.setText(Integer.toString(vlevel)); if (row.number != null) row.number.setText(Integer.toString(vlevel));
} }
@@ -1824,6 +1874,8 @@ public class VolumeDialogImpl implements VolumeDialog,
} }
row.animTargetProgress = newProgress; row.animTargetProgress = newProgress;
row.anim.setDuration(UPDATE_ANIMATION_DURATION); row.anim.setDuration(UPDATE_ANIMATION_DURATION);
row.anim.addListener(
getJankListener(row.view, TYPE_UPDATE, UPDATE_ANIMATION_DURATION));
row.anim.start(); row.anim.start();
} else { } else {
// update slider directly to clamped value // update slider directly to clamped value

View File

@@ -19,6 +19,7 @@ package com.android.systemui.volume.dagger;
import android.content.Context; import android.content.Context;
import android.media.AudioManager; import android.media.AudioManager;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.systemui.media.dialog.MediaOutputDialogFactory; import com.android.systemui.media.dialog.MediaOutputDialogFactory;
import com.android.systemui.plugins.ActivityStarter; import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.VolumeDialog; import com.android.systemui.plugins.VolumeDialog;
@@ -51,7 +52,8 @@ public interface VolumeModule {
DeviceProvisionedController deviceProvisionedController, DeviceProvisionedController deviceProvisionedController,
ConfigurationController configurationController, ConfigurationController configurationController,
MediaOutputDialogFactory mediaOutputDialogFactory, MediaOutputDialogFactory mediaOutputDialogFactory,
ActivityStarter activityStarter) { ActivityStarter activityStarter,
InteractionJankMonitor interactionJankMonitor) {
VolumeDialogImpl impl = new VolumeDialogImpl( VolumeDialogImpl impl = new VolumeDialogImpl(
context, context,
volumeDialogController, volumeDialogController,
@@ -59,7 +61,8 @@ public interface VolumeModule {
deviceProvisionedController, deviceProvisionedController,
configurationController, configurationController,
mediaOutputDialogFactory, mediaOutputDialogFactory,
activityStarter); activityStarter,
interactionJankMonitor);
impl.setStreamImportant(AudioManager.STREAM_SYSTEM, false); impl.setStreamImportant(AudioManager.STREAM_SYSTEM, false);
impl.setAutomute(true); impl.setAutomute(true);
impl.setSilentMode(false); impl.setSilentMode(false);

View File

@@ -38,6 +38,7 @@ import android.view.accessibility.AccessibilityManager;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
import com.android.internal.jank.InteractionJankMonitor;
import com.android.systemui.Prefs; import com.android.systemui.Prefs;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.SysuiTestCase; import com.android.systemui.SysuiTestCase;
@@ -85,6 +86,8 @@ public class VolumeDialogImplTest extends SysuiTestCase {
MediaOutputDialogFactory mMediaOutputDialogFactory; MediaOutputDialogFactory mMediaOutputDialogFactory;
@Mock @Mock
ActivityStarter mActivityStarter; ActivityStarter mActivityStarter;
@Mock
InteractionJankMonitor mInteractionJankMonitor;
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
@@ -99,7 +102,8 @@ public class VolumeDialogImplTest extends SysuiTestCase {
mDeviceProvisionedController, mDeviceProvisionedController,
mConfigurationController, mConfigurationController,
mMediaOutputDialogFactory, mMediaOutputDialogFactory,
mActivityStarter); mActivityStarter,
mInteractionJankMonitor);
mDialog.init(0, null); mDialog.init(0, null);
State state = createShellState(); State state = createShellState();
mDialog.onStateChangedH(state); mDialog.onStateChangedH(state);