Bug 832665 - Switching back and forth between the music app and FM radio (using home key) causes some unexpected behavior., r=mchen

This commit is contained in:
Andrea Marchesini 2013-01-25 16:12:17 +01:00
Родитель ec419c6c8a
Коммит a12b19957f
3 изменённых файлов: 38 добавлений и 26 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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<uint64_t> mActiveContentChildIDs;
bool mActiveContentChildIDsFrozen;
// This is needed for IPC comunication between
// AudioChannelServiceChild and this class.
friend class ContentParent;

Просмотреть файл

@ -145,6 +145,12 @@ TestContentChannels()
rv = agent2.Init();
NS_ENSURE_SUCCESS(rv, rv);
rv = agent1.mAgent->SetVisibilityState(true);
NS_ENSURE_SUCCESS(rv, rv);
rv = agent2.mAgent->SetVisibilityState(true);
NS_ENSURE_SUCCESS(rv, rv);
bool playing;
rv = agent1.StartPlaying(&playing);
NS_ENSURE_SUCCESS(rv, rv);
@ -166,7 +172,7 @@ TestContentChannels()
rv = agent2.StartPlaying(&playing);
NS_ENSURE_SUCCESS(rv, rv);
TEST_ENSURE_BASE(!playing, "Test3: A content channel unvisible agent2 should not be playing");
TEST_ENSURE_BASE(playing, "Test3: A content channel unvisible agent2 should be playing");
rv = agent1.mAgent->SetVisibilityState(true);
NS_ENSURE_SUCCESS(rv, rv);