Bug 782289 - Headphones status notification. Part 1: Send observer notification. r=philikon

We send this notification each time status change. For now, only on/off, maybe
it might be a good thing to add microphone status too. We will observe
this notification in b2g's shell.js to generate a mozChromeEvent.
This commit is contained in:
Alexandre Lissy 2012-08-13 16:57:51 +02:00
Родитель 5e77bcbda8
Коммит d346b69ee9
1 изменённых файлов: 18 добавлений и 0 удалений

Просмотреть файл

@ -18,6 +18,8 @@
#include "mozilla/Hal.h"
#include "AudioManager.h"
#include "gonk/AudioSystem.h"
#include "nsIObserverService.h"
#include "mozilla/Services.h"
using namespace mozilla::dom::gonk;
using namespace android;
@ -53,11 +55,27 @@ InternalSetAudioRoutes(SwitchState aState)
}
}
static void
NotifyHeadphonesStatus(SwitchState aState)
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
if (aState == SWITCH_STATE_ON) {
obs->NotifyObservers(nullptr, "headphones-status", NS_LITERAL_STRING("on").get());
} else if (aState == SWITCH_STATE_OFF) {
obs->NotifyObservers(nullptr, "headphones-status", NS_LITERAL_STRING("off").get());
} else {
obs->NotifyObservers(nullptr, "headphones-status", NS_LITERAL_STRING("unknown").get());
}
}
}
class HeadphoneSwitchObserver : public SwitchObserver
{
public:
void Notify(const SwitchEvent& aEvent) {
InternalSetAudioRoutes(aEvent.status());
NotifyHeadphonesStatus(aEvent.status());
}
};