diff options
author | Hung-ying Tyan <tyanh@google.com> | 2010-12-13 18:47:35 +0800 |
---|---|---|
committer | Hung-ying Tyan <tyanh@google.com> | 2010-12-29 16:07:17 +0800 |
commit | 1d12ef09a8e6ebc6638f4ff2f561c50c950023cb (patch) | |
tree | 9e0c0a867433bba16251427f44233152cface300 /telephony/java | |
parent | 672ebb61a755e4bbe60e4e884b1adadf186733b6 (diff) | |
download | frameworks_base-1d12ef09a8e6ebc6638f4ff2f561c50c950023cb.zip frameworks_base-1d12ef09a8e6ebc6638f4ff2f561c50c950023cb.tar.gz frameworks_base-1d12ef09a8e6ebc6638f4ff2f561c50c950023cb.tar.bz2 |
Fix setting audio group mode in SipPhone.
Bug: 3119690
Change-Id: I495d3c031ee4c272d360fe19553ef9726a3f8771
Diffstat (limited to 'telephony/java')
-rwxr-xr-x | telephony/java/com/android/internal/telephony/sip/SipPhone.java | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/telephony/java/com/android/internal/telephony/sip/SipPhone.java b/telephony/java/com/android/internal/telephony/sip/SipPhone.java index a92ac1c..72f3831 100755 --- a/telephony/java/com/android/internal/telephony/sip/SipPhone.java +++ b/telephony/java/com/android/internal/telephony/sip/SipPhone.java @@ -17,6 +17,7 @@ package com.android.internal.telephony.sip; import android.content.Context; +import android.media.AudioManager; import android.net.rtp.AudioGroup; import android.net.sip.SipAudioCall; import android.net.sip.SipErrorCode; @@ -126,7 +127,7 @@ public class SipPhone extends SipPhoneBase { (ringingCall.getState() == Call.State.WAITING)) { if (DEBUG) Log.d(LOG_TAG, "acceptCall"); // Always unmute when answering a new call - setMute(false); + ringingCall.setMute(false); ringingCall.acceptCall(); } else { throw new CallStateException("phone not ringing"); @@ -170,7 +171,7 @@ public class SipPhone extends SipPhoneBase { throw new CallStateException("cannot dial in current state"); } - setMute(false); + foregroundCall.setMute(false); try { Connection c = foregroundCall.dial(dialString); return c; @@ -288,16 +289,13 @@ public class SipPhone extends SipPhoneBase { @Override public void setEchoSuppressionEnabled(boolean enabled) { + // TODO: Remove the enabled argument. We should check the speakerphone + // state with AudioManager instead of keeping a state here so the + // method with a state argument is redundant. Also rename the method + // to something like onSpeaerphoneStateChanged(). Echo suppression may + // not be available on every device. synchronized (SipPhone.class) { - AudioGroup audioGroup = foregroundCall.getAudioGroup(); - if (audioGroup == null) return; - int mode = audioGroup.getMode(); - audioGroup.setMode(enabled - ? AudioGroup.MODE_ECHO_SUPPRESSION - : AudioGroup.MODE_NORMAL); - if (DEBUG) Log.d(LOG_TAG, String.format( - "audioGroup mode change: %d --> %d", mode, - audioGroup.getMode())); + foregroundCall.setAudioGroupMode(); } } @@ -450,13 +448,33 @@ public class SipPhone extends SipPhoneBase { ((SipConnection) connections.get(0)).acceptCall(); } - void hold() throws CallStateException { - setState(State.HOLDING); + private boolean isSpeakerOn() { + return ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)) + .isSpeakerphoneOn(); + } + + void setAudioGroupMode() { AudioGroup audioGroup = getAudioGroup(); - if (audioGroup != null) { + if (audioGroup == null) return; + int mode = audioGroup.getMode(); + if (state == State.HOLDING) { audioGroup.setMode(AudioGroup.MODE_ON_HOLD); + } else if (getMute()) { + audioGroup.setMode(AudioGroup.MODE_MUTED); + } else if (isSpeakerOn()) { + audioGroup.setMode(AudioGroup.MODE_ECHO_SUPPRESSION); + } else { + audioGroup.setMode(AudioGroup.MODE_NORMAL); } + if (DEBUG) Log.d(LOG_TAG, String.format( + "audioGroup mode change: %d --> %d", mode, + audioGroup.getMode())); + } + + void hold() throws CallStateException { + setState(State.HOLDING); for (Connection c : connections) ((SipConnection) c).hold(); + setAudioGroupMode(); } void unhold() throws CallStateException { @@ -465,19 +483,19 @@ public class SipPhone extends SipPhoneBase { for (Connection c : connections) { ((SipConnection) c).unhold(audioGroup); } + setAudioGroupMode(); } void setMute(boolean muted) { - AudioGroup audioGroup = getAudioGroup(); - if (audioGroup == null) return; - audioGroup.setMode( - muted ? AudioGroup.MODE_MUTED : AudioGroup.MODE_NORMAL); + for (Connection c : connections) { + ((SipConnection) c).setMute(muted); + } } boolean getMute() { - AudioGroup audioGroup = getAudioGroup(); - if (audioGroup == null) return false; - return (audioGroup.getMode() == AudioGroup.MODE_MUTED); + return connections.isEmpty() + ? false + : ((SipConnection) connections.get(0)).getMute(); } void merge(SipCall that) throws CallStateException { @@ -736,6 +754,17 @@ public class SipPhone extends SipPhoneBase { } } + void setMute(boolean muted) { + if ((mSipAudioCall != null) && (muted != mSipAudioCall.isMuted())) { + mSipAudioCall.toggleMute(); + } + } + + boolean getMute() { + return (mSipAudioCall == null) ? false + : mSipAudioCall.isMuted(); + } + @Override protected void setState(Call.State state) { if (state == mState) return; |