mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
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:
parent
3d1bd46584
commit
9e7cf58a54
@ -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;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user