Bug 726612 - Gonk Battery API backend doesn't mark the device as charging when plugged to AC. r=mounir

This commit is contained in:
Ben Francis 2012-02-15 13:10:15 -05:00
parent 9ab74fadea
commit c44c953812

View File

@ -256,6 +256,10 @@ DisableBatteryNotifications()
void
GetCurrentBatteryInformation(hal::BatteryInformation *aBatteryInfo)
{
static const int BATTERY_NOT_CHARGING = 0;
static const int BATTERY_CHARGING_USB = 1;
static const int BATTERY_CHARGING_AC = 2;
FILE *capacityFile = fopen("/sys/class/power_supply/battery/capacity", "r");
double capacity = dom::battery::kDefaultLevel * 100;
if (capacityFile) {
@ -270,8 +274,17 @@ GetCurrentBatteryInformation(hal::BatteryInformation *aBatteryInfo)
fclose(chargingFile);
}
#ifdef DEBUG
if (chargingSrc != BATTERY_NOT_CHARGING &&
chargingSrc != BATTERY_CHARGING_USB &&
chargingSrc != BATTERY_CHARGING_AC) {
HAL_LOG(("charging_source contained unknown value: %d", chargingSrc));
}
#endif
aBatteryInfo->level() = capacity / 100;
aBatteryInfo->charging() = chargingSrc == 1;
aBatteryInfo->charging() = (chargingSrc == BATTERY_CHARGING_USB ||
chargingSrc == BATTERY_CHARGING_AC);
aBatteryInfo->remainingTime() = dom::battery::kUnknownRemainingTime;
}