From 1a93cb3c1b9755256e7f2feeb50ef772572e4de5 Mon Sep 17 00:00:00 2001 From: Alastor Wu Date: Mon, 10 Aug 2015 17:23:33 +0800 Subject: [PATCH] Bug 1129882 - Add mozInterrupt in telephony object. r=baku --HG-- extra : rebase_source : 2e68e3ad3a7711ea65bc0167a0e9a5aaa65e3bf7 extra : source : 9c6fde246f6e673154b03d20768b3159c16f1fe9 --- dom/telephony/Telephony.cpp | 22 ++++++++++++++++++++-- dom/telephony/Telephony.h | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/dom/telephony/Telephony.cpp b/dom/telephony/Telephony.cpp index 75734c97e93c..6aafc045ff4e 100644 --- a/dom/telephony/Telephony.cpp +++ b/dom/telephony/Telephony.cpp @@ -21,7 +21,7 @@ #include "nsServiceManagerUtils.h" #include "nsThreadUtils.h" -#include "AudioChannelAgent.h" +#include "AudioChannelService.h" #include "CallsList.h" #include "TelephonyCall.h" #include "TelephonyCallGroup.h" @@ -66,7 +66,8 @@ public: Telephony::Telephony(nsPIDOMWindow* aOwner) : DOMEventTargetHelper(aOwner), mIsAudioStartPlaying(false), - mAudioAgentNotify(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY) + mAudioAgentNotify(nsIAudioChannelAgent::AUDIO_AGENT_NOTIFY), + mHaveDispatchedInterruptBeginEvent(false) { MOZ_ASSERT(aOwner); nsCOMPtr global = do_QueryInterface(aOwner); @@ -77,6 +78,7 @@ Telephony::Telephony(nsPIDOMWindow* aOwner) MOZ_ASSERT(!rv.Failed()); mReadyPromise = promise; + mMuted = AudioChannelService::IsAudioChannelMutedByDefault(); } Telephony::~Telephony() @@ -681,6 +683,22 @@ Telephony::WindowVolumeChanged(float aVolume, bool aMuted) return rv.StealNSResult(); } + // These events will be triggered when the telephony is interrupted by other + // audio channel. + if (mMuted != aMuted) { + mMuted = aMuted; + // We should not dispatch "mozinterruptend" when the system app initializes + // the telephony audio from muted to unmuted at the first time. The event + // "mozinterruptend" must be dispatched after the "mozinterruptbegin". + if (!mHaveDispatchedInterruptBeginEvent && mMuted) { + DispatchTrustedEvent(NS_LITERAL_STRING("mozinterruptbegin")); + mHaveDispatchedInterruptBeginEvent = mMuted; + } else if (mHaveDispatchedInterruptBeginEvent && !mMuted) { + DispatchTrustedEvent(NS_LITERAL_STRING("mozinterruptend")); + mHaveDispatchedInterruptBeginEvent = mMuted; + } + } + return NS_OK; } diff --git a/dom/telephony/Telephony.h b/dom/telephony/Telephony.h index 77863fec624a..bf99917facb9 100644 --- a/dom/telephony/Telephony.h +++ b/dom/telephony/Telephony.h @@ -61,6 +61,8 @@ class Telephony final : public DOMEventTargetHelper, bool mIsAudioStartPlaying; uint32_t mAudioAgentNotify; + bool mHaveDispatchedInterruptBeginEvent; + bool mMuted; public: NS_DECL_ISUPPORTS_INHERITED