From 7ed4efedc3077eaee21e239c1bc97e9b5b94c7bd Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Thu, 13 Jun 2024 12:07:06 +0200 Subject: [PATCH] Fix SecurityException if the notifications permission was revoked --- .../Plugins/NotificationsPlugin/NotificationsPlugin.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java index e352fae1..61125ece 100644 --- a/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java @@ -106,6 +106,10 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. @Override public boolean checkRequiredPermissions() { + return hasNotificationsPermission(); + } + + private boolean hasNotificationsPermission() { //Notifications use a different kind of permission, because it was added before the current runtime permissions model String notificationListenerList = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners"); return StringUtils.contains(notificationListenerList, context.getPackageName()); @@ -506,6 +510,9 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. } private void sendCurrentNotifications(NotificationReceiver service) { + if (!hasNotificationsPermission()) { + return; + } StatusBarNotification[] notifications = service.getActiveNotifications(); if (notifications != null) { //Can happen only on API 23 and lower for (StatusBarNotification notification : notifications) {