Bug 1250106 - Correctly set charging status and remaining time when battery level is rounded to 1.0 r=bz
authorJames Willcox <snorp@snorp.net>
Thu, 03 Mar 2016 10:19:52 -0600
changeset 287260 acdcbd858ac363bd6feca72022d4cc8c370a604f
parent 287259 8ccab7d6447f8e4129c8e0735bfd7e8a7db063af
child 287261 48c1800e5b2c321c312894858328efe8df11a49e
push id30065
push userkwierso@gmail.com
push dateWed, 09 Mar 2016 00:01:05 +0000
treeherdermozilla-central@886b5480b578 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1250106
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1250106 - Correctly set charging status and remaining time when battery level is rounded to 1.0 r=bz
dom/battery/BatteryManager.cpp
--- a/dom/battery/BatteryManager.cpp
+++ b/dom/battery/BatteryManager.cpp
@@ -135,25 +135,28 @@ BatteryManager::UpdateFromBatteryInfo(co
 
   // Round to the nearest ten percent for non-chrome and non-certified apps
   nsIDocument* doc = GetOwner()->GetDoc();
   uint16_t status = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
   if (doc) {
     doc->NodePrincipal()->GetAppStatus(&status);
   }
 
+  mCharging = aBatteryInfo.charging();
+  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;
+    }
   }
 
-  mCharging = aBatteryInfo.charging();
-  mRemainingTime = aBatteryInfo.remainingTime();
-
   // 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 "
              "should be 0. Please fix your backend!");
   }
 }