Merge "Log when app move to foreground or background."

This commit is contained in:
TreeHugger Robot
2017-11-02 06:06:56 +00:00
committed by Android (Google) Code Review
2 changed files with 22 additions and 0 deletions

View File

@@ -71,6 +71,7 @@ message StatsEvent {
PhoneSignalStrengthChanged phone_signal_strength_changed = 40;
SettingChanged setting_changed = 41;
KernelWakelockPulled kernel_wakelock_pulled = 42;
ActivityForegroundStateChanged activity_foreground_state_changed = 43;
// TODO: Reorder the numbering so that the most frequent occur events occur in the first 15.
}
}
@@ -693,3 +694,20 @@ message KernelWakelockPulled {
optional int64 total_time = 3;
optional string name = 4;
}
/*
* Logs activity going to foreground or background
*
* Logged from:
* frameworks/base/services/core/java/com/android/server/am/ActivityRecord.java
*/
message ActivityForegroundStateChanged {
enum Activity {
MOVE_TO_BACKGROUND = 0;
MOVE_TO_FOREGROUND = 1;
}
optional int32 uid = 1;
optional string pkg_name = 2;
optional string class_name = 3;
optional Activity activity = 4;
}

View File

@@ -4043,10 +4043,14 @@ public class ActivityManagerService extends IActivityManager.Stub
if (DEBUG_SWITCH) Slog.d(TAG_SWITCH,
"updateUsageStats: comp=" + component + "res=" + resumed);
final BatteryStatsImpl stats = mBatteryStatsService.getActiveStatistics();
StatsLog.write(StatsLog.ACTIVITY_FOREGROUND_STATE_CHANGED,
component.userId, component.realActivity.getPackageName(),
component.realActivity.getShortClassName(), resumed ? 1 : 0);
if (resumed) {
if (mUsageStatsService != null) {
mUsageStatsService.reportEvent(component.realActivity, component.userId,
UsageEvents.Event.MOVE_TO_FOREGROUND);
}
synchronized (stats) {
stats.noteActivityResumedLocked(component.app.uid);