diff options
author | Hung-ying Tyan <tyanh@google.com> | 2010-10-25 17:23:10 +0800 |
---|---|---|
committer | Hung-ying Tyan <tyanh@google.com> | 2010-11-30 18:55:37 +0800 |
commit | fa81463e88d15859b557be6fef5982b049b92ab8 (patch) | |
tree | 316df81a473bee049d1f9939a7511badd21daf12 /voip/java/android/net/sip | |
parent | 349f3509f7335bbdef443a75afa36fb3c2d9552c (diff) | |
download | frameworks_base-fa81463e88d15859b557be6fef5982b049b92ab8.zip frameworks_base-fa81463e88d15859b557be6fef5982b049b92ab8.tar.gz frameworks_base-fa81463e88d15859b557be6fef5982b049b92ab8.tar.bz2 |
Set AudioGroup mode according to audio settings
Set AudioGroup mode according to holding, mute and speaker phone settings.
Bug: 3119690
Change-Id: I02803ae105409b7f8482e6c2ef3e67623bd54e03
Diffstat (limited to 'voip/java/android/net/sip')
-rw-r--r-- | voip/java/android/net/sip/SipAudioCall.java | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/voip/java/android/net/sip/SipAudioCall.java b/voip/java/android/net/sip/SipAudioCall.java index b847ff6..286f60b 100644 --- a/voip/java/android/net/sip/SipAudioCall.java +++ b/voip/java/android/net/sip/SipAudioCall.java @@ -594,12 +594,10 @@ public class SipAudioCall { */ public void holdCall(int timeout) throws SipException { synchronized (this) { - if (mHold) return; + if (mHold) return; mSipSession.changeCall(createHoldOffer().encode(), timeout); mHold = true; - - AudioGroup audioGroup = getAudioGroup(); - if (audioGroup != null) audioGroup.setMode(AudioGroup.MODE_ON_HOLD); + setAudioGroupMode(); } } @@ -643,8 +641,7 @@ public class SipAudioCall { if (!mHold) return; mSipSession.changeCall(createContinueOffer().encode(), timeout); mHold = false; - AudioGroup audioGroup = getAudioGroup(); - if (audioGroup != null) audioGroup.setMode(AudioGroup.MODE_NORMAL); + setAudioGroupMode(); } } @@ -765,13 +762,8 @@ public class SipAudioCall { /** Toggles mute. */ public void toggleMute() { synchronized (this) { - AudioGroup audioGroup = getAudioGroup(); - if (audioGroup != null) { - audioGroup.setMode(mMuted - ? AudioGroup.MODE_NORMAL - : AudioGroup.MODE_MUTED); - mMuted = !mMuted; - } + mMuted = !mMuted; + setAudioGroupMode(); } } @@ -790,14 +782,22 @@ public class SipAudioCall { * Puts the device to speaker mode. * <p class="note"><strong>Note:</strong> Requires the * {@link android.Manifest.permission#MODIFY_AUDIO_SETTINGS} permission.</p> + * + * @param speakerMode set true to enable speaker mode; false to disable */ public void setSpeakerMode(boolean speakerMode) { synchronized (this) { ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)) .setSpeakerphoneOn(speakerMode); + setAudioGroupMode(); } } + private boolean isSpeakerOn() { + return ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)) + .isSpeakerphoneOn(); + } + /** * Sends a DTMF code. According to <a href="http://tools.ietf.org/html/rfc2833">RFC 2883</a>, * event 0--9 maps to decimal @@ -874,7 +874,11 @@ public class SipAudioCall { /** * Sets the {@link AudioGroup} object which the {@link AudioStream} object * joins. If {@code audioGroup} is null, then the {@code AudioGroup} object - * will be dynamically created when needed. + * will be dynamically created when needed. Note that the mode of the + * {@code AudioGroup} is not changed according to the audio settings (i.e., + * hold, mute, speaker phone) of this object. This is mainly used to merge + * multiple {@code SipAudioCall} objects to form a conference call. The + * settings of the first object (that merges others) override others'. * * @see #getAudioStream * @hide @@ -990,16 +994,25 @@ public class SipAudioCall { // AudioGroup logic: AudioGroup audioGroup = getAudioGroup(); if (mHold) { - if (audioGroup != null) { - audioGroup.setMode(AudioGroup.MODE_ON_HOLD); - } // don't create an AudioGroup here; doing so will fail if // there's another AudioGroup out there that's active } else { if (audioGroup == null) audioGroup = new AudioGroup(); stream.join(audioGroup); - if (mMuted) { + } + setAudioGroupMode(); + } + + // set audio group mode based on current audio configuration + private void setAudioGroupMode() { + AudioGroup audioGroup = getAudioGroup(); + if (audioGroup != null) { + if (mHold) { + audioGroup.setMode(AudioGroup.MODE_ON_HOLD); + } else if (mMuted) { audioGroup.setMode(AudioGroup.MODE_MUTED); + } else if (isSpeakerOn()) { + audioGroup.setMode(AudioGroup.MODE_ECHO_SUPPRESSION); } else { audioGroup.setMode(AudioGroup.MODE_NORMAL); } |