Skip to content

Commit

Permalink
Bug 975667 - gecko: hal: gonk: Emit battery level/charging notificati…
Browse files Browse the repository at this point in the history
…on. r=dhylands

The battery level and charging flag is now emitted from nsIObserverService
via the "gonkhal-battery-notifier" topic.  This can be useful to XPCOM
components that are not statically linked to Gecko.

The notification data is a IPropertyBag2 object.

Change-Id: Ia7b1faf3b66c19d6551d71ad554fd361c2614a22
  • Loading branch information
bhavsharma committed May 29, 2014
1 parent 3d1bd46 commit 9e7cf58
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions hal/gonk/GonkHal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "nsXULAppAPI.h"
#include "OrientationObserver.h"
#include "UeventPoller.h"
#include "nsIWritablePropertyBag2.h"
#include <algorithm>

#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
Expand Down Expand Up @@ -290,6 +291,25 @@ class BatteryUpdater : public nsRunnable {
hal_impl::SetLight(hal::eHalLightID_Battery, aConfig);

hal::NotifyBatteryChange(info);

{
// bug 975667
// Gecko gonk hal is required to emit battery charging/level notification via nsIObserverService.
// This is useful for XPCOM components that are not statically linked to Gecko and cannot call
// hal::EnableBatteryNotifications
nsCOMPtr<nsIObserverService> obsService = mozilla::services::GetObserverService();
nsCOMPtr<nsIWritablePropertyBag2> propbag =
do_CreateInstance("@mozilla.org/hash-property-bag;1");
if (obsService && propbag) {
propbag->SetPropertyAsBool(NS_LITERAL_STRING("charging"),
info.charging());
propbag->SetPropertyAsDouble(NS_LITERAL_STRING("level"),
info.level());

obsService->NotifyObservers(propbag, "gonkhal-battery-notifier", nullptr);
}
}

return NS_OK;
}
};
Expand Down

0 comments on commit 9e7cf58

Please sign in to comment.