mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 10:49:29 +02:00
Catch SecurityException in NotificationListener
This commit is contained in:
parent
a8bff6149d
commit
a833037136
3 changed files with 18 additions and 2 deletions
|
@ -57,15 +57,29 @@ class NotificationListener: NotificationListenerService() {
|
|||
|
||||
runAsync {
|
||||
if (shouldRemoveNotification(sbn) == NotificationHandling.Replace) {
|
||||
val success = try {
|
||||
cancelNotification(sbn.key)
|
||||
|
||||
true
|
||||
} catch (ex: SecurityException) {
|
||||
// this occurs when the notification access is revoked
|
||||
// while this function is running
|
||||
|
||||
false
|
||||
}
|
||||
|
||||
notificationManager.notify(
|
||||
sbn.packageName,
|
||||
NotificationIds.NOTIFICATION_BLOCKED,
|
||||
NotificationCompat.Builder(this@NotificationListener, NotificationChannels.BLOCKED_NOTIFICATIONS_NOTIFICATION)
|
||||
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||
.setSmallIcon(R.drawable.ic_stat_block)
|
||||
.setContentTitle(getString(R.string.notification_filter_not_blocked_title))
|
||||
.setContentTitle(
|
||||
if (success)
|
||||
getString(R.string.notification_filter_not_blocked_title)
|
||||
else
|
||||
getString(R.string.notification_filter_blocking_failed_title)
|
||||
)
|
||||
.setContentText(queryAppTitleCache.query(sbn.packageName))
|
||||
.setLocalOnly(true)
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
|
|
|
@ -16,4 +16,5 @@
|
|||
-->
|
||||
<resources>
|
||||
<string name="notification_filter_not_blocked_title">TimeLimit hat eine Benachrichtigung blockiert</string>
|
||||
<string name="notification_filter_blocking_failed_title">TimeLimit konnte eine Benachrichtigung nicht blockieren</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,4 +16,5 @@
|
|||
-->
|
||||
<resources>
|
||||
<string name="notification_filter_not_blocked_title">TimeLimit has blocked a notification</string>
|
||||
<string name="notification_filter_blocking_failed_title">TimeLimit could not block a notification</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue