Bug 1129882 - Add mozInterrupt in telephony object. r=baku

This commit is contained in:
Alastor Wu 2015-08-10 17:23:33 +08:00
parent 4e69f152f7
commit 215e13227f
2 changed files with 22 additions and 2 deletions

View File

@ -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<nsIGlobalObject> 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;
}

View File

@ -61,6 +61,8 @@ class Telephony final : public DOMEventTargetHelper,
bool mIsAudioStartPlaying;
uint32_t mAudioAgentNotify;
bool mHaveDispatchedInterruptBeginEvent;
bool mMuted;
public:
NS_DECL_ISUPPORTS_INHERITED