From c44c953812b90aa940f5991441be9cc4e2c746b3 Mon Sep 17 00:00:00 2001 From: Ben Francis Date: Wed, 15 Feb 2012 13:10:15 -0500 Subject: [PATCH] Bug 726612 - Gonk Battery API backend doesn't mark the device as charging when plugged to AC. r=mounir --- hal/gonk/GonkHal.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hal/gonk/GonkHal.cpp b/hal/gonk/GonkHal.cpp index c2abe7a2235..4c98315b003 100644 --- a/hal/gonk/GonkHal.cpp +++ b/hal/gonk/GonkHal.cpp @@ -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; }