Bug 1124127 - round power percentage to whole number before passing on, r=gsvelto
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Wed, 21 Jan 2015 14:06:40 +0000
changeset 226291 7d8d4ff84ddbfb2d6d2c8d882170921ce5de815f
parent 226290 638193021207c635767dd23c8861f70b6707431b
child 226292 13dd7bfcb9b1864327c8b5c2b69c739ef92befa0
push id54803
push usergijskruitbosch@gmail.com
push dateWed, 28 Jan 2015 15:51:03 +0000
treeherdermozilla-inbound@7d8d4ff84ddb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgsvelto
bugs1124127
milestone38.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 1124127 - round power percentage to whole number before passing on, r=gsvelto
hal/linux/UPowerClient.cpp
--- a/hal/linux/UPowerClient.cpp
+++ b/hal/linux/UPowerClient.cpp
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Hal.h"
 #include "HalLog.h"
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 #include <mozilla/dom/battery/Constants.h>
 #include "nsAutoRef.h"
+#include <cmath>
 
 /*
  * Helper that manages the destruction of glib objects as soon as they leave
  * the current scope.
  *
  * We are specializing nsAutoRef class.
  */
 
@@ -423,24 +424,24 @@ UPowerClient::UpdateSavedInfo(GHashTable
     case eState_Discharging:
     case eState_Empty:
     case eState_PendingDischarge:
       mCharging = false;
       break;
   }
 
   /*
-   * The battery level might be very close to 100% (like 99.xxxx%) without
+   * The battery level might be very close to 100% (like 99%) without
    * increasing. It seems that upower sets the battery state as 'full' in that
    * case so we should trust it and not even try to get the value.
    */
   if (isFull) {
     mLevel = 1.0;
   } else {
-    mLevel = g_value_get_double(static_cast<const GValue*>(g_hash_table_lookup(aHashTable, "Percentage")))*0.01;
+    mLevel = round(g_value_get_double(static_cast<const GValue*>(g_hash_table_lookup(aHashTable, "Percentage"))))*0.01;
   }
 
   if (isFull) {
     mRemainingTime = 0;
   } else {
     mRemainingTime = mCharging ? g_value_get_int64(static_cast<const GValue*>(g_hash_table_lookup(aHashTable, "TimeToFull")))
                                : g_value_get_int64(static_cast<const GValue*>(g_hash_table_lookup(aHashTable, "TimeToEmpty")));