diff --git a/dom/telephony/Telephony.cpp b/dom/telephony/Telephony.cpp index 75734c97e93..6aafc045ff4 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 77863fec624..bf99917facb 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