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

Commit d53a30b9 authored by Steve Kondik's avatar Steve Kondik
Browse files

Fix encoding of UTF-16 SMS.

parent b4c226a9
Loading
Loading
Loading
Loading
+34 −34
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ public class SmsMessage extends SmsMessageBase{
    public static SubmitPdu getSubmitPdu(String scAddress,
            String destinationAddress, String message,
            boolean statusReportRequested, byte[] header) {
        return getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested, header, ENCODING_UNKNOWN);
        return getSubmitPdu(scAddress, destinationAddress, message, statusReportRequested, header, ENCODING_7BIT);
    }
    
    
@@ -249,6 +249,8 @@ public class SmsMessage extends SmsMessageBase{
            return null;
        }

        Log.i(LOG_TAG, "Using encoding supplied as: " + encoding);
        		
        SubmitPdu ret = new SubmitPdu();
        // MTI = SMS-SUBMIT, UDHI = header != null
        byte mtiByte = (byte)(0x01 | (header != null ? 0x40 : 0x00));
@@ -257,35 +259,31 @@ public class SmsMessage extends SmsMessageBase{
                statusReportRequested, ret);
        // User Data (and length)
        byte[] userData;
        if(encoding == ENCODING_UNKNOWN){
            // First, try encoding it with the GSM alphabet
            encoding = ENCODING_7BIT;
        }

        try {
        	try {
        		if(encoding == ENCODING_7BIT){
        			userData = GsmAlphabet.stringToGsm7BitPackedWithHeader(message, header);
            }else{ //assume UCS-2
                try{
                    userData = encodeUCS2(message, header);
                }catch(UnsupportedEncodingException uex){
                    Log.e(LOG_TAG,
                            "Implausible UnsupportedEncodingException ",
                            uex);
                    return null;
        		}
        		else { //assume UCS-2
        			userData = encodeUCS2(message, header);
        			encoding = ENCODING_16BIT;
        		}

        	} catch (EncodeException ex) {
        		// Encoding to the 7-bit alphabet failed. Let's see if we can
        		// send it as a UCS-2 encoded message
            try{
        		Log.i(LOG_TAG, "7-bit encode failed, trying UCS2");
        		userData = encodeUCS2(message, header);
        		encoding = ENCODING_16BIT;
        	}

        } catch (UnsupportedEncodingException uex) {
        	Log.e(LOG_TAG,
        			"Implausible UnsupportedEncodingException ",
        			uex);
        	return null;
        }
        }
              
        if (encoding == ENCODING_7BIT) {
            if ((0xff & userData[0]) > MAX_USER_DATA_SEPTETS) {
@@ -309,9 +307,11 @@ public class SmsMessage extends SmsMessageBase{
            // TP-Data-Coding-Scheme
            // Class 3, UCS-2 encoding, uncompressed
            bo.write(0x0b);
        }
            
            // (no TP-Validity-Period)

        }
        
        bo.write(userData, 0, userData.length);
        ret.encodedMessage = bo.toByteArray();
        return ret;