Bug 1292655 - Limit BatteryManager chargingTime/dischargingTime precision. r=baku
authorTom Schuster <evilpies@gmail.com>
Tue, 16 Aug 2016 22:56:21 +0200
changeset 335491 a0a05115cfe81172d63eb64b07d2435836072409
parent 335490 6a6829ccc2b43074b8f3542b3db3213224502eab
child 335492 122c43944c570beacf0b8140b3d65192dbb73e8a
push id10033
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:50:26 +0000
treeherdermozilla-aurora@5dddbefdf759 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1292655
milestone51.0a1
Bug 1292655 - Limit BatteryManager chargingTime/dischargingTime precision. r=baku
dom/battery/BatteryManager.cpp
--- a/dom/battery/BatteryManager.cpp
+++ b/dom/battery/BatteryManager.cpp
@@ -144,16 +144,21 @@ BatteryManager::UpdateFromBatteryInfo(co
   mRemainingTime = aBatteryInfo.remainingTime();
 
   if (!nsContentUtils::IsChromeDoc(doc) &&
       status != nsIPrincipal::APP_STATUS_CERTIFIED)
   {
     mLevel = lround(mLevel * 10.0) / 10.0;
     if (mLevel == 1.0) {
       mRemainingTime = mCharging ? kDefaultRemainingTime : kUnknownRemainingTime;
+    } else if (mRemainingTime != kUnknownRemainingTime) {
+      // Round the remaining time to a multiple of 15 minutes and never zero
+      const double MINUTES_15 = 15.0 * 60.0;
+      mRemainingTime = fmax(lround(mRemainingTime / MINUTES_15) * MINUTES_15,
+                            MINUTES_15);
     }
   }
 
   // Add some guards to make sure the values are coherent.
   if (mLevel == 1.0 && mCharging == true &&
       mRemainingTime != kDefaultRemainingTime) {
     mRemainingTime = kDefaultRemainingTime;
     NS_ERROR("Battery API: When charging and level at 1.0, remaining time "