From d5dbd9640b2d0691447f7bf845143cac181cc889 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Fri, 25 Jan 2013 13:24:08 +0100 Subject: [PATCH] Bug 832665 - Switching back and forth between the music app and FM radio (using home key) causes some unexpected behavior., r=mchen, a=tef+ --- dom/audiochannel/AudioChannelService.cpp | 51 +++++++++++++----------- dom/audiochannel/AudioChannelService.h | 5 ++- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/dom/audiochannel/AudioChannelService.cpp b/dom/audiochannel/AudioChannelService.cpp index 31eae6a3d3ba..bcb6078441bc 100644 --- a/dom/audiochannel/AudioChannelService.cpp +++ b/dom/audiochannel/AudioChannelService.cpp @@ -67,6 +67,7 @@ NS_IMPL_ISUPPORTS0(AudioChannelService) AudioChannelService::AudioChannelService() : mCurrentHigherChannel(AUDIO_CHANNEL_LAST) +, mActiveContentChildIDsFrozen(false) { // Creation of the hash table. mAgents.Init(); @@ -169,6 +170,27 @@ AudioChannelService::GetMutedInternal(AudioChannelType aType, uint64_t aChildID, mChannelCounters[oldType].RemoveElement(aChildID); } + // If the audio content channel is visible, let's remember this ChildID. + if (newType == AUDIO_CHANNEL_INT_CONTENT && + oldType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN && + !mActiveContentChildIDs.Contains(aChildID)) { + + if (mActiveContentChildIDsFrozen) { + mActiveContentChildIDsFrozen = false; + mActiveContentChildIDs.Clear(); + } + + mActiveContentChildIDs.AppendElement(aChildID); + } + + // If nothing is visible, the list has to been frozen. + else if (newType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN && + oldType == AUDIO_CHANNEL_INT_CONTENT && + !mActiveContentChildIDsFrozen && + mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty()) { + mActiveContentChildIDsFrozen = true; + } + // Let play any visible audio channel. if (!aElementHidden) { return false; @@ -179,8 +201,7 @@ AudioChannelService::GetMutedInternal(AudioChannelType aType, uint64_t aChildID, // We are not visible, maybe we have to mute. if (newType == AUDIO_CHANNEL_INT_NORMAL_HIDDEN || (newType == AUDIO_CHANNEL_INT_CONTENT_HIDDEN && - (!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT].IsEmpty() || - HasMoreThanOneContentChannelHidden()))) { + !mActiveContentChildIDs.Contains(aChildID))) { muted = true; } @@ -199,25 +220,6 @@ AudioChannelService::ContentChannelIsActive() !mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].IsEmpty(); } -bool -AudioChannelService::HasMoreThanOneContentChannelHidden() -{ - uint32_t childId = CONTENT_PARENT_UNKNOWN_CHILD_ID; - bool empty = true; - for (uint32_t i = 0; - i < mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].Length(); - ++i) { - if (empty) { - childId = mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN][i]; - empty = false; - } else if (childId != mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN][i]) { - return true; - } - } - - return false; -} - void AudioChannelService::SendAudioChannelChangedNotification() { @@ -279,8 +281,7 @@ AudioChannelService::SendAudioChannelChangedNotification() } // Content channels play in background if just one is active. - else if ((!mChannelCounters[AUDIO_CHANNEL_INT_CONTENT_HIDDEN].IsEmpty() && - !HasMoreThanOneContentChannelHidden())) { + else if (!mActiveContentChildIDs.IsEmpty()) { higher = AUDIO_CHANNEL_CONTENT; } @@ -391,6 +392,10 @@ AudioChannelService::Observe(nsISupports* aSubject, const char* aTopic, const PR while ((index = mChannelCounters[type].IndexOf(childID)) != -1) { mChannelCounters[type].RemoveElementAt(index); } + + if ((index = mActiveContentChildIDs.IndexOf(childID)) != -1) { + mActiveContentChildIDs.RemoveElementAt(index); + } } // We don't have to remove the agents from the mAgents hashtable because if diff --git a/dom/audiochannel/AudioChannelService.h b/dom/audiochannel/AudioChannelService.h index 86efb132e890..b8222fb1938f 100644 --- a/dom/audiochannel/AudioChannelService.h +++ b/dom/audiochannel/AudioChannelService.h @@ -98,8 +98,6 @@ protected: bool ChannelsActiveWithHigherPriorityThan(AudioChannelInternalType aType); - bool HasMoreThanOneContentChannelHidden(); - const char* ChannelName(AudioChannelType aType); AudioChannelInternalType GetInternalType(AudioChannelType aType, @@ -130,6 +128,9 @@ protected: AudioChannelType mCurrentHigherChannel; + nsTArray mActiveContentChildIDs; + bool mActiveContentChildIDsFrozen; + // This is needed for IPC comunication between // AudioChannelServiceChild and this class. friend class ContentParent;