From 1de4bc95865a5eb6491db79c413d98e05e8545e3 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 26 Mar 2023 12:56:34 -0400 Subject: [PATCH] Restore POST_NOTIFICATIONS permission check for SDK 33+ Although we don't even target it yet and don't prompt for it but whatever, less work in the future. --- .../util/system/NotificationExtensions.kt | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/NotificationExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/NotificationExtensions.kt index 3958d0cdfe..5a37d66154 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/NotificationExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/NotificationExtensions.kt @@ -1,14 +1,16 @@ package eu.kanade.tachiyomi.util.system -import android.annotation.SuppressLint +import android.Manifest import android.app.Notification import android.app.NotificationManager import android.content.Context +import android.os.Build import androidx.core.app.NotificationChannelCompat import androidx.core.app.NotificationChannelGroupCompat import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import androidx.core.app.NotificationManagerCompat.NotificationWithIdAndTag +import androidx.core.content.PermissionChecker import androidx.core.content.getSystemService import eu.kanade.tachiyomi.R @@ -20,22 +22,18 @@ fun Context.notify(id: Int, channelId: String, block: (NotificationCompat.Builde this.notify(id, notification) } -@SuppressLint("MissingPermission") fun Context.notify(id: Int, notification: Notification) { - // TODO: check for permission once targeting SDK 33+ -// if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { -// return -// } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { + return + } NotificationManagerCompat.from(this).notify(id, notification) } -@SuppressLint("MissingPermission") fun Context.notify(notificationWithIdAndTags: List) { - // TODO: check for permission once targeting SDK 33+ -// if (PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { -// return -// } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU && PermissionChecker.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PermissionChecker.PERMISSION_GRANTED) { + return + } NotificationManagerCompat.from(this).notify(notificationWithIdAndTags) }