diff options
| -rw-r--r-- | cmds/statsd/src/atoms.proto | 21 | ||||
| -rw-r--r-- | services/core/java/com/android/server/am/ActiveServices.java | 8 |
2 files changed, 29 insertions, 0 deletions
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto index ed570e76a3d1..e58c53506c54 100644 --- a/cmds/statsd/src/atoms.proto +++ b/cmds/statsd/src/atoms.proto @@ -97,6 +97,7 @@ message Atom { BootSequenceReported boot_sequence_reported = 57; DaveyOccurred davey_occurred = 58; OverlayStateChanged overlay_state_changed = 59; + ForegroundServiceStateChanged foreground_service_state_changed = 60; // TODO: Reorder the numbering so that the most frequent occur events occur in the first 15. } @@ -998,6 +999,25 @@ message OverlayStateChanged { optional State state = 4; } +/* + * Logs foreground service starts and stops. + * Note that this is not when a service starts or stops, but when it is + * considered foreground. + * Logged from + * //frameworks/base/services/core/java/com/android/server/am/ActiveServices.java + */ +message ForegroundServiceStateChanged { + optional int32 uid = 1; + // package_name + "/" + class_name + optional string short_name = 2; + + enum State { + ENTER = 1; + EXIT = 2; + } + optional State state = 3; +} + /** * Pulls bytes transferred via wifi (Sum of foreground and background usage). * @@ -1463,3 +1483,4 @@ message RemainingBatteryCapacity { message FullBatteryCapacity { optional int32 capacity_uAh = 1; } + diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java index 2f7d4c1ec634..14404f5d4e4f 100644 --- a/services/core/java/com/android/server/am/ActiveServices.java +++ b/services/core/java/com/android/server/am/ActiveServices.java @@ -84,6 +84,7 @@ import android.os.UserHandle; import android.util.EventLog; import android.util.PrintWriterPrinter; import android.util.Slog; +import android.util.StatsLog; import android.util.SparseArray; import android.util.TimeUtils; import android.util.proto.ProtoOutputStream; @@ -1094,6 +1095,8 @@ public final class ActiveServices { active.mNumActive++; } r.isForeground = true; + StatsLog.write(StatsLog.FOREGROUND_SERVICE_STATE_CHANGED, r.userId, r.shortName, + StatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__ENTER); } r.postNotification(); if (r.app != null) { @@ -1109,6 +1112,8 @@ public final class ActiveServices { decActiveForegroundAppLocked(smap, r); } r.isForeground = false; + StatsLog.write(StatsLog.FOREGROUND_SERVICE_STATE_CHANGED, r.userId, r.shortName, + StatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__EXIT); if (r.app != null) { mAm.updateLruProcessLocked(r.app, false, null); updateServiceForegroundLocked(r.app, true); @@ -2533,7 +2538,10 @@ public final class ActiveServices { cancelForegroundNotificationLocked(r); if (r.isForeground) { decActiveForegroundAppLocked(smap, r); + StatsLog.write(StatsLog.FOREGROUND_SERVICE_STATE_CHANGED, r.userId, r.shortName, + StatsLog.FOREGROUND_SERVICE_STATE_CHANGED__STATE__EXIT); } + r.isForeground = false; r.foregroundId = 0; r.foregroundNoti = null; |