2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 14:15:14 +00:00

Fix SecurityException if the notifications permission was revoked

This commit is contained in:
Albert Vaca Cintora
2024-06-13 12:07:06 +02:00
parent 96ecd620cf
commit 7ed4efedc3

View File

@@ -106,6 +106,10 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
@Override @Override
public boolean checkRequiredPermissions() { 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 //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"); String notificationListenerList = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners");
return StringUtils.contains(notificationListenerList, context.getPackageName()); return StringUtils.contains(notificationListenerList, context.getPackageName());
@@ -506,6 +510,9 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
} }
private void sendCurrentNotifications(NotificationReceiver service) { private void sendCurrentNotifications(NotificationReceiver service) {
if (!hasNotificationsPermission()) {
return;
}
StatusBarNotification[] notifications = service.getActiveNotifications(); StatusBarNotification[] notifications = service.getActiveNotifications();
if (notifications != null) { //Can happen only on API 23 and lower if (notifications != null) { //Can happen only on API 23 and lower
for (StatusBarNotification notification : notifications) { for (StatusBarNotification notification : notifications) {