Loading services/core/java/com/android/server/am/ActiveServices.java +22 −0 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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 Loading Loading @@ -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) { Loading Loading @@ -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()) { Loading Loading @@ -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); Loading Loading @@ -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. Loading Loading @@ -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, Loading Loading @@ -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); } Loading Loading @@ -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 Loading Loading
services/core/java/com/android/server/am/ActiveServices.java +22 −0 Original line number Diff line number Diff line Loading @@ -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, Loading Loading @@ -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 Loading Loading @@ -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) { Loading Loading @@ -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()) { Loading Loading @@ -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); Loading Loading @@ -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. Loading Loading @@ -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, Loading Loading @@ -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); } Loading Loading @@ -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 Loading