Populate WaitResult with AML data for hot launches

Make the time of "am start -W" and metrics log are consistent.

Bug: 120981435
Bug: 123355661
Test: atest ActivityMetricsLoggerTests# \
            testAppHotLaunchSetsWaitResultDelayData

Change-Id: I83a249146763e866048f7c4f92ec584b5fb4e4f0
This commit is contained in:
Riddle Hsu
2019-10-31 13:34:27 +08:00
parent c504244125
commit c48c89150b
4 changed files with 20 additions and 18 deletions

View File

@@ -823,7 +823,14 @@ class ActivityMetricsLogger {
return StatsLog.APP_START_OCCURRED__TYPE__HOT;
}
return StatsLog.APP_START_OCCURRED__TYPE__UNKNOWN;
}
}
/** @return the last known window drawn delay of the given windowing mode. */
int getLastDrawnDelayMs(@WindowingMode int windowingMode) {
final WindowingModeTransitionInfo info = mLastWindowingModeTransitionInfo.get(
windowingMode);
return info != null ? info.windowsDrawnDelayMs : INVALID_DELAY;
}
WindowingModeTransitionInfoSnapshot logAppTransitionReportedDrawn(ActivityRecord r,
boolean restoredFromBundle) {

View File

@@ -5122,7 +5122,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
final @LaunchState int launchState = info != null ? info.getLaunchState() : -1;
mStackSupervisor.reportActivityLaunchedLocked(false /* timeout */, this,
windowsDrawnDelayMs, launchState);
mStackSupervisor.stopWaitingForActivityVisible(this);
mStackSupervisor.stopWaitingForActivityVisible(this, windowsDrawnDelayMs);
finishLaunchTickingLocked();
if (task != null) {
task.hasBeenVisible = true;

View File

@@ -561,8 +561,8 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
return candidateTaskId;
}
void waitActivityVisible(ComponentName name, WaitResult result, long startTimeMs) {
final WaitInfo waitInfo = new WaitInfo(name, result, startTimeMs);
void waitActivityVisible(ComponentName name, WaitResult result) {
final WaitInfo waitInfo = new WaitInfo(name, result);
mWaitingForActivityVisible.add(waitInfo);
}
@@ -572,10 +572,15 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
// down to the max limit while they are still waiting to finish.
mFinishingActivities.remove(r);
stopWaitingForActivityVisible(r);
stopWaitingForActivityVisible(r, WaitResult.INVALID_DELAY);
}
void stopWaitingForActivityVisible(ActivityRecord r) {
stopWaitingForActivityVisible(r,
getActivityMetricsLogger().getLastDrawnDelayMs(r.getWindowingMode()));
}
void stopWaitingForActivityVisible(ActivityRecord r, long totalTime) {
boolean changed = false;
for (int i = mWaitingForActivityVisible.size() - 1; i >= 0; --i) {
final WaitInfo w = mWaitingForActivityVisible.get(i);
@@ -584,7 +589,7 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
changed = true;
result.timeout = false;
result.who = w.getComponent();
result.totalTime = SystemClock.uptimeMillis() - w.getStartTime();
result.totalTime = totalTime;
mWaitingForActivityVisible.remove(w);
}
}
@@ -2823,13 +2828,10 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
static class WaitInfo {
private final ComponentName mTargetComponent;
private final WaitResult mResult;
/** Time stamp when we started to wait for {@link WaitResult}. */
private final long mStartTimeMs;
WaitInfo(ComponentName targetComponent, WaitResult result, long startTimeMs) {
WaitInfo(ComponentName targetComponent, WaitResult result) {
this.mTargetComponent = targetComponent;
this.mResult = result;
this.mStartTimeMs = startTimeMs;
}
public boolean matches(ComponentName targetComponent) {
@@ -2840,10 +2842,6 @@ public class ActivityStackSupervisor implements RecentTasks.Callbacks {
return mResult;
}
public long getStartTime() {
return mStartTimeMs;
}
public ComponentName getComponent() {
return mTargetComponent;
}

View File

@@ -107,7 +107,6 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
@@ -764,9 +763,7 @@ class ActivityStarter {
mRequest.waitResult.who = r.mActivityComponent;
mRequest.waitResult.totalTime = 0;
} else {
final long startTimeMs = SystemClock.uptimeMillis();
mSupervisor.waitActivityVisible(r.mActivityComponent, mRequest.waitResult,
startTimeMs);
mSupervisor.waitActivityVisible(r.mActivityComponent, mRequest.waitResult);
// Note: the timeout variable is not currently not ever set.
do {
try {