Bug 797817 - Update the battery indicator led when receiving battery status change. r=cjones
authorBenjamin Chen <bechen@mozilla.com>
Mon, 22 Oct 2012 11:10:05 +0800
changeset 111270 e2e34182037317be0897425d288bea304b7a63eb
parent 111269 051bc70ec007d3824e4e70c015ccb3ee43a324e9
child 111271 3f97f6533a44627a41eb8aa6ba744d1d3180c409
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewerscjones
bugs797817
milestone19.0a1
Bug 797817 - Update the battery indicator led when receiving battery status change. r=cjones
hal/gonk/GonkHal.cpp
--- a/hal/gonk/GonkHal.cpp
+++ b/hal/gonk/GonkHal.cpp
@@ -78,16 +78,23 @@
 #ifndef OOM_SCORE_ADJ_MIN
 #define OOM_SCORE_ADJ_MIN  (-1000)
 #endif
 
 #ifndef OOM_SCORE_ADJ_MAX
 #define OOM_SCORE_ADJ_MAX  1000
 #endif
 
+#ifndef BATTERY_CHARGING_ARGB
+#define BATTERY_CHARGING_ARGB 0x00FF0000
+#endif
+#ifndef BATTERY_FULL_ARGB
+#define BATTERY_FULL_ARGB 0x0000FF00
+#endif
+
 using namespace mozilla;
 using namespace mozilla::hal;
 
 namespace mozilla {
 namespace hal_impl {
 
 namespace {
 
@@ -245,16 +252,36 @@ CancelVibrate(const hal::WindowIdentifie
 namespace {
 
 class BatteryUpdater : public nsRunnable {
 public:
   NS_IMETHOD Run()
   {
     hal::BatteryInformation info;
     hal_impl::GetCurrentBatteryInformation(&info);
+
+    // Control the battery indicator (led light) here using BatteryInformation
+    // we just retrieved.
+    uint32_t color = 0; // Format: 0x00rrggbb.
+    if (info.charging() && (info.level() == 1)) {
+      // Charging and battery full.
+      color = BATTERY_FULL_ARGB;
+    } else if (info.charging() && (info.level() < 1)) {
+      // Charging but not full.
+      color = BATTERY_CHARGING_ARGB;
+    } // else turn off battery indicator.
+
+    hal::LightConfiguration aConfig(hal::eHalLightID_Battery,
+                                    hal::eHalLightMode_User,
+                                    hal::eHalLightFlash_None,
+                                    0,
+                                    0,
+                                    color);
+    hal_impl::SetLight(hal::eHalLightID_Battery, aConfig);
+
     hal::NotifyBatteryChange(info);
     return NS_OK;
   }
 };
 
 } // anonymous namespace
 
 class BatteryObserver : public IUeventObserver,