Commit ba5a9250 authored by Nicolas Fella's avatar Nicolas Fella

Require KitKat for SMS plugin

parent d7c8f61c
......@@ -94,6 +94,7 @@ public class SMSHelper {
* @param threadID Thread to look up
* @return List of all messages in the thread
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static List<Message> getMessagesInThread(Context context, ThreadID threadID) {
final String selection = ThreadID.lookupColumn + " == ?";
final String[] selectionArgs = new String[] { threadID.toString() };
......@@ -107,6 +108,7 @@ public class SMSHelper {
* @param timestamp epoch in millis matching the timestamp to return
* @return null if no matching message is found, otherwise return a Message
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static List<Message> getMessagesSinceTimestamp(Context context, long timestamp) {
final String selection = Message.DATE + " > ?";
final String[] selectionArgs = new String[] {Long.toString(timestamp)};
......@@ -123,10 +125,11 @@ public class SMSHelper {
* @param selectionArgs Parameters for selection. May be null.
* @return Returns HashMap<ThreadID, List<Message>>, which is transformed in caller functions into other classes.
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private static HashMap<ThreadID, List<Message>> getMessages(Uri Uri,
Context context,
String selection,
String[] selectionArgs) {
Context context,
String selection,
String[] selectionArgs) {
HashMap<ThreadID, List<Message>> toReturn = new HashMap<>();
try (Cursor myCursor = context.getContentResolver().query(
Uri,
......@@ -168,6 +171,7 @@ public class SMSHelper {
* @param selectionArgs Parameters for selection. May be null.
* @return List of messages matching the filter
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private static List<Message> getMessagesWithFilter(Context context, String selection, String[] selectionArgs) {
HashMap<ThreadID, List<Message>> result = getMessages(SMSHelper.getSMSUri(), context, selection, selectionArgs);
List<Message> toReturn = new ArrayList<>();
......@@ -185,6 +189,7 @@ public class SMSHelper {
* @param context android.content.Context running the request
* @return Mapping of thread_id to the first message in each thread
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static Map<ThreadID, Message> getConversations(Context context) {
HashMap<ThreadID, List<Message>> result = getMessages(SMSHelper.getConversationUri(), context, null, null);
HashMap<ThreadID, Message> toReturn = new HashMap<>();
......@@ -214,6 +219,7 @@ public class SMSHelper {
/**
* Represent an ID used to uniquely identify a message thread
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static class ThreadID {
final Long threadID;
static final String lookupColumn = Telephony.Sms.THREAD_ID;
......@@ -241,6 +247,7 @@ public class SMSHelper {
/**
* Represent a message and all of its interesting data columns
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public static class Message {
final String address;
......
......@@ -29,6 +29,7 @@ import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
......@@ -58,6 +59,7 @@ import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import static org.kde.kdeconnect.Plugins.TelephonyPlugin.TelephonyPlugin.PACKET_TYPE_TELEPHONY;
......@@ -179,6 +181,7 @@ public class SMSPlugin extends Plugin {
* In this case, this onChange expects to be called whenever *anything* in the Messages
* database changes and simply reports those updated messages to anyone who might be listening
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public void onChange(boolean selfChange) {
if (mPlugin.mostRecentTimestamp == 0) {
......@@ -272,6 +275,7 @@ public class SMSPlugin extends Plugin {
device.sendPacket(np);
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public boolean onCreate() {
permissionExplanation = R.string.telepathy_permission_explanation;
......@@ -297,6 +301,7 @@ public class SMSPlugin extends Plugin {
return context.getResources().getString(R.string.pref_plugin_telepathy_desc);
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
public boolean onPacketReceived(NetworkPacket np) {
......@@ -339,6 +344,7 @@ public class SMSPlugin extends Plugin {
* @param messages Messages to include in the packet
* @return NetworkPacket of type PACKET_TYPE_SMS_MESSAGE
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private static NetworkPacket constructBulkMessagePacket(Collection<SMSHelper.Message> messages) {
NetworkPacket reply = new NetworkPacket(PACKET_TYPE_SMS_MESSAGE);
......@@ -367,6 +373,7 @@ public class SMSPlugin extends Plugin {
* <p>
* Send one packet of type PACKET_TYPE_SMS_MESSAGE with the first message in all conversations
*/
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private boolean handleRequestConversations(NetworkPacket packet) {
Map<SMSHelper.ThreadID, SMSHelper.Message> conversations = SMSHelper.getConversations(this.context);
......@@ -387,6 +394,7 @@ public class SMSPlugin extends Plugin {
return true;
}
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private boolean handleRequestConversation(NetworkPacket packet) {
SMSHelper.ThreadID threadID = new SMSHelper.ThreadID(packet.getLong("threadID"));
......@@ -434,4 +442,9 @@ public class SMSPlugin extends Plugin {
Manifest.permission.READ_SMS,
};
}
@Override
public int getMinSdk() {
return Build.VERSION_CODES.KITKAT;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment