Merge "Add trace points to service related events" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
41d88dd57b
@@ -762,6 +762,15 @@ public final class ActiveServices {
|
||||
}
|
||||
}
|
||||
|
||||
private static void traceInstant(@NonNull String message, @NonNull ServiceRecord service) {
|
||||
if (!Trace.isTagEnabled(Trace.TRACE_TAG_ACTIVITY_MANAGER)) {
|
||||
return;
|
||||
}
|
||||
final String serviceName = (service.getComponentName() != null)
|
||||
? service.getComponentName().toShortString() : "(?)";
|
||||
Trace.instant(Trace.TRACE_TAG_ACTIVITY_MANAGER, message + serviceName);
|
||||
}
|
||||
|
||||
ComponentName startServiceLocked(IApplicationThread caller, Intent service, String resolvedType,
|
||||
int callingPid, int callingUid, boolean fgRequired, String callingPackage,
|
||||
@Nullable String callingFeatureId, final int userId, boolean isSdkSandboxService,
|
||||
@@ -818,6 +827,9 @@ public final class ActiveServices {
|
||||
}
|
||||
|
||||
ServiceRecord r = res.record;
|
||||
|
||||
traceInstant("startService(): ", r);
|
||||
|
||||
// Note, when startService() or startForegroundService() is called on an already
|
||||
// running SHORT_SERVICE FGS, the call will succeed (i.e. we won't throw
|
||||
// ForegroundServiceStartNotAllowedException), even when the service is already timed
|
||||
@@ -1407,6 +1419,7 @@ public final class ActiveServices {
|
||||
}
|
||||
|
||||
private void stopServiceLocked(ServiceRecord service, boolean enqueueOomAdj) {
|
||||
traceInstant("stopService(): ", service);
|
||||
try {
|
||||
Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "stopServiceLocked()");
|
||||
if (service.delayed) {
|
||||
@@ -1946,6 +1959,7 @@ public final class ActiveServices {
|
||||
if (notification == null) {
|
||||
throw new IllegalArgumentException("null notification");
|
||||
}
|
||||
traceInstant("startForeground(): ", r);
|
||||
final int foregroundServiceStartType = foregroundServiceType;
|
||||
// Instant apps need permission to create foreground services.
|
||||
if (r.appInfo.isInstantApp()) {
|
||||
@@ -2484,6 +2498,7 @@ public final class ActiveServices {
|
||||
}
|
||||
} else {
|
||||
if (r.isForeground) {
|
||||
traceInstant("stopForeground(): ", r);
|
||||
final ServiceMap smap = getServiceMapLocked(r.userId);
|
||||
if (smap != null) {
|
||||
decActiveForegroundAppLocked(smap, r);
|
||||
@@ -3311,6 +3326,7 @@ public final class ActiveServices {
|
||||
Slog.i(TAG_SERVICE, "Short FGS started: " + sr);
|
||||
}
|
||||
}
|
||||
traceInstant("short FGS start/extend: ", sr);
|
||||
sr.setShortFgsInfo(SystemClock.uptimeMillis());
|
||||
|
||||
// We'll restart the timeout.
|
||||
@@ -3356,6 +3372,8 @@ public final class ActiveServices {
|
||||
return;
|
||||
}
|
||||
Slog.e(TAG_SERVICE, "Short FGS timed out: " + sr);
|
||||
traceInstant("short FGS timeout: ", sr);
|
||||
|
||||
logFGSStateChangeLocked(sr,
|
||||
FOREGROUND_SERVICE_STATE_CHANGED__STATE__TIMED_OUT,
|
||||
nowUptime > sr.mFgsEnterTime ? (int) (nowUptime - sr.mFgsEnterTime) : 0,
|
||||
@@ -3409,6 +3427,7 @@ public final class ActiveServices {
|
||||
}
|
||||
|
||||
Slog.e(TAG_SERVICE, "Short FGS procstate demoted: " + sr);
|
||||
traceInstant("short FGS demote: ", sr);
|
||||
|
||||
mAm.updateOomAdjLocked(sr.app, OOM_ADJ_REASON_SHORT_FGS_TIMEOUT);
|
||||
}
|
||||
@@ -3439,6 +3458,9 @@ public final class ActiveServices {
|
||||
} else {
|
||||
Slog.e(TAG_SERVICE, message);
|
||||
}
|
||||
|
||||
traceInstant("short FGS ANR: ", sr);
|
||||
|
||||
mAm.appNotResponding(sr.app, tr);
|
||||
|
||||
// TODO: Can we close the ANR dialog here, if it's still shown? Currently, the ANR
|
||||
|
||||
Reference in New Issue
Block a user