Bug 727287 - Battery support for akami devices [r=mounir]
authorFabrice Desré <fabrice@mozilla.com>
Thu, 16 Feb 2012 14:40:43 -0800
changeset 89928 956fe683561ce651f30bfbff9fd36f26d0e245bd
parent 89927 373679b399185a5f84cc40592c3736d20c900e5a
child 89929 8ae2b959b51dc0ca2020104bd82dd461aa729027
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
bugs727287
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 727287 - Battery support for akami devices [r=mounir]
hal/gonk/GonkHal.cpp
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -263,20 +263,39 @@ GetCurrentBatteryInformation(hal::Batter
   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;
+  int chargingSrc = BATTERY_CHARGING_USB;
+  bool done = false;
   if (chargingFile) {
     fscanf(chargingFile, "%d", &chargingSrc);
     fclose(chargingFile);
+    done = true;
+  }
+
+  if (!done) {
+    // toro devices support
+    chargingFile = fopen("/sys/class/power_supply/battery/status", "r");
+    if (chargingFile) {
+      char status[16];
+      fscanf(chargingFile, "%s", &status);
+      if (!strcmp(status, "Charging") || !strcmp(status, "Full")) {
+        // no way here to know if we're charging from USB or AC.
+        chargingSrc = BATTERY_CHARGING_USB;
+      } else {
+        chargingSrc = BATTERY_NOT_CHARGING;
+      }
+      fclose(chargingFile);
+      done = true;
+    }
   }
 
   #ifdef DEBUG
   if (chargingSrc != BATTERY_NOT_CHARGING &&
       chargingSrc != BATTERY_CHARGING_USB &&
       chargingSrc != BATTERY_CHARGING_AC) {
     HAL_LOG(("charging_source contained unknown value: %d", chargingSrc));
   }