OSDN Git Service

Do not create EMPTY batterystats history file.
authorHui Yu <huiyu@google.com>
Fri, 31 May 2019 22:14:43 +0000 (15:14 -0700)
committerHui Yu <huiyu@google.com>
Fri, 31 May 2019 23:48:47 +0000 (23:48 +0000)
commite40781ee848f285fe88e3d9bea351a8a10df5dcc
tree3cf6ccfd81afdd9a5d805ce38ab7ae1dd8e2dc9e
parentbe8a41a604cfc601d997d962e8abadd668024310
Do not create EMPTY batterystats history file.

Previously when batterystats history buffer exceeds MAX_HISTORY_BUFFER
size, we create a new history file which is empty until batterystats
history buffer is written to the file. But the buffer is written to the
file every 30 minutes by default. When the file is empty, if the
system server process crashed or abrupt powered off, the file will remain
empty.

During the device bootup, batterystats reads history buffer from
the empty file and failed. The important mHistoryBaseTime variable is zero,
which causes all timestamps in subsequent history events are wrong, this
causes volta go/powerbug displays wrong, also Battery Usage in Settings
are wrong.

The fix is to not create new empty history file on disk until we actually
write history buffer to the file.

This problem can be manually reproduced by creating new empty file under
battery-history directory, then power off the device by long press power
button.

Bug: 133525277
Test: frameworks/base/core/tests/coretests/src/com/android/internal/os/BatteryStatsHistoryTest.java

Change-Id: I0c22881df6897e8832b472cc5e82fbf2727eb252
core/java/com/android/internal/os/BatteryStatsHistory.java
core/java/com/android/internal/os/BatteryStatsImpl.java
core/tests/coretests/src/com/android/internal/os/BatteryStatsHistoryTest.java