2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-05 16:45:08 +00:00

[SMS App] Export all addresses of multitarget messages

## Summary
Export the complete list of remote addresses of a multitarget message

Note that this changes format of the returned Message object, replacing the string "address" field with a string list "addresses" field, so it is not backwards-compatible with old desktop applications

## Test Plan
See Test Plan of the desktop-side patch: https://invent.kde.org/kde/kdeconnect-kde/merge_requests/101
This commit is contained in:
Simon Redman
2019-07-19 17:46:54 +00:00
parent 1db4327370
commit abcb6cbf33
3 changed files with 403 additions and 92 deletions

View File

@@ -75,23 +75,47 @@ public class SMSPlugin extends Plugin {
* The body should contain the key "messages" mapping to an array of messages
* <p>
* For example:
* { "messages" : [
* {
* "version": 2 // This is the second version of this packet type and
* // version 1 packets (which did not carry this flag)
* // are incompatible with the new format
* "messages" : [
* { "event" : 1, // 32-bit field containing a bitwise-or of event flags
* // See constants declared in SMSHelper.Message for defined
* // values and explanations
* "body" : "Hello", // Text message body
* "address" : "2021234567", // Sending or receiving address of the message
* "addresses": <List<Address>> // List of Address objects, one for each participant of the conversation
* // The user's Address is excluded so:
* // If this is a single-target messsage, there will only be one
* // Address (the other party)
* // If this is an incoming multi-target message, the first Address is the
* // sender and all other addresses are other parties to the conversation
* // If this is an outgoing multi-target message, the sender is implicit
* // (the user's phone number) and all Addresses are recipients
* "date" : "1518846484880", // Timestamp of the message
* "type" : "2", // Compare with Android's
* // Telephony.TextBasedSmsColumns.MESSAGE_TYPE_*
* "thread_id" : "132" // Thread to which the message belongs
* "thread_id" : 132 // Thread to which the message belongs
* "read" : true // Boolean representing whether a message is read or unread
* },
* { ... },
* ...
* ]
*
* The following optional fields of a message object may be defined
* "sub_id": <int> // Android's subscriber ID, which is basically used to determine which SIM card the message
* // belongs to. This is mostly useful when attempting to reply to an SMS with the correct
* // SIM card using PACKET_TYPE_SMS_REQUEST.
* // If this value is not defined or if it does not match a valid subscriber_id known by
* // Android, we will use whatever subscriber ID Android gives us as the default
*
* An Address object looks like:
* {
* "address": <String> // Address (phone number, email address, etc.) of this object
* }
*/
private final static String PACKET_TYPE_SMS_MESSAGE = "kdeconnect.sms.messages";
private final static int SMS_MESSAGE_PACKET_VERSION = 2; // We *send* packets of this version
/**
* Packet sent to request a message be sent
@@ -280,6 +304,10 @@ public class SMSPlugin extends Plugin {
ContentObserver messageObserver = new MessageContentObserver(new Handler(helperLooper));
SMSHelper.registerObserver(messageObserver, context);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
Log.w("SMSPlugin", "This is a very old version of Android. The SMS Plugin might not function as intended.");
}
return true;
}
@@ -346,12 +374,12 @@ public class SMSPlugin extends Plugin {
body.put(json);
} catch (JSONException e) {
Log.e("Conversations", "Error serializing message");
Log.e("Conversations", "Error serializing message", e);
}
}
reply.set("messages", body);
reply.set("event", "batch_messages");
reply.set("version", SMS_MESSAGE_PACKET_VERSION);
return reply;
}
@@ -426,14 +454,23 @@ public class SMSPlugin extends Plugin {
return new String[]{
Manifest.permission.SEND_SMS,
Manifest.permission.READ_SMS,
// READ_PHONE_STATE should be optional, since we can just query the user, but that
// requires a GUI implementation for querying the user!
Manifest.permission.READ_PHONE_STATE,
};
}
/**
* I suspect we can actually go lower than this, but it might get unstable
* With versions older than KITKAT, lots of the content providers used in SMSHelper become
* un-documented. Most manufacturers *did* do things the same way as was done in mainline
* Android at that time, but some did not. If the manufacturer followed the default route,
* everything will be fine. If not, the plugin will crash. But, since we have a global catch-all
* in Device.onPacketReceived, it will not crash catastrophically.
* The onCreated method of this SMSPlugin complains if a version older than KitKat is loaded,
* but it still allowed in the optimistic hope that things will "just work"
*/
@Override
public int getMinSdk() {
return Build.VERSION_CODES.KITKAT;
return Build.VERSION_CODES.FROYO;
}
}