diff options
author | Adam Lesinski <adamlesinski@google.com> | 2015-06-12 15:18:06 -0700 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2015-06-12 15:18:06 -0700 |
commit | f4013aa4f7f9ba0010840c20fd747b73880f3d74 (patch) | |
tree | fdd4c1e14e632355c8fd984599dd956675d4d0d9 | |
parent | 6cb8e30bb7e79cb694bf44d185da201e9deb9363 (diff) | |
download | frameworks_base-f4013aa4f7f9ba0010840c20fd747b73880f3d74.zip frameworks_base-f4013aa4f7f9ba0010840c20fd747b73880f3d74.tar.gz frameworks_base-f4013aa4f7f9ba0010840c20fd747b73880f3d74.tar.bz2 |
BatteryStats: Wifi energy data is sometimes wrong
Wifi energy data sometimes reports negative values. The bug
is filed, but in the meanwhile, batterystats calculations
are way off due to strange values.
Now we ignore invalid data, and sample again later.
Bug:21613534
Change-Id: I3c5c1385e15d85346e6fd3a2737cb58ca706ab74
-rw-r--r-- | services/core/java/com/android/server/am/BatteryStatsService.java | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/services/core/java/com/android/server/am/BatteryStatsService.java b/services/core/java/com/android/server/am/BatteryStatsService.java index b97fa69..b56e326 100644 --- a/services/core/java/com/android/server/am/BatteryStatsService.java +++ b/services/core/java/com/android/server/am/BatteryStatsService.java @@ -1113,23 +1113,32 @@ public final class BatteryStatsService extends IBatteryStats.Stub // correct delta from when we should start reading (aka when we are on battery). WifiActivityEnergyInfo info = mWifiManager.reportActivityInfo(); if (info != null && info.isValid()) { + if (info.mControllerEnergyUsed < 0 || info.mControllerIdleTimeMs < 0 || + info.mControllerRxTimeMs < 0 || info.mControllerTxTimeMs < 0) { + Slog.wtf(TAG, "Reported WiFi energy data is invalid: " + info); + return null; + } + // We will modify the last info object to be the delta, and store the new // WifiActivityEnergyInfo object as our last one. final WifiActivityEnergyInfo result = mLastInfo; result.mTimestamp = info.getTimeStamp(); result.mStackState = info.getStackState(); + + // These times seem to be the most reliable. result.mControllerTxTimeMs = info.mControllerTxTimeMs - mLastInfo.mControllerTxTimeMs; result.mControllerRxTimeMs = info.mControllerRxTimeMs - mLastInfo.mControllerRxTimeMs; - result.mControllerEnergyUsed = - info.mControllerEnergyUsed - mLastInfo.mControllerEnergyUsed; // WiFi calculates the idle time as a difference from the on time and the various // Rx + Tx times. There seems to be some missing time there because this sometimes // becomes negative. Just cap it at 0 and move on. + // b/21613534 result.mControllerIdleTimeMs = Math.max(0, info.mControllerIdleTimeMs - mLastInfo.mControllerIdleTimeMs); + result.mControllerEnergyUsed = + Math.max(0, info.mControllerEnergyUsed - mLastInfo.mControllerEnergyUsed); if (result.mControllerTxTimeMs < 0 || result.mControllerRxTimeMs < 0) { |