Merge "Set AudioGroup mode according to audio settings" into gingerbread

This commit is contained in:
Hung-ying Tyan
2010-12-02 17:50:33 -08:00
committed by Android (Google) Code Review

View File

@@ -594,12 +594,10 @@ public class SipAudioCall {
*/ */
public void holdCall(int timeout) throws SipException { public void holdCall(int timeout) throws SipException {
synchronized (this) { synchronized (this) {
if (mHold) return; if (mHold) return;
mSipSession.changeCall(createHoldOffer().encode(), timeout); mSipSession.changeCall(createHoldOffer().encode(), timeout);
mHold = true; mHold = true;
setAudioGroupMode();
AudioGroup audioGroup = getAudioGroup();
if (audioGroup != null) audioGroup.setMode(AudioGroup.MODE_ON_HOLD);
} }
} }
@@ -643,8 +641,7 @@ public class SipAudioCall {
if (!mHold) return; if (!mHold) return;
mSipSession.changeCall(createContinueOffer().encode(), timeout); mSipSession.changeCall(createContinueOffer().encode(), timeout);
mHold = false; mHold = false;
AudioGroup audioGroup = getAudioGroup(); setAudioGroupMode();
if (audioGroup != null) audioGroup.setMode(AudioGroup.MODE_NORMAL);
} }
} }
@@ -765,13 +762,8 @@ public class SipAudioCall {
/** Toggles mute. */ /** Toggles mute. */
public void toggleMute() { public void toggleMute() {
synchronized (this) { synchronized (this) {
AudioGroup audioGroup = getAudioGroup(); mMuted = !mMuted;
if (audioGroup != null) { setAudioGroupMode();
audioGroup.setMode(mMuted
? AudioGroup.MODE_NORMAL
: AudioGroup.MODE_MUTED);
mMuted = !mMuted;
}
} }
} }
@@ -790,14 +782,22 @@ public class SipAudioCall {
* Puts the device to speaker mode. * Puts the device to speaker mode.
* <p class="note"><strong>Note:</strong> Requires the * <p class="note"><strong>Note:</strong> Requires the
* {@link android.Manifest.permission#MODIFY_AUDIO_SETTINGS} permission.</p> * {@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) { public void setSpeakerMode(boolean speakerMode) {
synchronized (this) { synchronized (this) {
((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE)) ((AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE))
.setSpeakerphoneOn(speakerMode); .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>, * Sends a DTMF code. According to <a href="http://tools.ietf.org/html/rfc2833">RFC 2883</a>,
* event 0--9 maps to decimal * event 0--9 maps to decimal
@@ -874,7 +874,11 @@ public class SipAudioCall {
/** /**
* Sets the {@link AudioGroup} object which the {@link AudioStream} object * Sets the {@link AudioGroup} object which the {@link AudioStream} object
* joins. If {@code audioGroup} is null, then the {@code AudioGroup} 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 * @see #getAudioStream
* @hide * @hide
@@ -990,16 +994,25 @@ public class SipAudioCall {
// AudioGroup logic: // AudioGroup logic:
AudioGroup audioGroup = getAudioGroup(); AudioGroup audioGroup = getAudioGroup();
if (mHold) { if (mHold) {
if (audioGroup != null) {
audioGroup.setMode(AudioGroup.MODE_ON_HOLD);
}
// don't create an AudioGroup here; doing so will fail if // don't create an AudioGroup here; doing so will fail if
// there's another AudioGroup out there that's active // there's another AudioGroup out there that's active
} else { } else {
if (audioGroup == null) audioGroup = new AudioGroup(); if (audioGroup == null) audioGroup = new AudioGroup();
stream.join(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); audioGroup.setMode(AudioGroup.MODE_MUTED);
} else if (isSpeakerOn()) {
audioGroup.setMode(AudioGroup.MODE_ECHO_SUPPRESSION);
} else { } else {
audioGroup.setMode(AudioGroup.MODE_NORMAL); audioGroup.setMode(AudioGroup.MODE_NORMAL);
} }