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

Commit 264b2081 authored by Ta-wei Yen's avatar Ta-wei Yen
Browse files

Allow UTF-8 data SMS to be filtered as VVM SMS

The OMTP visual voicemail specification does not specify what the
VVM SMS is.

Previouly only data SMS that is encoded with the Data Coding Scheme
GSM 7bit or UCS2 can be recognized. These format cannot be sent with
SmsManager.sendDataMessage() and prevents CTS testing.

This CL will attempt to decode the 8bit binary DCS userdata as a UTF-8
string. This format can be sent with sendDataMessage()

Fixes: 33397325
Fixes: 36075510
Test: CTS VisualVoicemailServiceTest

Change-Id: I81aa2993d43d1a39e1192d02828a4d982475441f
parent 333c7cb3
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,9 @@ import android.util.Log;


import com.android.internal.telephony.VisualVoicemailSmsParser.WrappedMessageData;
import com.android.internal.telephony.VisualVoicemailSmsParser.WrappedMessageData;


import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
@@ -169,6 +172,7 @@ public class VisualVoicemailSmsFilter {
    @Nullable
    @Nullable
    private static String getFullMessage(byte[][] pdus, String format) {
    private static String getFullMessage(byte[][] pdus, String format) {
        StringBuilder builder = new StringBuilder();
        StringBuilder builder = new StringBuilder();
        CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder();
        for (byte pdu[] : pdus) {
        for (byte pdu[] : pdus) {
            SmsMessage message = SmsMessage.createFromPdu(pdu, format);
            SmsMessage message = SmsMessage.createFromPdu(pdu, format);


@@ -177,6 +181,19 @@ public class VisualVoicemailSmsFilter {
                return null;
                return null;
            }
            }
            String body = message.getMessageBody();
            String body = message.getMessageBody();
            if (body == null && message.getUserData() != null) {
                // Attempt to interpret the user data as UTF-8. UTF-8 string over data SMS using
                // 8BIT data coding scheme is our recommended way to send VVM SMS and is used in CTS
                // Tests. The OMTP visual voicemail specification does not specify the SMS type and
                // encoding.
                ByteBuffer byteBuffer = ByteBuffer.wrap(message.getUserData());
                try {
                    body = decoder.decode(byteBuffer).toString();
                } catch (CharacterCodingException e) {
                    // User data is not decode-able as UTF-8. Ignoring.
                    return null;
                }
            }
            if (body != null) {
            if (body != null) {
                builder.append(body);
                builder.append(body);
            }
            }