diff options
author | Sanket Agarwal <sanketa@google.com> | 2015-07-21 12:11:31 -0700 |
---|---|---|
committer | Sanket Agarwal <sanketa@google.com> | 2016-02-04 17:09:32 -0800 |
commit | b15a8306d22839f252a5c4de597e1d35a9f107a0 (patch) | |
tree | 4bee00e266217d0ce088dabf2f80899a84cab63a /src/android/bluetooth/client/map/BluetoothMapBmessageParser.java | |
parent | a3acb17ad38d82048816b37cc1eb6b7872540961 (diff) | |
download | bluetooth-b15a8306d22839f252a5c4de597e1d35a9f107a0.tar.gz |
Use only UTF-8 for fetching a message.
Currently the API lets the users fetch SMS using either UTF-8 or native
SMS-PDU format. SMS-PDU is not supported by the String() class (also its
more complicated than just a simple string encoding since it contains
recipient etc information). Besides, the library does not decode such
messages and leaves it to the user to handle them. Currently it decodes
it as the default character set on device which is incorrect behavior.
Hence in this change we ensure that the API can only be used with UTF-8
which makes the conversion of Strings consistent.
NOTE: It's OK to avoid supporting native charset since it is not
mandatory in MAPv12 spec.
Change-Id: Ic10a82ff69f848cb3f6e80353d3e63ce3910d306
(cherry picked from commit 4b4d3f8260c9b4476f900ee7b08ee66450624081)
Diffstat (limited to 'src/android/bluetooth/client/map/BluetoothMapBmessageParser.java')
-rw-r--r-- | src/android/bluetooth/client/map/BluetoothMapBmessageParser.java | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/android/bluetooth/client/map/BluetoothMapBmessageParser.java b/src/android/bluetooth/client/map/BluetoothMapBmessageParser.java index ef75e7b..d4da25c 100644 --- a/src/android/bluetooth/client/map/BluetoothMapBmessageParser.java +++ b/src/android/bluetooth/client/map/BluetoothMapBmessageParser.java @@ -33,11 +33,13 @@ import android.bluetooth.client.map.utils.BmsgTokenizer.Property; import java.io.ByteArrayInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.text.ParseException; class BluetoothMapBmessageParser { private final static String TAG = "BluetoothMapBmessageParser"; + private final boolean DBG = false; private final static String CRLF = "\r\n"; @@ -75,6 +77,10 @@ class BluetoothMapBmessageParser { static public BluetoothMapBmessage createBmessage(String str) { BluetoothMapBmessageParser p = new BluetoothMapBmessageParser(); + if (DBG) { + Log.d(TAG, "actual wired contents: " + str); + } + try { p.parse(str); } catch (IOException e) { @@ -291,6 +297,17 @@ class BluetoothMapBmessageParser { } while (!prop.equals(BEGIN_MSG)); /* + * check that the charset is always set to UTF-8. We expect only text transfer (in lieu with + * the MAPv12 specifying only RFC2822 (text only) for MMS/EMAIL and SMS do not support + * non-text content. If the charset is not set to UTF-8, it is safe to set the message as + * empty. We force the getMessage (see BluetoothMasClient) to only call getMessage with + * UTF-8 as the MCE is not obliged to support native charset. + */ + if (!mBmsg.mBbodyCharset.equals("UTF-8")) { + Log.e(TAG, "The charset was not set to charset UTF-8: " + mBmsg.mBbodyCharset); + } + + /* * <bmessage-body-content>::={ "BEGIN:MSG"<CRLF> 'message'<CRLF> * "END:MSG"<CRLF> } */ @@ -314,7 +331,11 @@ class BluetoothMapBmessageParser { if (prop != null) { if (prop.equals(END_MSG)) { - mBmsg.mMessage = new String(data, 0, messageLen); + if (mBmsg.mBbodyCharset.equals("UTF-8")) { + mBmsg.mMessage = new String(data, 0, messageLen, StandardCharsets.UTF_8); + } else { + mBmsg.mMessage = null; + } } else { /* Handle possible exception for incorrect LENGTH value * from MSE while parsing GET Message response */ @@ -346,7 +367,11 @@ class BluetoothMapBmessageParser { throw expected(END_MSG); } - mBmsg.mMessage = remng.substring(0, messageLen); + if (mBmsg.mBbodyCharset.equals("UTF-8")) { + mBmsg.mMessage = remng.substring(0, messageLen); + } else { + mBmsg.mMessage = null; + } } prop = mParser.next(); |