Bug 1191918 - Round battery level to nearest 10% r=bz

This commit is contained in:
James Willcox 2015-08-10 15:20:37 -05:00
Родитель 83c3255308
Коммит e027a0e412
2 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <cmath>
#include <limits>
#include "BatteryManager.h"
#include "Constants.h"
@ -12,6 +13,7 @@
#include "mozilla/dom/BatteryManagerBinding.h"
#include "mozilla/Preferences.h"
#include "nsIDOMClassInfo.h"
#include "nsIDocument.h"
/**
* We have to use macros here because our leak analysis tool things we are
@ -129,6 +131,23 @@ void
BatteryManager::UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo)
{
mLevel = aBatteryInfo.level();
// 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);
}
if (!nsContentUtils::IsChromeDoc(doc) &&
status != nsIPrincipal::APP_STATUS_CERTIFIED)
{
mLevel = 0.292f;
printf_stderr("SNORP: battery level before rounding: %lf\n", mLevel);
mLevel = lround(mLevel * 10.0) / 10.0;
printf_stderr("SNORP: battery level after rounding: %lf\n", mLevel);
}
mCharging = aBatteryInfo.charging();
mRemainingTime = aBatteryInfo.remainingTime();

Просмотреть файл

@ -66,10 +66,14 @@ private:
*/
void UpdateFromBatteryInfo(const hal::BatteryInformation& aBatteryInfo);
/**
* Represents the battery level, ranging from 0.0 (dead or removed?)
* to 1.0 (fully charged)
*/
double mLevel;
bool mCharging;
/**
* Represents the discharging time or the charging time, dpending on the
* Represents the discharging time or the charging time, depending on the
* current battery status (charging or not).
*/
double mRemainingTime;