From e74743c684a0ec0741d36b9e65b0c3a3351afb66 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Thu, 9 Jul 2020 15:17:58 +0530 Subject: [PATCH] Use StringUtils.contains(). --- src/org/kde/kdeconnect/Helpers/SMSHelper.java | 12 +++--------- .../MprisReceiverPlugin/MprisReceiverPlugin.java | 3 ++- .../NotificationsPlugin/NotificationsPlugin.java | 3 ++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/org/kde/kdeconnect/Helpers/SMSHelper.java b/src/org/kde/kdeconnect/Helpers/SMSHelper.java index 004d950e..dd83c0d7 100644 --- a/src/org/kde/kdeconnect/Helpers/SMSHelper.java +++ b/src/org/kde/kdeconnect/Helpers/SMSHelper.java @@ -40,6 +40,7 @@ import androidx.annotation.RequiresApi; import com.klinker.android.send_message.Utils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -257,17 +258,10 @@ public class SMSHelper { null, null) ) { - if (availableColumnsCursor != null) { - return true; // if we got the cursor, the query shouldn't fail - } - return false; + return availableColumnsCursor != null; // if we got the cursor, the query shouldn't fail } catch (SQLiteException | IllegalArgumentException e) { // With uri content://mms-sms/conversations this query throws an exception if sub_id is not supported - String errMessage = e.getMessage(); - if (errMessage != null && errMessage.contains(Telephony.Sms.SUBSCRIPTION_ID)) { - return false; - } - return true; + return !StringUtils.contains(e.getMessage(), Telephony.Sms.SUBSCRIPTION_ID); } } diff --git a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java index 4b63ccf6..1d38600c 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java @@ -34,6 +34,7 @@ import androidx.annotation.RequiresApi; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; +import org.apache.commons.lang3.StringUtils; import org.kde.kdeconnect.Helpers.AppsHelper; import org.kde.kdeconnect.NetworkPacket; import org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationReceiver; @@ -260,7 +261,7 @@ public class MprisReceiverPlugin extends Plugin { private boolean hasPermission() { String notificationListenerList = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners"); - return (notificationListenerList != null && notificationListenerList.contains(context.getPackageName())); + return StringUtils.contains(notificationListenerList, context.getPackageName()); } } diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java index 6ef13b5e..e244e25f 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java @@ -51,6 +51,7 @@ import androidx.fragment.app.DialogFragment; import org.apache.commons.collections4.MultiValuedMap; import org.apache.commons.collections4.multimap.ArrayListValuedHashMap; +import org.apache.commons.lang3.StringUtils; import org.json.JSONArray; import org.kde.kdeconnect.Helpers.AppsHelper; import org.kde.kdeconnect.NetworkPacket; @@ -121,7 +122,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. private boolean hasPermission() { String notificationListenerList = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners"); - return (notificationListenerList != null && notificationListenerList.contains(context.getPackageName())); + return StringUtils.contains(notificationListenerList, context.getPackageName()); } @Override