Bug 726612 - Gonk Battery API backend doesn't mark the device as charging when plugged to AC. r=mounir
authorBen Francis <ben@krellian.com>
Wed, 15 Feb 2012 13:10:15 -0500
changeset 89798 ebcae0510986e90119ba65ea1e799d0affcd4b5f
parent 89797 0016309e3d7f14aa573bd79e64cd7acbca467d24
child 89799 25949048af3d368866bb879928fa59e49aaf899d
push id783
push userlsblakk@mozilla.com
push dateTue, 24 Apr 2012 17:33:42 +0000
treeherdermozilla-beta@11faed19f136 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs726612
milestone13.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 726612 - Gonk Battery API backend doesn't mark the device as charging when plugged to AC. r=mounir
hal/gonk/GonkHal.cpp
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -251,32 +251,45 @@ DisableBatteryNotifications()
   sWatcherThread->Shutdown();
   NS_IF_RELEASE(sWatcherThread);
   delete sWatcher;
 }
 
 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) {
     fscanf(capacityFile, "%lf", &capacity);
     fclose(capacityFile);
   }
 
   FILE *chargingFile = fopen("/sys/class/power_supply/battery/charging_source", "r");
   int chargingSrc = 1;
   if (chargingFile) {
     fscanf(chargingFile, "%d", &chargingSrc);
     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;
 }
 
 namespace {
 
 /**
  * RAII class to help us remember to close file descriptors.
  */