Bug 975667 - gecko: hal: gonk: Emit battery level/charging notification. 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
This commit is contained in:
Bhavna Sharma 2014-05-29 15:12:00 +02:00
parent d55fb640f7
commit 0a52cde5de

View File

@ -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)
@ -290,6 +291,25 @@ public:
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;
}
};