Merge "Parse params needed for SipDelegate routing" am: 9a13fb1dbf am: b81ca0dc24

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1616689

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I6cb191134894a3b6130dccc7f4b7d3fbcd85c5e3
This commit is contained in:
Brad Ebinger
2021-03-05 05:12:44 +00:00
committed by Automerger Merge Worker
5 changed files with 49 additions and 6 deletions

View File

@@ -11819,10 +11819,12 @@ package android.telephony.ims {
public final class SipMessage implements android.os.Parcelable {
ctor public SipMessage(@NonNull String, @NonNull String, @NonNull byte[]);
method public int describeContents();
method @Nullable public String getCallIdParameter();
method @NonNull public byte[] getContent();
method @NonNull public byte[] getEncodedMessage();
method @NonNull public String getHeaderSection();
method @NonNull public String getStartLine();
method @Nullable public String getViaBranchParameter();
method public void writeToParcel(@NonNull android.os.Parcel, int);
field @NonNull public static final android.os.Parcelable.Creator<android.telephony.ims.SipMessage> CREATOR;
}

View File

@@ -65,6 +65,11 @@ public class SipMessageParsingUtils {
// compact form of the via header key
private static final String VIA_SIP_HEADER_KEY_COMPACT = "v";
// call-id header key
private static final String CALL_ID_SIP_HEADER_KEY = "call-id";
// compact form of the call-id header key
private static final String CALL_ID_SIP_HEADER_KEY_COMPACT = "i";
/**
* @return true if the SIP message start line is considered a request (based on known request
* methods).
@@ -124,6 +129,17 @@ public class SipMessageParsingUtils {
return null;
}
/**
* Return the call-id header key's associated value.
* @param headerString The string containing the headers of the SIP message.
*/
public static String getCallId(String headerString) {
// search for the call-Id header, there should only be one in the header.
List<Pair<String, String>> headers = parseHeaders(headerString, true,
CALL_ID_SIP_HEADER_KEY, CALL_ID_SIP_HEADER_KEY_COMPACT);
return !headers.isEmpty() ? headers.get(0).second : null;
}
private static String[] splitStartLineAndVerify(String startLine) {
String[] splitLine = startLine.split(" ");
if (isStartLineMalformed(splitLine)) return null;

View File

@@ -19,6 +19,7 @@ package android.telephony.ims;
import static java.nio.charset.StandardCharsets.UTF_8;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Build;
import android.os.Parcel;
@@ -46,6 +47,8 @@ public final class SipMessage implements Parcelable {
private final String mStartLine;
private final String mHeaderSection;
private final byte[] mContent;
private final String mViaBranchParam;
private final String mCallIdParam;
/**
* Represents a partially encoded SIP message.
@@ -63,6 +66,9 @@ public final class SipMessage implements Parcelable {
mStartLine = startLine;
mHeaderSection = headerSection;
mContent = content;
mViaBranchParam = SipMessageParsingUtils.getTransactionId(mHeaderSection);
mCallIdParam = SipMessageParsingUtils.getCallId(mHeaderSection);
}
/**
@@ -73,6 +79,8 @@ public final class SipMessage implements Parcelable {
mHeaderSection = source.readString();
mContent = new byte[source.readInt()];
source.readByteArray(mContent);
mViaBranchParam = source.readString();
mCallIdParam = source.readString();
}
/**
@@ -97,6 +105,25 @@ public final class SipMessage implements Parcelable {
return mContent;
}
/**
* @return the branch parameter enclosed in the Via header key's value. See RFC 3261 section
* 20.42 for more information on the Via header. If {@code null}, then there was either no
* Via parameter found in this SIP message's headers or no branch parameter found in the
* Via header.
*/
public @Nullable String getViaBranchParameter() {
return mViaBranchParam;
}
/**
* @return the value associated with the call-id header of this SIP message. See RFC 3261
* section 20.8 for more information on the call-id header. If {@code null}, then there was no
* call-id header found in this SIP message's headers.
*/
public @Nullable String getCallIdParameter() {
return mCallIdParam;
}
@Override
public int describeContents() {
return 0;
@@ -108,6 +135,8 @@ public final class SipMessage implements Parcelable {
dest.writeString(mHeaderSection);
dest.writeInt(mContent.length);
dest.writeByteArray(mContent);
dest.writeString(mViaBranchParam);
dest.writeString(mCallIdParam);
}
public static final @NonNull Creator<SipMessage> CREATOR = new Creator<SipMessage>() {

View File

@@ -31,8 +31,6 @@ import android.telephony.ims.stub.SipDelegate;
import android.text.TextUtils;
import android.util.Log;
import com.android.internal.telephony.SipMessageParsingUtils;
import java.util.ArrayList;
import java.util.Set;
import java.util.concurrent.Executor;
@@ -188,7 +186,7 @@ public class SipDelegateAidlWrapper implements DelegateStateCallback, DelegateMe
}
private void notifyLocalMessageFailedToBeReceived(SipMessage m, int reason) {
String transactionId = SipMessageParsingUtils.getTransactionId(m.getHeaderSection());
String transactionId = m.getViaBranchParameter();
if (TextUtils.isEmpty(transactionId)) {
Log.w(LOG_TAG, "failure to parse SipMessage.");
throw new IllegalArgumentException("Malformed SipMessage, can not determine "

View File

@@ -32,8 +32,6 @@ import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
import com.android.internal.telephony.SipMessageParsingUtils;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.concurrent.Executor;
@@ -268,7 +266,7 @@ public class SipDelegateConnectionAidlWrapper implements SipDelegateConnection,
}
private void notifyLocalMessageFailedToSend(SipMessage m, int reason) {
String transactionId = SipMessageParsingUtils.getTransactionId(m.getHeaderSection());
String transactionId = m.getViaBranchParameter();
if (TextUtils.isEmpty(transactionId)) {
Log.w(LOG_TAG, "sendMessage detected a malformed SipMessage and can not get a "
+ "transaction ID.");