Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7180a5a2 authored by Andrew Cheng's avatar Andrew Cheng
Browse files

Fix MMS returns Bad Request

Existing code tried to replace attachments with a text string,
irrespective of whether the mime part was an attachment or not. This
caused MAP to return Bad Request when mime part was text content type.

Also removed a redundant newline when an attachment is converted to a
text string.

Fixes: 178589673
Tag: #stability
Test: atest BluetoothInstrumentationTests
Test: Verify phone no longer returns a "sent Bad Request" obex
error in HCI logs when attempting a Get "x-bt/message" on a
plain text MMS.

Change-Id: I2b87746e45f8f02dbfe37eee0f5620d92ecad106
parent c9e4f1c2
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -3856,10 +3856,20 @@ public class BluetoothMapContent {
                    // according to spec, "charset" should not be set. However, if the attachment
                    // is replaced with a text string, the bMessage now contains text and should
                    // have charset set to UTF-8 according to spec.
                    if (!message.getIncludeAttachments()) {
                    if (!part.mContentType.toUpperCase().contains("TEXT")
                            && !message.getIncludeAttachments()) {
                        StringBuilder sb = new StringBuilder();
                        try {
                            part.encodePlainText(sb);
                            // Each time {@code encodePlainText} is called, it adds {@code "\r\n"}
                            // to the string. {@code encodePlainText} is called here to replace
                            // an image with a string, but later on, when we encode the entire
                            // bMessage in {@link BluetoothMapbMessageMime#encode()},
                            // {@code encodePlainText} will be called again on this {@code
                            // MimePart} (as text this time), adding a second {@code "\r\n"}. So
                            // we remove the extra newline from the end.
                            int newlineIndex = sb.lastIndexOf("\r\n");
                            if (newlineIndex != -1) sb.delete(newlineIndex, newlineIndex + 4);
                            text = sb.toString();
                            part.mContentType = "text";
                        } catch (UnsupportedEncodingException e) {