Merge "Validate SipMessages have a correct Via branch parameter" am: 71715457e7 am: 6a34d0784d
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1663521 Change-Id: I710dc269f002fb7e912b6392a2d66b6a30cd3064
This commit is contained in:
@@ -11988,7 +11988,7 @@ package android.telephony.ims {
|
|||||||
method @NonNull public byte[] getEncodedMessage();
|
method @NonNull public byte[] getEncodedMessage();
|
||||||
method @NonNull public String getHeaderSection();
|
method @NonNull public String getHeaderSection();
|
||||||
method @NonNull public String getStartLine();
|
method @NonNull public String getStartLine();
|
||||||
method @Nullable public String getViaBranchParameter();
|
method @NonNull public String getViaBranchParameter();
|
||||||
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
method public void writeToParcel(@NonNull android.os.Parcel, int);
|
||||||
field @NonNull public static final android.os.Parcelable.Creator<android.telephony.ims.SipMessage> CREATOR;
|
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.Build;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.internal.telephony.SipMessageParsingUtils;
|
import com.android.internal.telephony.SipMessageParsingUtils;
|
||||||
|
|
||||||
@@ -60,14 +61,19 @@ public final class SipMessage implements Parcelable {
|
|||||||
*/
|
*/
|
||||||
public SipMessage(@NonNull String startLine, @NonNull String headerSection,
|
public SipMessage(@NonNull String startLine, @NonNull String headerSection,
|
||||||
@NonNull byte[] content) {
|
@NonNull byte[] content) {
|
||||||
if (startLine == null || headerSection == null || content == null) {
|
Objects.requireNonNull(startLine, "Required parameter is null: startLine");
|
||||||
throw new IllegalArgumentException("One or more null parameters entered");
|
Objects.requireNonNull(headerSection, "Required parameter is null: headerSection");
|
||||||
}
|
Objects.requireNonNull(content, "Required parameter is null: content");
|
||||||
|
|
||||||
mStartLine = startLine;
|
mStartLine = startLine;
|
||||||
mHeaderSection = headerSection;
|
mHeaderSection = headerSection;
|
||||||
mContent = content;
|
mContent = content;
|
||||||
|
|
||||||
mViaBranchParam = SipMessageParsingUtils.getTransactionId(mHeaderSection);
|
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);
|
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
|
* @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
|
* 20.42 for more information on the Via header.
|
||||||
* Via parameter found in this SIP message's headers or no branch parameter found in the
|
|
||||||
* Via header.
|
|
||||||
*/
|
*/
|
||||||
public @Nullable String getViaBranchParameter() {
|
public @NonNull String getViaBranchParameter() {
|
||||||
return mViaBranchParam;
|
return mViaBranchParam;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ import android.telephony.ims.SipDelegateImsConfiguration;
|
|||||||
import android.telephony.ims.SipDelegateManager;
|
import android.telephony.ims.SipDelegateManager;
|
||||||
import android.telephony.ims.SipMessage;
|
import android.telephony.ims.SipMessage;
|
||||||
import android.telephony.ims.stub.SipDelegate;
|
import android.telephony.ims.stub.SipDelegate;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -187,11 +185,6 @@ public class SipDelegateAidlWrapper implements DelegateStateCallback, DelegateMe
|
|||||||
|
|
||||||
private void notifyLocalMessageFailedToBeReceived(SipMessage m, int reason) {
|
private void notifyLocalMessageFailedToBeReceived(SipMessage m, int reason) {
|
||||||
String transactionId = m.getViaBranchParameter();
|
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;
|
SipDelegate d = mDelegate;
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
mExecutor.execute(() -> d.notifyMessageReceiveError(transactionId, reason));
|
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.DelegateConnectionMessageCallback;
|
||||||
import android.telephony.ims.stub.DelegateConnectionStateCallback;
|
import android.telephony.ims.stub.DelegateConnectionStateCallback;
|
||||||
import android.telephony.ims.stub.SipDelegate;
|
import android.telephony.ims.stub.SipDelegate;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@@ -267,12 +266,6 @@ public class SipDelegateConnectionAidlWrapper implements SipDelegateConnection,
|
|||||||
|
|
||||||
private void notifyLocalMessageFailedToSend(SipMessage m, int reason) {
|
private void notifyLocalMessageFailedToSend(SipMessage m, int reason) {
|
||||||
String transactionId = m.getViaBranchParameter();
|
String transactionId = m.getViaBranchParameter();
|
||||||
if (TextUtils.isEmpty(transactionId)) {
|
mExecutor.execute(() -> mMessageCallback.onMessageSendFailure(transactionId, reason));
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user