Merge "Only consider the last launched activity for metrics logger" into sc-v2-dev

This commit is contained in:
TreeHugger Robot
2021-11-02 02:59:40 +00:00
committed by Android (Google) Code Review
2 changed files with 20 additions and 61 deletions

View File

@@ -190,7 +190,7 @@ class ActivityMetricsLogger {
@VisibleForTesting @VisibleForTesting
boolean allDrawn() { boolean allDrawn() {
return mAssociatedTransitionInfo != null && mAssociatedTransitionInfo.allDrawn(); return mAssociatedTransitionInfo != null && mAssociatedTransitionInfo.mIsDrawn;
} }
boolean hasActiveTransitionInfo() { boolean hasActiveTransitionInfo() {
@@ -224,8 +224,8 @@ class ActivityMetricsLogger {
final boolean mProcessRunning; final boolean mProcessRunning;
/** whether the process of the launching activity didn't have any active activity. */ /** whether the process of the launching activity didn't have any active activity. */
final boolean mProcessSwitch; final boolean mProcessSwitch;
/** The activities that should be drawn. */ /** Whether the last launched activity has reported drawn. */
final ArrayList<ActivityRecord> mPendingDrawActivities = new ArrayList<>(2); boolean mIsDrawn;
/** The latest activity to have been launched. */ /** The latest activity to have been launched. */
@NonNull ActivityRecord mLastLaunchedActivity; @NonNull ActivityRecord mLastLaunchedActivity;
@@ -318,10 +318,7 @@ class ActivityMetricsLogger {
mLastLaunchedActivity.mLaunchRootTask = null; mLastLaunchedActivity.mLaunchRootTask = null;
} }
mLastLaunchedActivity = r; mLastLaunchedActivity = r;
if (!r.noDisplay && !r.isReportedDrawn()) { mIsDrawn = r.isReportedDrawn();
if (DEBUG_METRICS) Slog.i(TAG, "Add pending draw " + r);
mPendingDrawActivities.add(r);
}
} }
/** Returns {@code true} if the incoming activity can belong to this transition. */ /** Returns {@code true} if the incoming activity can belong to this transition. */
@@ -332,29 +329,7 @@ class ActivityMetricsLogger {
/** @return {@code true} if the activity matches a launched activity in this transition. */ /** @return {@code true} if the activity matches a launched activity in this transition. */
boolean contains(ActivityRecord r) { boolean contains(ActivityRecord r) {
return r != null && (r == mLastLaunchedActivity || mPendingDrawActivities.contains(r)); return r == mLastLaunchedActivity;
}
/** Called when the activity is drawn or won't be drawn. */
void removePendingDrawActivity(ActivityRecord r) {
if (DEBUG_METRICS) Slog.i(TAG, "Remove pending draw " + r);
mPendingDrawActivities.remove(r);
}
boolean allDrawn() {
return mPendingDrawActivities.isEmpty();
}
/** Only keep the records which can be drawn. */
void updatePendingDraw(boolean keepInitializing) {
for (int i = mPendingDrawActivities.size() - 1; i >= 0; i--) {
final ActivityRecord r = mPendingDrawActivities.get(i);
if (!r.mVisibleRequested
&& !(keepInitializing && r.isState(ActivityRecord.State.INITIALIZING))) {
if (DEBUG_METRICS) Slog.i(TAG, "Discard pending draw " + r);
mPendingDrawActivities.remove(i);
}
}
} }
/** /**
@@ -377,7 +352,7 @@ class ActivityMetricsLogger {
@Override @Override
public String toString() { public String toString() {
return "TransitionInfo{" + Integer.toHexString(System.identityHashCode(this)) return "TransitionInfo{" + Integer.toHexString(System.identityHashCode(this))
+ " a=" + mLastLaunchedActivity + " ua=" + mPendingDrawActivities + "}"; + " a=" + mLastLaunchedActivity + " d=" + mIsDrawn + "}";
} }
} }
@@ -683,8 +658,7 @@ class ActivityMetricsLogger {
// visible such as after the top task is finished. // visible such as after the top task is finished.
for (int i = mTransitionInfoList.size() - 2; i >= 0; i--) { for (int i = mTransitionInfoList.size() - 2; i >= 0; i--) {
final TransitionInfo prevInfo = mTransitionInfoList.get(i); final TransitionInfo prevInfo = mTransitionInfoList.get(i);
prevInfo.updatePendingDraw(false /* keepInitializing */); if (prevInfo.mIsDrawn || !prevInfo.mLastLaunchedActivity.mVisibleRequested) {
if (prevInfo.allDrawn()) {
abort(prevInfo, "nothing will be drawn"); abort(prevInfo, "nothing will be drawn");
} }
} }
@@ -711,17 +685,16 @@ class ActivityMetricsLogger {
if (DEBUG_METRICS) Slog.i(TAG, "notifyWindowsDrawn " + r); if (DEBUG_METRICS) Slog.i(TAG, "notifyWindowsDrawn " + r);
final TransitionInfo info = getActiveTransitionInfo(r); final TransitionInfo info = getActiveTransitionInfo(r);
if (info == null || info.allDrawn()) { if (info == null || info.mIsDrawn) {
if (DEBUG_METRICS) Slog.i(TAG, "notifyWindowsDrawn no activity to be drawn"); if (DEBUG_METRICS) Slog.i(TAG, "notifyWindowsDrawn not pending drawn " + info);
return null; return null;
} }
// Always calculate the delay because the caller may need to know the individual drawn time. // Always calculate the delay because the caller may need to know the individual drawn time.
info.mWindowsDrawnDelayMs = info.calculateDelay(timestampNs); info.mWindowsDrawnDelayMs = info.calculateDelay(timestampNs);
info.removePendingDrawActivity(r); info.mIsDrawn = true;
info.updatePendingDraw(false /* keepInitializing */);
final TransitionInfoSnapshot infoSnapshot = new TransitionInfoSnapshot(info); final TransitionInfoSnapshot infoSnapshot = new TransitionInfoSnapshot(info);
if (info.mLoggedTransitionStarting && info.allDrawn()) { if (info.mLoggedTransitionStarting) {
done(false /* abort */, info, "notifyWindowsDrawn - all windows drawn", timestampNs); done(false /* abort */, info, "notifyWindowsDrawn", timestampNs);
} }
if (r.mWmService.isRecentsAnimationTarget(r)) { if (r.mWmService.isRecentsAnimationTarget(r)) {
r.mWmService.getRecentsAnimationController().logRecentsAnimationStartTime( r.mWmService.getRecentsAnimationController().logRecentsAnimationStartTime(
@@ -770,12 +743,8 @@ class ActivityMetricsLogger {
info.mCurrentTransitionDelayMs = info.calculateDelay(timestampNs); info.mCurrentTransitionDelayMs = info.calculateDelay(timestampNs);
info.mReason = activityToReason.valueAt(index); info.mReason = activityToReason.valueAt(index);
info.mLoggedTransitionStarting = true; info.mLoggedTransitionStarting = true;
// Do not remove activity in initializing state because the transition may be started if (info.mIsDrawn) {
// by starting window. The initializing activity may be requested to visible soon. done(false /* abort */, info, "notifyTransitionStarting drawn", timestampNs);
info.updatePendingDraw(true /* keepInitializing */);
if (info.allDrawn()) {
done(false /* abort */, info, "notifyTransitionStarting - all windows drawn",
timestampNs);
} }
} }
} }
@@ -828,14 +797,11 @@ class ActivityMetricsLogger {
return; return;
} }
if (!r.mVisibleRequested || r.finishing) { if (!r.mVisibleRequested || r.finishing) {
info.removePendingDrawActivity(r);
if (info.mLastLaunchedActivity == r) {
// Check if the tracker can be cancelled because the last launched activity may be // Check if the tracker can be cancelled because the last launched activity may be
// no longer visible. // no longer visible.
scheduleCheckActivityToBeDrawn(r, 0 /* delay */); scheduleCheckActivityToBeDrawn(r, 0 /* delay */);
} }
} }
}
private void scheduleCheckActivityToBeDrawn(@NonNull ActivityRecord r, long delay) { private void scheduleCheckActivityToBeDrawn(@NonNull ActivityRecord r, long delay) {
// The activity and its task are passed separately because it is possible that the activity // The activity and its task are passed separately because it is possible that the activity
@@ -852,17 +818,12 @@ class ActivityMetricsLogger {
// If we have an active transition that's waiting on a certain activity that will be // If we have an active transition that's waiting on a certain activity that will be
// invisible now, we'll never get onWindowsDrawn, so abort the transition if necessary. // invisible now, we'll never get onWindowsDrawn, so abort the transition if necessary.
// We have no active transitions. // We have no active transitions. Or the notified activity whose visibility changed is
// no longer the launched activity, then we can still wait to get onWindowsDrawn.
if (info == null) { if (info == null) {
return; return;
} }
// The notified activity whose visibility changed is no longer the launched activity.
// We can still wait to get onWindowsDrawn.
if (info.mLastLaunchedActivity != r) {
return;
}
// If the task of the launched activity contains any activity to be drawn, then the // If the task of the launched activity contains any activity to be drawn, then the
// window drawn event should report later to complete the transition. Otherwise all // window drawn event should report later to complete the transition. Otherwise all
// activities in this task may be finished, invisible or drawn, so the transition event // activities in this task may be finished, invisible or drawn, so the transition event
@@ -945,7 +906,6 @@ class ActivityMetricsLogger {
} }
logAppTransitionFinished(info, isHibernating != null ? isHibernating : false); logAppTransitionFinished(info, isHibernating != null ? isHibernating : false);
} }
info.mPendingDrawActivities.clear();
mTransitionInfoList.remove(info); mTransitionInfoList.remove(info);
} }
@@ -1122,7 +1082,7 @@ class ActivityMetricsLogger {
if (info == null) { if (info == null) {
return null; return null;
} }
if (!info.allDrawn() && info.mPendingFullyDrawn == null) { if (!info.mIsDrawn && info.mPendingFullyDrawn == null) {
// There are still undrawn activities, postpone reporting fully drawn until all of its // There are still undrawn activities, postpone reporting fully drawn until all of its
// windows are drawn. So that is closer to an usable state. // windows are drawn. So that is closer to an usable state.
info.mPendingFullyDrawn = () -> { info.mPendingFullyDrawn = () -> {

View File

@@ -477,7 +477,6 @@ public class ActivityMetricsLaunchObserverTests extends WindowTestsBase {
@Test @Test
public void testConsecutiveLaunch() { public void testConsecutiveLaunch() {
mTrampolineActivity.setState(ActivityRecord.State.INITIALIZING, "test");
onActivityLaunched(mTrampolineActivity); onActivityLaunched(mTrampolineActivity);
mActivityMetricsLogger.notifyActivityLaunching(mTopActivity.intent, mActivityMetricsLogger.notifyActivityLaunching(mTopActivity.intent,
mTrampolineActivity /* caller */, mTrampolineActivity.getUid()); mTrampolineActivity /* caller */, mTrampolineActivity.getUid());