Add support for sending and receiving SMSes longer than 160 characters
ClosedPublic

Authored by sredman on May 14 2017, 1:33 AM.

Details

Summary

The SMS protocol does not support sending a message longer than 160 characters. Android's SmsManager.sendTextMessage(..) fails to send in case the message is too long.
Instead of failing, check the message length. If it is longer than 160 characters, break it up and send it as several messages

On receive, collect the list of messages, then combine their bodies

Test Plan

Send a long message via KDE Connect and verify that it is actually sent
Send a short message via KDE Connect and verify that it can also be sent
Ideally: Test sending a message which is the maximum length for an SMS (160 characters) and verify that it is sent as exactly one SMS (And billed properly)

Receive a long message and verify that it is delivered as a single long message, even though we all know that it was transmitted as a multi-part SMS
Receive a short message and verify that it is correctly delivered

Diff Detail

Repository
R225 KDE Connect - Android application
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
sredman created this revision.May 14 2017, 1:33 AM
sredman retitled this revision from Add support for SMSes longer than 160 characters to Add support for sending SMSes longer than 160 characters.May 14 2017, 1:58 AM
sredman edited reviewers, added: KDE Connect; removed: kdeconnect.May 14 2017, 2:02 AM
sredman updated this revision to Diff 14498.May 14 2017, 2:49 AM
  • Add support for recieving multi-part SMS messages
sredman retitled this revision from Add support for sending SMSes longer than 160 characters to Add support for sending and receiving SMSes longer than 160 characters.May 14 2017, 2:54 AM
sredman edited the summary of this revision. (Show Details)
sredman edited the test plan for this revision. (Show Details)
albertvaka requested changes to this revision.May 14 2017, 10:12 AM
albertvaka added a subscriber: albertvaka.

Thanks for the patch! This was something really missing in KDE Connect :)

If you fix the small issue I commented inline, the rest looks good to me.

src/org/kde/kdeconnect/Plugins/TelepathyPlugin/TelepathyPlugin.java
71

SMS lenght is more difficult to calculate than just checking the length of the string: it depends on the encoding used and the size of each specific character in that encoding (see [1]).

Luckily enough, looks like there is a really easy solution. We can just always call smsManager.divideMessage and then smsManager.sendMultipartTextMessage regardless of the size and number of parts. Viewing the source code from Android [2], it looks like sendMultipartTextMessage handles correctly the case of short SMS that fit in a single message.

[1] https://messente.com/documentation/tools/sms-length-calculator
[2] https://android.googlesource.com/platform/frameworks/opt/telephony/+/4931e2c/src/java/android/telephony/SmsManager.java#178

This revision now requires changes to proceed.May 14 2017, 10:12 AM
sredman updated this revision to Diff 14513.May 14 2017, 4:28 PM
sredman edited edge metadata.

Add support for sending and recieving multi-part SMS messages

sredman marked an inline comment as done.May 14 2017, 4:35 PM

Oops. Hold everything. I just realized you linked me to the SmsManager source, not the default messanging app. I need to learn to read more carefully! Let me amend the commit to not bother checking, since SmsManager is doing that for us.

sredman updated this revision to Diff 14514.May 14 2017, 4:46 PM

Add support for sending and recieving multi-part SMS messages

I'm glad you knew to look for that -- That would have been a real nasty bug to find. But not for me, since I don't have an easy way to type non-ascii characters :)

One thing I was worried about is messages which are 160 bytes long -- Since the multi-part SMS protocol adds a header, this might get sent as two -- Happily, Android's SmsManager.divideMessage does correctly account for this as far as I can tell from looking at my bill, and a 160 byte message is "divided" into a single 160 byte message.

albertvaka accepted this revision.May 16 2017, 7:01 PM

Perfect, looks good now! I'll push this change and make a release.

This revision is now accepted and ready to land.May 16 2017, 7:01 PM
This revision was automatically updated to reflect the committed changes.