Merge "Fix SIP bug of different transport/port used for requests." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
5f86d7f50b
@ -383,7 +383,9 @@ public class SipPhone extends SipPhoneBase {
|
|||||||
Connection dial(String originalNumber) throws SipException {
|
Connection dial(String originalNumber) throws SipException {
|
||||||
String calleeSipUri = originalNumber;
|
String calleeSipUri = originalNumber;
|
||||||
if (!calleeSipUri.contains("@")) {
|
if (!calleeSipUri.contains("@")) {
|
||||||
calleeSipUri += "@" + getSipDomain(mProfile);
|
calleeSipUri = mProfile.getUriString().replaceFirst(
|
||||||
|
mProfile.getUserName() + "@",
|
||||||
|
calleeSipUri + "@");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
SipProfile callee =
|
SipProfile callee =
|
||||||
|
@ -20,6 +20,7 @@ import android.os.Parcel;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import java.io.ObjectStreamException;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import javax.sip.InvalidArgumentException;
|
import javax.sip.InvalidArgumentException;
|
||||||
@ -40,12 +41,15 @@ import javax.sip.address.URI;
|
|||||||
public class SipProfile implements Parcelable, Serializable, Cloneable {
|
public class SipProfile implements Parcelable, Serializable, Cloneable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final int DEFAULT_PORT = 5060;
|
private static final int DEFAULT_PORT = 5060;
|
||||||
|
private static final String TCP = "TCP";
|
||||||
|
private static final String UDP = "UDP";
|
||||||
private Address mAddress;
|
private Address mAddress;
|
||||||
private String mProxyAddress;
|
private String mProxyAddress;
|
||||||
private String mPassword;
|
private String mPassword;
|
||||||
private String mDomain;
|
private String mDomain;
|
||||||
private String mProtocol = ListeningPoint.UDP;
|
private String mProtocol = UDP;
|
||||||
private String mProfileName;
|
private String mProfileName;
|
||||||
|
private int mPort = DEFAULT_PORT;
|
||||||
private boolean mSendKeepAlive = false;
|
private boolean mSendKeepAlive = false;
|
||||||
private boolean mAutoRegistration = true;
|
private boolean mAutoRegistration = true;
|
||||||
private transient int mCallingUid = 0;
|
private transient int mCallingUid = 0;
|
||||||
@ -95,6 +99,7 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
mUri.setUserPassword(profile.getPassword());
|
mUri.setUserPassword(profile.getPassword());
|
||||||
mDisplayName = profile.getDisplayName();
|
mDisplayName = profile.getDisplayName();
|
||||||
mProxyAddress = profile.getProxyAddress();
|
mProxyAddress = profile.getProxyAddress();
|
||||||
|
mProfile.mPort = profile.getPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -171,12 +176,11 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
* @throws IllegalArgumentException if the port number is out of range
|
* @throws IllegalArgumentException if the port number is out of range
|
||||||
*/
|
*/
|
||||||
public Builder setPort(int port) throws IllegalArgumentException {
|
public Builder setPort(int port) throws IllegalArgumentException {
|
||||||
try {
|
if ((port > 65535) || (port < 1000)) {
|
||||||
mUri.setPort(port);
|
throw new IllegalArgumentException("incorrect port arugment");
|
||||||
return this;
|
|
||||||
} catch (InvalidArgumentException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
}
|
||||||
|
mProfile.mPort = port;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -193,7 +197,7 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
throw new NullPointerException("protocol cannot be null");
|
throw new NullPointerException("protocol cannot be null");
|
||||||
}
|
}
|
||||||
protocol = protocol.toUpperCase();
|
protocol = protocol.toUpperCase();
|
||||||
if (!protocol.equals("UDP") && !protocol.equals("TCP")) {
|
if (!protocol.equals(UDP) && !protocol.equals(TCP)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"unsupported protocol: " + protocol);
|
"unsupported protocol: " + protocol);
|
||||||
}
|
}
|
||||||
@ -258,13 +262,22 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
mProfile.mPassword = mUri.getUserPassword();
|
mProfile.mPassword = mUri.getUserPassword();
|
||||||
mUri.setUserPassword(null);
|
mUri.setUserPassword(null);
|
||||||
try {
|
try {
|
||||||
mProfile.mAddress = mAddressFactory.createAddress(
|
|
||||||
mDisplayName, mUri);
|
|
||||||
if (!TextUtils.isEmpty(mProxyAddress)) {
|
if (!TextUtils.isEmpty(mProxyAddress)) {
|
||||||
SipURI uri = (SipURI)
|
SipURI uri = (SipURI)
|
||||||
mAddressFactory.createURI(fix(mProxyAddress));
|
mAddressFactory.createURI(fix(mProxyAddress));
|
||||||
mProfile.mProxyAddress = uri.getHost();
|
mProfile.mProxyAddress = uri.getHost();
|
||||||
|
} else {
|
||||||
|
if (!mProfile.mProtocol.equals(UDP)) {
|
||||||
|
mUri.setTransportParam(mProfile.mProtocol);
|
||||||
|
}
|
||||||
|
if (mProfile.mPort != DEFAULT_PORT) {
|
||||||
|
mUri.setPort(mProfile.mPort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
mProfile.mAddress = mAddressFactory.createAddress(
|
||||||
|
mDisplayName, mUri);
|
||||||
|
} catch (InvalidArgumentException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
// must not occur
|
// must not occur
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
@ -286,6 +299,7 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
mSendKeepAlive = (in.readInt() == 0) ? false : true;
|
mSendKeepAlive = (in.readInt() == 0) ? false : true;
|
||||||
mAutoRegistration = (in.readInt() == 0) ? false : true;
|
mAutoRegistration = (in.readInt() == 0) ? false : true;
|
||||||
mCallingUid = in.readInt();
|
mCallingUid = in.readInt();
|
||||||
|
mPort = in.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -299,6 +313,7 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
out.writeInt(mSendKeepAlive ? 1 : 0);
|
out.writeInt(mSendKeepAlive ? 1 : 0);
|
||||||
out.writeInt(mAutoRegistration ? 1 : 0);
|
out.writeInt(mAutoRegistration ? 1 : 0);
|
||||||
out.writeInt(mCallingUid);
|
out.writeInt(mCallingUid);
|
||||||
|
out.writeInt(mPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -322,7 +337,13 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
* @return the SIP URI string of this profile
|
* @return the SIP URI string of this profile
|
||||||
*/
|
*/
|
||||||
public String getUriString() {
|
public String getUriString() {
|
||||||
return mAddress.getURI().toString();
|
// We need to return the sip uri domain instead of
|
||||||
|
// the SIP URI with transport, port information if
|
||||||
|
// the outbound proxy address exists.
|
||||||
|
if (!TextUtils.isEmpty(mProxyAddress)) {
|
||||||
|
return "sip:" + getUserName() + "@" + mDomain;
|
||||||
|
}
|
||||||
|
return getUri().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -377,8 +398,7 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
* @return the port number of the SIP server
|
* @return the port number of the SIP server
|
||||||
*/
|
*/
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
int port = getUri().getPort();
|
return mPort;
|
||||||
return (port == -1) ? DEFAULT_PORT : port;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -441,4 +461,10 @@ public class SipProfile implements Parcelable, Serializable, Cloneable {
|
|||||||
public int getCallingUid() {
|
public int getCallingUid() {
|
||||||
return mCallingUid;
|
return mCallingUid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Object readResolve() throws ObjectStreamException {
|
||||||
|
// For compatibility.
|
||||||
|
if (mPort == 0) mPort = DEFAULT_PORT;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,8 +215,9 @@ class SipHelper {
|
|||||||
String tag) throws ParseException, SipException {
|
String tag) throws ParseException, SipException {
|
||||||
FromHeader fromHeader = createFromHeader(userProfile, tag);
|
FromHeader fromHeader = createFromHeader(userProfile, tag);
|
||||||
ToHeader toHeader = createToHeader(userProfile);
|
ToHeader toHeader = createToHeader(userProfile);
|
||||||
SipURI requestURI = mAddressFactory.createSipURI("sip:"
|
SipURI requestURI = mAddressFactory.createSipURI(
|
||||||
+ userProfile.getSipDomain());
|
userProfile.getUriString().replaceFirst(
|
||||||
|
userProfile.getUserName() + "@", ""));
|
||||||
List<ViaHeader> viaHeaders = createViaHeaders();
|
List<ViaHeader> viaHeaders = createViaHeaders();
|
||||||
CallIdHeader callIdHeader = createCallIdHeader();
|
CallIdHeader callIdHeader = createCallIdHeader();
|
||||||
CSeqHeader cSeqHeader = createCSeqHeader(requestType);
|
CSeqHeader cSeqHeader = createCSeqHeader(requestType);
|
||||||
|
Reference in New Issue
Block a user