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

Commit c3d14c19 authored by Andrew Cheng's avatar Andrew Cheng Committed by Automerger Merge Worker
Browse files

Merge "Specify charset encoding UTF-8 for image-only MMS" am: 5ea0005d am:...

Merge "Specify charset encoding UTF-8 for image-only MMS" am: 5ea0005d am: 82dc14d8 am: d9a5ac9e am: 746cc900

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Bluetooth/+/1330890

Change-Id: I354068afd862ee4305722e3c9b6f01ac6fc2e233
parents 23fcf5a7 746cc900
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -3810,8 +3810,6 @@ public class BluetoothMapContent {
     * @param message the bMessage object to add the information to
     */
    private void extractMmsParts(long id, BluetoothMapbMessageMime message) {
        /* Handling of filtering out non-text parts for exclude
         * attachments is handled within the bMessage object. */
        final String[] projection = null;
        String selection = new String(Mms.Part.MSG_ID + "=" + id);
        String uriStr = new String(Mms.CONTENT_URI + "/" + id + "/part");
@@ -3847,6 +3845,28 @@ public class BluetoothMapContent {
                    part.mContentLocation = cl;
                    part.mContentDisposition = cdisp;

                    // Filtering out non-text parts (e.g., an image) when attachments are to be
                    // excluded is currently handled within the "message" object's encoding
                    // function (c.f., BluetoothMapbMessageMime.encodeMime()), where the
                    // attachment is replaced with a text string containing the part name or
                    // filename.
                    // However, replacing with text during encoding is too late, as charset
                    // information does not get properly set and propagated. For example, if a MMS
                    // consists only of a GIF, it's mimetype is "image/gif" and not "text", so
                    // 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()) {
                        StringBuilder sb = new StringBuilder();
                        try {
                            part.encodePlainText(sb);
                            text = sb.toString();
                            part.mContentType = "text";
                        } catch (UnsupportedEncodingException e) {
                            Log.d(TAG, "extractMmsParts", e);
                        }
                    }

                    try {
                        if (text != null) {
                            part.mData = text.getBytes("UTF-8");