diff options
author | Hui Yu <huiyu@google.com> | 2019-09-03 17:45:49 -0700 |
---|---|---|
committer | Hui Yu <huiyu@google.com> | 2019-12-16 22:26:45 +0000 |
commit | 8d83364c5f882db3e30df432616068a95d459813 (patch) | |
tree | 21da7bf8e86500864b058f8ad65ff2929a3330cb /services/usage/java | |
parent | 402c7bb521361872547286f129026158ec952d1b (diff) |
[DO NOT MERGE] Better timestamp for shutdown and startup events.
Fix the bug that during android P to Q upgrade, DEVICE_SHUTDOWN
event mistakenly gets a newer timestamp than DEVICE_STARTUP event.
Bug: 139656029
Test: flash the device with android P, then upgrade to android Q,
then "adb shell dumpsys usagestats", observe DEVICE_SHUTDOWN
is before DEVICE_STARTUP.
Change-Id: I5429fe7648529be8379270adefd26bd98a31357c
Diffstat (limited to 'services/usage/java')
-rw-r--r-- | services/usage/java/com/android/server/usage/UserUsageStatsService.java | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/services/usage/java/com/android/server/usage/UserUsageStatsService.java b/services/usage/java/com/android/server/usage/UserUsageStatsService.java index 11c0e4abdb35..9fc1949183f8 100644 --- a/services/usage/java/com/android/server/usage/UserUsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UserUsageStatsService.java @@ -136,17 +136,16 @@ class UserUsageStatsService { } // During system reboot, add a DEVICE_SHUTDOWN event to the end of event list, the timestamp - // is last time UsageStatsDatabase is persisted to disk. + // is last time UsageStatsDatabase is persisted to disk or the last event's time whichever + // is higher (because the file system timestamp is round down to integral seconds). // Also add a DEVICE_STARTUP event with current system timestamp. final IntervalStats currentDailyStats = mCurrentStats[INTERVAL_DAILY]; if (currentDailyStats != null) { - // File system timestamp only has precision of 1 second, add 1000ms to make up - // for the loss of round up. - final Event shutdownEvent = - new Event(DEVICE_SHUTDOWN, currentDailyStats.lastTimeSaved + 1000); + final Event shutdownEvent = new Event(DEVICE_SHUTDOWN, + Math.max(currentDailyStats.lastTimeSaved, currentDailyStats.endTime)); shutdownEvent.mPackage = Event.DEVICE_EVENT_PACKAGE_NAME; currentDailyStats.addEvent(shutdownEvent); - final Event startupEvent = new Event(DEVICE_STARTUP, currentTimeMillis); + final Event startupEvent = new Event(DEVICE_STARTUP, System.currentTimeMillis()); startupEvent.mPackage = Event.DEVICE_EVENT_PACKAGE_NAME; currentDailyStats.addEvent(startupEvent); } |