Merge "Validate SipMessages have a correct Via branch parameter"
This commit is contained in:
@@ -11988,7 +11988,7 @@ package android.telephony.ims {
|
||||
method @NonNull public byte[] getEncodedMessage();
|
||||
method @NonNull public String getHeaderSection();
|
||||
method @NonNull public String getStartLine();
|
||||
method @Nullable public String getViaBranchParameter();
|
||||
method @NonNull 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;
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.annotation.SystemApi;
|
||||
import android.os.Build;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.telephony.SipMessageParsingUtils;
|
||||
|
||||
@@ -60,14 +61,19 @@ public final class SipMessage implements Parcelable {
|
||||
*/
|
||||
public SipMessage(@NonNull String startLine, @NonNull String headerSection,
|
||||
@NonNull byte[] content) {
|
||||
if (startLine == null || headerSection == null || content == null) {
|
||||
throw new IllegalArgumentException("One or more null parameters entered");
|
||||
}
|
||||
Objects.requireNonNull(startLine, "Required parameter is null: startLine");
|
||||
Objects.requireNonNull(headerSection, "Required parameter is null: headerSection");
|
||||
Objects.requireNonNull(content, "Required parameter is null: content");
|
||||
|
||||
mStartLine = startLine;
|
||||
mHeaderSection = headerSection;
|
||||
mContent = content;
|
||||
|
||||
mViaBranchParam = SipMessageParsingUtils.getTransactionId(mHeaderSection);
|
||||
if (TextUtils.isEmpty(mViaBranchParam)) {
|
||||
throw new IllegalArgumentException("header section MUST contain a branch parameter "
|
||||
+ "inside of the Via header.");
|
||||
}
|
||||
mCallIdParam = SipMessageParsingUtils.getCallId(mHeaderSection);
|
||||
}
|
||||
|
||||
@@ -107,11 +113,9 @@ public final class SipMessage implements Parcelable {
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* 20.42 for more information on the Via header.
|
||||
*/
|
||||
public @Nullable String getViaBranchParameter() {
|
||||
public @NonNull String getViaBranchParameter() {
|
||||
return mViaBranchParam;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,6 @@ import android.telephony.ims.SipDelegateImsConfiguration;
|
||||
import android.telephony.ims.SipDelegateManager;
|
||||
import android.telephony.ims.SipMessage;
|
||||
import android.telephony.ims.stub.SipDelegate;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
@@ -187,11 +185,6 @@ public class SipDelegateAidlWrapper implements DelegateStateCallback, DelegateMe
|
||||
|
||||
private void notifyLocalMessageFailedToBeReceived(SipMessage m, int reason) {
|
||||
String transactionId = m.getViaBranchParameter();
|
||||
if (TextUtils.isEmpty(transactionId)) {
|
||||
Log.w(LOG_TAG, "failure to parse SipMessage.");
|
||||
throw new IllegalArgumentException("Malformed SipMessage, can not determine "
|
||||
+ "transaction ID.");
|
||||
}
|
||||
SipDelegate d = mDelegate;
|
||||
if (d != null) {
|
||||
mExecutor.execute(() -> d.notifyMessageReceiveError(transactionId, reason));
|
||||
|
||||
@@ -28,7 +28,6 @@ import android.telephony.ims.SipMessage;
|
||||
import android.telephony.ims.stub.DelegateConnectionMessageCallback;
|
||||
import android.telephony.ims.stub.DelegateConnectionStateCallback;
|
||||
import android.telephony.ims.stub.SipDelegate;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
@@ -267,12 +266,6 @@ public class SipDelegateConnectionAidlWrapper implements SipDelegateConnection,
|
||||
|
||||
private void notifyLocalMessageFailedToSend(SipMessage m, int reason) {
|
||||
String transactionId = m.getViaBranchParameter();
|
||||
if (TextUtils.isEmpty(transactionId)) {
|
||||
Log.w(LOG_TAG, "sendMessage detected a malformed SipMessage and can not get a "
|
||||
+ "transaction ID.");
|
||||
throw new IllegalArgumentException("Could not send SipMessage due to malformed header");
|
||||
}
|
||||
mExecutor.execute(() ->
|
||||
mMessageCallback.onMessageSendFailure(transactionId, reason));
|
||||
mExecutor.execute(() -> mMessageCallback.onMessageSendFailure(transactionId, reason));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user