From d346b69ee9e530383cf8263fe52b9952f7603798 Mon Sep 17 00:00:00 2001 From: Alexandre Lissy Date: Mon, 13 Aug 2012 16:57:51 +0200 Subject: [PATCH] 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. --- dom/system/gonk/AudioManager.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dom/system/gonk/AudioManager.cpp b/dom/system/gonk/AudioManager.cpp index 6db2163bf313..70d5d40da7f1 100644 --- a/dom/system/gonk/AudioManager.cpp +++ b/dom/system/gonk/AudioManager.cpp @@ -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 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()); } };