summaryrefslogtreecommitdiff
path: root/telephony/java
diff options
context:
space:
mode:
authorAllen Su <allenwtsu@google.com>2021-01-25 18:10:11 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-01-25 18:10:11 +0000
commit725e04e4f1c2835faf0cac587946e014069bb201 (patch)
treeac43bfd153b051f44b022f9710ab28a4105c523c /telephony/java
parent8910e2c51bec1fb846993fcf579a5e319364c964 (diff)
parent227d47f9ec0b29f1d96e6b80fb3af257c61bea16 (diff)
Merge "[RCS]Add getEncodedMessage() in SipMessage.java"
Diffstat (limited to 'telephony/java')
-rw-r--r--telephony/java/android/telephony/ims/SipMessage.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/telephony/java/android/telephony/ims/SipMessage.java b/telephony/java/android/telephony/ims/SipMessage.java
index 006cca84e44b..9cfa640fce18 100644
--- a/telephony/java/android/telephony/ims/SipMessage.java
+++ b/telephony/java/android/telephony/ims/SipMessage.java
@@ -16,6 +16,8 @@
package android.telephony.ims;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.os.Build;
@@ -39,6 +41,7 @@ import java.util.Objects;
public final class SipMessage implements Parcelable {
// Should not be set to true for production!
private static final boolean IS_DEBUGGING = Build.IS_ENG;
+ private static final String CRLF = "\r\n";
private final String mStartLine;
private final String mHeaderSection;
@@ -165,4 +168,19 @@ public final class SipMessage implements Parcelable {
result = 31 * result + Arrays.hashCode(mContent);
return result;
}
+
+ /**
+ * @return the UTF-8 encoded SIP message.
+ */
+ public @NonNull byte[] getEncodedMessage() {
+ byte[] header = new StringBuilder()
+ .append(mStartLine)
+ .append(mHeaderSection)
+ .append(CRLF)
+ .toString().getBytes(UTF_8);
+ byte[] sipMessage = new byte[header.length + mContent.length];
+ System.arraycopy(header, 0, sipMessage, 0, header.length);
+ System.arraycopy(mContent, 0, sipMessage, header.length, mContent.length);
+ return sipMessage;
+ }
}