Bug 1250106 - Correctly set charging status and remaining time when battery level is rounded to 1.0 r=bz
☠☠ backed out by fb5b94df3eca ☠ ☠
authorJames Willcox <snorp@snorp.net>
Thu, 03 Mar 2016 10:19:52 -0600
changeset 338015 7bb636bd183b96f1c61ee24cd67da024d699c69c
parent 338014 4beeb84a6696c4c25357899cee3ce90576914c11
child 338016 f4aec1239d76cc678e3b06edf4741096440faf85
push id12405
push usercku@mozilla.com
push dateTue, 08 Mar 2016 03:35:29 +0000
reviewersbz
bugs1250106
milestone47.0a1
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,29 @@ 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) {
+      mCharging = false;
+      mRemainingTime = kDefaultRemainingTime;
+    }
   }
 
-  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!");
   }
 }