Skip to content
Snippets Groups Projects
Commit 1acf06a6 authored by Todd Poynor's avatar Todd Poynor
Browse files

BatteryStats: Don't collect battery stats if no battery

If the device has no battery, or has a removeable battery that is
currently removed, do not collect battery statistics.

Bug: 34507420
Test: manual: dumpsys batterystats
Change-Id: Id8edb494f353a40c648f798690f611f89f464d34
parent 10adc355
No related branches found
No related tags found
No related merge requests found
......@@ -11228,7 +11228,9 @@ public class BatteryStatsImpl extends BatteryStats {
reportChangesToStatsLog(mHaveBatteryLevel ? mHistoryCur : null,
status, plugType, level, temp);
 
final boolean onBattery = plugType == BATTERY_PLUGGED_NONE;
final boolean onBattery =
plugType == BATTERY_PLUGGED_NONE &&
status != BatteryManager.BATTERY_STATUS_UNKNOWN;
final long uptime = mClocks.uptimeMillis();
final long elapsedRealtime = mClocks.elapsedRealtime();
if (!mHaveBatteryLevel) {
......@@ -11262,7 +11264,8 @@ public class BatteryStatsImpl extends BatteryStats {
mRecordingHistory = true;
startRecordingHistory(elapsedRealtime, uptime, true);
}
} else if (level < 96) {
} else if (level < 96 &&
status != BatteryManager.BATTERY_STATUS_UNKNOWN) {
if (!mRecordingHistory) {
mRecordingHistory = true;
startRecordingHistory(elapsedRealtime, uptime, true);
......@@ -11400,9 +11403,12 @@ public class BatteryStatsImpl extends BatteryStats {
addHistoryRecordLocked(elapsedRealtime, uptime);
}
}
if (!onBattery && status == BatteryManager.BATTERY_STATUS_FULL) {
// We don't record history while we are plugged in and fully charged.
// The next time we are unplugged, history will be cleared.
if (!onBattery &&
(status == BatteryManager.BATTERY_STATUS_FULL ||
status == BatteryManager.BATTERY_STATUS_UNKNOWN)) {
// We don't record history while we are plugged in and fully charged
// (or when battery is not present). The next time we are
// unplugged, history will be cleared.
mRecordingHistory = DEBUG;
}
 
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment