diff options
author | Hung-ying Tyan <tyanh@google.com> | 2011-01-04 17:47:47 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2011-01-04 17:47:47 -0800 |
commit | 05c53067b613796624937214e506c58de817c8fd (patch) | |
tree | 08ffcfce72fba6c4b566236b2929aee4311d6c21 /telephony | |
parent | dc78e3fe7f2ffbc810cd54e86e3a83e279d74984 (diff) | |
parent | 273d2ea3f986f1611d2cf303cc5b93f820c14dd3 (diff) | |
download | frameworks_base-05c53067b613796624937214e506c58de817c8fd.zip frameworks_base-05c53067b613796624937214e506c58de817c8fd.tar.gz frameworks_base-05c53067b613796624937214e506c58de817c8fd.tar.bz2 |
am 273d2ea3: Merge "Fix setting audio group mode in SipPhone." into gingerbread
* commit '273d2ea3f986f1611d2cf303cc5b93f820c14dd3':
Fix setting audio group mode in SipPhone.
Diffstat (limited to 'telephony')
-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; |