Merge "SipService: reduce the usage of javax.sdp.*." into gingerbread

This commit is contained in:
Chia-chi Yeh
2010-09-02 08:13:01 -07:00
committed by Android (Google) Code Review
11 changed files with 72 additions and 64 deletions

View File

@@ -20,7 +20,6 @@ import gov.nist.javax.sip.SipStackExt;
import gov.nist.javax.sip.clientauthutils.AccountManager;
import gov.nist.javax.sip.clientauthutils.AuthenticationHelper;
import android.net.sip.SessionDescription;
import android.net.sip.SipProfile;
import android.util.Log;
@@ -243,7 +242,7 @@ class SipHelper {
}
public ClientTransaction sendInvite(SipProfile caller, SipProfile callee,
SessionDescription sessionDescription, String tag)
String sessionDescription, String tag)
throws SipException {
try {
FromHeader fromHeader = createFromHeader(caller, tag);
@@ -259,9 +258,9 @@ class SipHelper {
toHeader, viaHeaders, maxForwards);
request.addHeader(createContactHeader(caller));
request.setContent(sessionDescription.getContent(),
request.setContent(sessionDescription,
mHeaderFactory.createContentTypeHeader(
"application", sessionDescription.getType()));
"application", "sdp"));
ClientTransaction clientTransaction =
mSipProvider.getNewClientTransaction(request);
@@ -273,12 +272,12 @@ class SipHelper {
}
public ClientTransaction sendReinvite(Dialog dialog,
SessionDescription sessionDescription) throws SipException {
String sessionDescription) throws SipException {
try {
Request request = dialog.createRequest(Request.INVITE);
request.setContent(sessionDescription.getContent(),
request.setContent(sessionDescription,
mHeaderFactory.createContentTypeHeader(
"application", sessionDescription.getType()));
"application", "sdp"));
ClientTransaction clientTransaction =
mSipProvider.getNewClientTransaction(request);
@@ -326,7 +325,7 @@ class SipHelper {
* @param event the INVITE request event
*/
public ServerTransaction sendInviteOk(RequestEvent event,
SipProfile localProfile, SessionDescription sessionDescription,
SipProfile localProfile, String sessionDescription,
ServerTransaction inviteTransaction)
throws SipException {
try {
@@ -334,9 +333,9 @@ class SipHelper {
Response response = mMessageFactory.createResponse(Response.OK,
request);
response.addHeader(createContactHeader(localProfile));
response.setContent(sessionDescription.getContent(),
response.setContent(sessionDescription,
mHeaderFactory.createContentTypeHeader(
"application", sessionDescription.getType()));
"application", "sdp"));
if (inviteTransaction == null) {
inviteTransaction = getServerTransaction(event);

View File

@@ -53,6 +53,9 @@ import java.util.TimerTask;
import java.util.TreeSet;
import javax.sip.SipException;
/**
* @hide
*/
public final class SipService extends ISipService.Stub {
private static final String TAG = "SipService";
private static final int EXPIRY_TIME = 3600;
@@ -442,7 +445,7 @@ public final class SipService extends ISipService.Stub {
@Override
public void onRinging(ISipSession session, SipProfile caller,
byte[] sessionDescription) {
String sessionDescription) {
synchronized (SipService.this) {
try {
if (!isRegistered()) {

View File

@@ -20,6 +20,7 @@ import gov.nist.javax.sip.clientauthutils.AccountManager;
import gov.nist.javax.sip.clientauthutils.UserCredentials;
import gov.nist.javax.sip.header.SIPHeaderNames;
import gov.nist.javax.sip.header.WWWAuthenticate;
import gov.nist.javax.sip.message.SIPMessage;
import android.net.sip.ISipSession;
import android.net.sip.ISipSessionListener;
@@ -31,6 +32,7 @@ import android.text.TextUtils;
import android.util.Log;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.DatagramSocket;
import java.text.ParseException;
import java.util.Collection;
@@ -284,6 +286,22 @@ class SipSessionGroup implements SipListener {
}
}
private String extractContent(Message message) {
// Currently we do not support secure MIME bodies.
byte[] bytes = message.getRawContent();
if (bytes != null) {
try {
if (message instanceof SIPMessage) {
return ((SIPMessage) message).getMessageContent();
} else {
return new String(bytes, "UTF-8");
}
} catch (UnsupportedEncodingException e) {
}
}
return null;
}
private class SipSessionCallReceiverImpl extends SipSessionImpl {
public SipSessionCallReceiverImpl(ISipSessionListener listener) {
super(listener);
@@ -302,7 +320,7 @@ class SipSessionGroup implements SipListener {
newSession.mPeerProfile = createPeerProfile(event.getRequest());
newSession.mState = SipSessionState.INCOMING_CALL;
newSession.mPeerSessionDescription =
event.getRequest().getRawContent();
extractContent(event.getRequest());
addSipSession(newSession);
mProxy.onRinging(newSession, newSession.mPeerProfile,
newSession.mPeerSessionDescription);
@@ -321,7 +339,7 @@ class SipSessionGroup implements SipListener {
Dialog mDialog;
ServerTransaction mServerTransaction;
ClientTransaction mClientTransaction;
byte[] mPeerSessionDescription;
String mPeerSessionDescription;
boolean mInCall;
boolean mReRegisterFlag = false;
@@ -401,12 +419,12 @@ class SipSessionGroup implements SipListener {
}
public void makeCall(SipProfile peerProfile,
SessionDescription sessionDescription) {
String sessionDescription) {
doCommandAsync(
new MakeCallCommand(peerProfile, sessionDescription));
}
public void answerCall(SessionDescription sessionDescription) {
public void answerCall(String sessionDescription) {
try {
processCommand(
new MakeCallCommand(mPeerProfile, sessionDescription));
@@ -419,7 +437,7 @@ class SipSessionGroup implements SipListener {
doCommandAsync(END_CALL);
}
public void changeCall(SessionDescription sessionDescription) {
public void changeCall(String sessionDescription) {
doCommandAsync(
new MakeCallCommand(mPeerProfile, sessionDescription));
}
@@ -726,10 +744,9 @@ class SipSessionGroup implements SipListener {
if (evt instanceof MakeCallCommand) {
MakeCallCommand cmd = (MakeCallCommand) evt;
mPeerProfile = cmd.getPeerProfile();
SessionDescription sessionDescription =
cmd.getSessionDescription();
mClientTransaction = mSipHelper.sendInvite(mLocalProfile,
mPeerProfile, sessionDescription, generateTag());
mPeerProfile, cmd.getSessionDescription(),
generateTag());
mDialog = mClientTransaction.getDialog();
addSipSession(this);
mState = SipSessionState.OUTGOING_CALL;
@@ -811,7 +828,7 @@ class SipSessionGroup implements SipListener {
return true;
case Response.OK:
mSipHelper.sendInviteAck(event, mDialog);
mPeerSessionDescription = response.getRawContent();
mPeerSessionDescription = extractContent(response);
establishCall();
return true;
case Response.PROXY_AUTHENTICATION_REQUIRED:
@@ -897,7 +914,7 @@ class SipSessionGroup implements SipListener {
// got Re-INVITE
RequestEvent event = mInviteReceived = (RequestEvent) evt;
mState = SipSessionState.INCOMING_CALL;
mPeerSessionDescription = event.getRequest().getRawContent();
mPeerSessionDescription = extractContent(event.getRequest());
mServerTransaction = null;
mProxy.onRinging(this, mPeerProfile, mPeerSessionDescription);
return true;
@@ -1060,10 +1077,10 @@ class SipSessionGroup implements SipListener {
}
private class MakeCallCommand extends EventObject {
private SessionDescription mSessionDescription;
private String mSessionDescription;
public MakeCallCommand(SipProfile peerProfile,
SessionDescription sessionDescription) {
String sessionDescription) {
super(peerProfile);
mSessionDescription = sessionDescription;
}
@@ -1072,7 +1089,7 @@ class SipSessionGroup implements SipListener {
return (SipProfile) getSource();
}
public SessionDescription getSessionDescription() {
public String getSessionDescription() {
return mSessionDescription;
}
}

View File

@@ -56,7 +56,7 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
}
public void onRinging(final ISipSession session, final SipProfile caller,
final byte[] sessionDescription) {
final String sessionDescription) {
if (mListener == null) return;
proxy(new Runnable() {
public void run() {
@@ -83,7 +83,7 @@ class SipSessionListenerProxy extends ISipSessionListener.Stub {
}
public void onCallEstablished(final ISipSession session,
final byte[] sessionDescription) {
final String sessionDescription) {
if (mListener == null) return;
proxy(new Runnable() {
public void run() {

View File

@@ -115,8 +115,7 @@ interface ISipSession {
* @param sessionDescription the session description of this call
* @see ISipSessionListener
*/
void makeCall(in SipProfile callee,
in SessionDescription sessionDescription);
void makeCall(in SipProfile callee, String sessionDescription);
/**
* Answers an incoming call with the specified session description. The
@@ -125,7 +124,7 @@ interface ISipSession {
*
* @param sessionDescription the session description to answer this call
*/
void answerCall(in SessionDescription sessionDescription);
void answerCall(String sessionDescription);
/**
* Ends an established call, terminates an outgoing call or rejects an
@@ -143,5 +142,5 @@ interface ISipSession {
*
* @param sessionDescription the new session description
*/
void changeCall(in SessionDescription sessionDescription);
void changeCall(String sessionDescription);
}

View File

@@ -39,7 +39,7 @@ interface ISipSessionListener {
* @param sessionDescription the caller's session description
*/
void onRinging(in ISipSession session, in SipProfile caller,
in byte[] sessionDescription);
String sessionDescription);
/**
* Called when a RINGING response is received for the INVITE request sent
@@ -55,7 +55,7 @@ interface ISipSessionListener {
* @param sessionDescription the peer's session description
*/
void onCallEstablished(in ISipSession session,
in byte[] sessionDescription);
String sessionDescription);
/**
* Called when the session is terminated.

View File

@@ -186,8 +186,8 @@ public class SdpSessionDescription extends SessionDescription {
}
}
public SdpSessionDescription build() {
return mSdp;
public String build() {
return mSdp.toString();
}
}

View File

@@ -168,9 +168,9 @@ public interface SipAudioCall {
* Attaches an incoming call to this call object.
*
* @param session the session that receives the incoming call
* @param sdp the session description of the incoming call
* @param sessionDescription the session description of the incoming call
*/
void attachCall(ISipSession session, SdpSessionDescription sdp)
void attachCall(ISipSession session, String sessionDescription)
throws SipException;
/** Ends a call. */

View File

@@ -28,14 +28,6 @@ import android.net.rtp.AudioCodec;
import android.net.rtp.AudioGroup;
import android.net.rtp.AudioStream;
import android.net.rtp.RtpStream;
import android.net.sip.ISipSession;
import android.net.sip.SdpSessionDescription;
import android.net.sip.SessionDescription;
import android.net.sip.SipAudioCall;
import android.net.sip.SipManager;
import android.net.sip.SipProfile;
import android.net.sip.SipSessionAdapter;
import android.net.sip.SipSessionState;
import android.net.wifi.WifiManager;
import android.os.Message;
import android.os.RemoteException;
@@ -200,7 +192,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
@Override
public synchronized void onRinging(ISipSession session,
SipProfile peerProfile, byte[] sessionDescription) {
SipProfile peerProfile, String sessionDescription) {
try {
if ((mSipSession == null) || !mInCall
|| !session.getCallId().equals(mSipSession.getCallId())) {
@@ -222,7 +214,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
}
}
private synchronized void establishCall(byte[] sessionDescription) {
private synchronized void establishCall(String sessionDescription) {
stopRingbackTone();
stopRinging();
try {
@@ -238,7 +230,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
@Override
public void onCallEstablished(ISipSession session,
byte[] sessionDescription) {
String sessionDescription) {
establishCall(sessionDescription);
Listener listener = mListener;
if (listener != null) {
@@ -316,10 +308,10 @@ public class SipAudioCallImpl extends SipSessionAdapter
}
public synchronized void attachCall(ISipSession session,
SdpSessionDescription sdp) throws SipException {
String sessionDescription) throws SipException {
mSipSession = session;
mPeerSd = sdp;
try {
mPeerSd = new SdpSessionDescription(sessionDescription);
session.setListener(this);
} catch (Throwable e) {
Log.e(TAG, "attachCall()", e);
@@ -394,12 +386,12 @@ public class SipAudioCallImpl extends SipSessionAdapter
if (audioGroup != null) audioGroup.setMode(AudioGroup.MODE_NORMAL);
}
private SessionDescription createOfferSessionDescription() {
private String createOfferSessionDescription() {
AudioCodec[] codecs = AudioCodec.getSystemSupportedCodecs();
return createSdpBuilder(true, convert(codecs)).build();
}
private SessionDescription createAnswerSessionDescription() {
private String createAnswerSessionDescription() {
try {
// choose an acceptable media from mPeerSd to answer
SdpSessionDescription.AudioCodec codec = getCodec(mPeerSd);
@@ -416,7 +408,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
}
}
private SessionDescription createHoldSessionDescription() {
private String createHoldSessionDescription() {
try {
return createSdpBuilder(false, mCodec)
.addMediaAttribute(AUDIO, "sendonly", (String) null)
@@ -448,7 +440,7 @@ public class SipAudioCallImpl extends SipSessionAdapter
return (mWm.getConnectionInfo().getBSSID() == null) ? false : true;
}
private SessionDescription createContinueSessionDescription() {
private String createContinueSessionDescription() {
return createSdpBuilder(true, mCodec).build();
}

View File

@@ -298,21 +298,19 @@ public class SipManager {
throw new SipException("Call ID missing in incoming call intent");
}
byte[] offerSd = getOfferSessionDescription(incomingCallIntent);
String offerSd = getOfferSessionDescription(incomingCallIntent);
if (offerSd == null) {
throw new SipException("Session description missing in incoming "
+ "call intent");
}
try {
SdpSessionDescription sdp = new SdpSessionDescription(offerSd);
ISipSession session = mSipService.getPendingSession(callId);
if (session == null) return null;
SipAudioCall call = new SipAudioCallImpl(
context, session.getLocalProfile());
call.setRingtoneEnabled(ringtoneEnabled);
call.attachCall(session, sdp);
call.attachCall(session, offerSd);
call.setListener(listener);
return call;
} catch (Throwable t) {
@@ -329,7 +327,7 @@ public class SipManager {
public static boolean isIncomingCallIntent(Intent intent) {
if (intent == null) return false;
String callId = getCallId(intent);
byte[] offerSd = getOfferSessionDescription(intent);
String offerSd = getOfferSessionDescription(intent);
return ((callId != null) && (offerSd != null));
}
@@ -351,8 +349,8 @@ public class SipManager {
* @return the offer session description or null if the intent does not
* have it
*/
public static byte[] getOfferSessionDescription(Intent incomingCallIntent) {
return incomingCallIntent.getByteArrayExtra(OFFER_SD_KEY);
public static String getOfferSessionDescription(Intent incomingCallIntent) {
return incomingCallIntent.getStringExtra(OFFER_SD_KEY);
}
/**
@@ -365,7 +363,7 @@ public class SipManager {
* @hide
*/
public static Intent createIncomingCallBroadcast(String action,
String callId, byte[] sessionDescription) {
String callId, String sessionDescription) {
Intent intent = new Intent(action);
intent.putExtra(CALL_ID_KEY, callId);
intent.putExtra(OFFER_SD_KEY, sessionDescription);

View File

@@ -26,14 +26,14 @@ public class SipSessionAdapter extends ISipSessionListener.Stub {
}
public void onRinging(ISipSession session, SipProfile caller,
byte[] sessionDescription) {
String sessionDescription) {
}
public void onRingingBack(ISipSession session) {
}
public void onCallEstablished(
ISipSession session, byte[] sessionDescription) {
public void onCallEstablished(ISipSession session,
String sessionDescription) {
}
public void onCallEnded(ISipSession session) {