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,7 +57,16 @@ class NotificationListener: NotificationListenerService() {
|
||||||
|
|
||||||
runAsync {
|
runAsync {
|
||||||
if (shouldRemoveNotification(sbn) == NotificationHandling.Replace) {
|
if (shouldRemoveNotification(sbn) == NotificationHandling.Replace) {
|
||||||
cancelNotification(sbn.key)
|
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(
|
notificationManager.notify(
|
||||||
sbn.packageName,
|
sbn.packageName,
|
||||||
|
@ -65,7 +74,12 @@ class NotificationListener: NotificationListenerService() {
|
||||||
NotificationCompat.Builder(this@NotificationListener, NotificationChannels.BLOCKED_NOTIFICATIONS_NOTIFICATION)
|
NotificationCompat.Builder(this@NotificationListener, NotificationChannels.BLOCKED_NOTIFICATIONS_NOTIFICATION)
|
||||||
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||||
.setSmallIcon(R.drawable.ic_stat_block)
|
.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))
|
.setContentText(queryAppTitleCache.query(sbn.packageName))
|
||||||
.setLocalOnly(true)
|
.setLocalOnly(true)
|
||||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
|
|
|
@ -16,4 +16,5 @@
|
||||||
-->
|
-->
|
||||||
<resources>
|
<resources>
|
||||||
<string name="notification_filter_not_blocked_title">TimeLimit hat eine Benachrichtigung blockiert</string>
|
<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>
|
</resources>
|
||||||
|
|
|
@ -16,4 +16,5 @@
|
||||||
-->
|
-->
|
||||||
<resources>
|
<resources>
|
||||||
<string name="notification_filter_not_blocked_title">TimeLimit has blocked a notification</string>
|
<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>
|
</resources>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue