Skip to content

Commit

Permalink
Bug 1006380 - Set phone in PHONE_STATE_IN_COMMUNICATION audio state w…
Browse files Browse the repository at this point in the history
…hen telephony audio channel is in use. r=mchen
  • Loading branch information
jaoo committed May 29, 2014
1 parent e109c7c commit b1de933
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
7 changes: 7 additions & 0 deletions dom/audiochannel/AudioChannelService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ AudioChannelService::ContentOrNormalChannelIsActive()
!mChannelCounters[AUDIO_CHANNEL_INT_NORMAL].IsEmpty();
}

bool
AudioChannelService::TelephonyChannelIsActive()
{
return !mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY].IsEmpty() ||
!mChannelCounters[AUDIO_CHANNEL_INT_TELEPHONY_HIDDEN].IsEmpty();
}

bool
AudioChannelService::ProcessContentOrNormalChannelIsActive(uint64_t aChildID)
{
Expand Down
6 changes: 6 additions & 0 deletions dom/audiochannel/AudioChannelService.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ class AudioChannelService
*/
virtual bool ContentOrNormalChannelIsActive();

/**
* Return true if there is a telephony channel active in this process
* or one of its subprocesses.
*/
virtual bool TelephonyChannelIsActive();

/**
* Return true if a normal or content channel is active for the given
* process ID.
Expand Down
50 changes: 44 additions & 6 deletions dom/system/gonk/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ using namespace mozilla::dom::bluetooth;

#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "AudioManager" , ## args)

#define HEADPHONES_STATUS_HEADSET MOZ_UTF16("headset")
#define HEADPHONES_STATUS_HEADPHONE MOZ_UTF16("headphone")
#define HEADPHONES_STATUS_OFF MOZ_UTF16("off")
#define HEADPHONES_STATUS_UNKNOWN MOZ_UTF16("unknown")
#define HEADPHONES_STATUS_CHANGED "headphones-status-changed"
#define MOZ_SETTINGS_CHANGE_ID "mozsettings-changed"
#define HEADPHONES_STATUS_HEADSET MOZ_UTF16("headset")
#define HEADPHONES_STATUS_HEADPHONE MOZ_UTF16("headphone")
#define HEADPHONES_STATUS_OFF MOZ_UTF16("off")
#define HEADPHONES_STATUS_UNKNOWN MOZ_UTF16("unknown")
#define HEADPHONES_STATUS_CHANGED "headphones-status-changed"
#define MOZ_SETTINGS_CHANGE_ID "mozsettings-changed"
#define AUDIO_CHANNEL_PROCESS_CHANGED "audio-channel-process-changed"

static void BinderDeadCallback(status_t aErr);
static void InternalSetAudioRoutes(SwitchState aState);
Expand Down Expand Up @@ -280,6 +281,32 @@ AudioManager::HandleBluetoothStatusChanged(nsISupports* aSubject,
#endif
}

void
AudioManager::HandleAudioChannelProcessChanged()
{
// Note: If the user answers a VoIP call (e.g. WebRTC calls) during the
// telephony call (GSM/CDMA calls) the audio manager won't set the
// PHONE_STATE_IN_COMMUNICATION audio state. Once the telephony call finishes
// the RIL plumbing sets the PHONE_STATE_NORMAL audio state. This seems to be
// an issue for the VoIP call but it is not. Once the RIL plumbing sets the
// the PHONE_STATE_NORMAL audio state the AudioManager::mPhoneAudioAgent
// member will call the StopPlaying() method causing that this function will
// be called again and therefore the audio manager sets the
// PHONE_STATE_IN_COMMUNICATION audio state.

if ((mPhoneState == PHONE_STATE_IN_CALL) ||
(mPhoneState == PHONE_STATE_RINGTONE)) {
return;
}

AudioChannelService *service = AudioChannelService::GetAudioChannelService();
NS_ENSURE_TRUE_VOID(service);

bool telephonyChannelIsActive = service->TelephonyChannelIsActive();
telephonyChannelIsActive ? SetPhoneState(PHONE_STATE_IN_COMMUNICATION) :
SetPhoneState(PHONE_STATE_NORMAL);
}

nsresult
AudioManager::Observe(nsISupports* aSubject,
const char* aTopic,
Expand All @@ -298,6 +325,11 @@ AudioManager::Observe(nsISupports* aSubject,
return NS_OK;
}

else if (!strcmp(aTopic, AUDIO_CHANNEL_PROCESS_CHANGED)) {
HandleAudioChannelProcessChanged();
return NS_OK;
}

// To process the volume control on each audio channel according to
// change of settings
else if (!strcmp(aTopic, MOZ_SETTINGS_CHANGE_ID)) {
Expand Down Expand Up @@ -429,6 +461,9 @@ AudioManager::AudioManager()
if (NS_FAILED(obs->AddObserver(this, MOZ_SETTINGS_CHANGE_ID, false))) {
NS_WARNING("Failed to add mozsettings-changed observer!");
}
if (NS_FAILED(obs->AddObserver(this, AUDIO_CHANNEL_PROCESS_CHANGED, false))) {
NS_WARNING("Failed to add audio-channel-process-changed observer!");
}

#ifdef MOZ_B2G_RIL
char value[PROPERTY_VALUE_MAX];
Expand Down Expand Up @@ -456,6 +491,9 @@ AudioManager::~AudioManager() {
if (NS_FAILED(obs->RemoveObserver(this, MOZ_SETTINGS_CHANGE_ID))) {
NS_WARNING("Failed to remove mozsettings-changed observer!");
}
if (NS_FAILED(obs->RemoveObserver(this, AUDIO_CHANNEL_PROCESS_CHANGED))) {
NS_WARNING("Failed to remove audio-channel-process-changed!");
}
}

NS_IMETHODIMP
Expand Down
1 change: 1 addition & 0 deletions dom/system/gonk/AudioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class AudioManager : public nsIAudioManager
void HandleBluetoothStatusChanged(nsISupports* aSubject,
const char* aTopic,
const nsCString aAddress);
void HandleAudioChannelProcessChanged();
};

} /* namespace gonk */
Expand Down

0 comments on commit b1de933

Please sign in to comment.