Add missing permission checks for notifications

Notifications can be disabled manually even after permission has been granted once.
Always check if they are enabled before notifying the user.

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta 2026-02-05 12:56:37 +08:00
parent d33c3737ec
commit d35d5fa5d4
6 changed files with 38 additions and 15 deletions

View file

@ -82,8 +82,10 @@ class NewVersionWorker(
) )
val notificationManager = NotificationManagerCompat.from(applicationContext) val notificationManager = NotificationManagerCompat.from(applicationContext)
if (notificationManager.areNotificationsEnabled()) {
notificationManager.notify(2000, notificationBuilder.build()) notificationManager.notify(2000, notificationBuilder.build())
} }
}
@Throws(IOException::class, ReCaptchaException::class) @Throws(IOException::class, ReCaptchaException::class)
private fun checkNewVersion() { private fun checkNewVersion() {

View file

@ -134,8 +134,11 @@ class ErrorUtil {
) )
) )
NotificationManagerCompat.from(context) val notificationManager = NotificationManagerCompat.from(context)
if (notificationManager.areNotificationsEnabled()) {
notificationManager
.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build()) .notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
}
ContextCompat.getMainExecutor(context).execute { ContextCompat.getMainExecutor(context).execute {
// since the notification is silent, also show a toast, otherwise the user is confused // since the notification is silent, also show a toast, otherwise the user is confused

View file

@ -92,8 +92,10 @@ class NotificationHelper(val context: Context) {
// Show individual stream notifications, set channel icon only if there is actually // Show individual stream notifications, set channel icon only if there is actually
// one // one
showStreamNotifications(newStreams, data.serviceId, data.url, bitmap) showStreamNotifications(newStreams, data.serviceId, data.url, bitmap)
// Show summary notification // Show summary notification if enabled
if (manager.areNotificationsEnabled()) {
manager.notify(data.pseudoId, summaryBuilder.build()) manager.notify(data.pseudoId, summaryBuilder.build())
}
iconLoadingTargets.remove(this) // allow it to be garbage-collected iconLoadingTargets.remove(this) // allow it to be garbage-collected
} }
@ -101,8 +103,10 @@ class NotificationHelper(val context: Context) {
override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) { override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) {
// Show individual stream notifications // Show individual stream notifications
showStreamNotifications(newStreams, data.serviceId, data.url, null) showStreamNotifications(newStreams, data.serviceId, data.url, null)
// Show summary notification // Show summary notification if enabled
if (manager.areNotificationsEnabled()) {
manager.notify(data.pseudoId, summaryBuilder.build()) manager.notify(data.pseudoId, summaryBuilder.build())
}
iconLoadingTargets.remove(this) // allow it to be garbage-collected iconLoadingTargets.remove(this) // allow it to be garbage-collected
} }
@ -124,11 +128,14 @@ class NotificationHelper(val context: Context) {
channelUrl: String, channelUrl: String,
channelIcon: Bitmap? channelIcon: Bitmap?
) { ) {
for (stream in newStreams) { if (manager.areNotificationsEnabled()) {
val notification = createStreamNotification(stream, serviceId, channelUrl, channelIcon) newStreams.forEach { stream ->
val notification =
createStreamNotification(stream, serviceId, channelUrl, channelIcon)
manager.notify(stream.url.hashCode(), notification) manager.notify(stream.url.hashCode(), notification)
} }
} }
}
private fun createStreamNotification( private fun createStreamNotification(
item: StreamInfoItem, item: StreamInfoItem,

View file

@ -185,8 +185,10 @@ class FeedLoadService : Service() {
} }
} }
if (notificationManager.areNotificationsEnabled()) {
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()) notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
} }
}
// ///////////////////////////////////////////////////////////////////////// // /////////////////////////////////////////////////////////////////////////
// Notification Actions // Notification Actions

View file

@ -144,8 +144,10 @@ public abstract class BaseImportExportService extends Service {
notificationBuilder.setContentText(text); notificationBuilder.setContentText(text);
} }
if (notificationManager.areNotificationsEnabled()) {
notificationManager.notify(getNotificationId(), notificationBuilder.build()); notificationManager.notify(getNotificationId(), notificationBuilder.build());
} }
}
protected void stopService() { protected void stopService() {
postErrorResult(null, null); postErrorResult(null, null);
@ -174,8 +176,11 @@ public abstract class BaseImportExportService extends Service {
.setContentTitle(title) .setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty)) .setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty))
.setContentText(textOrEmpty); .setContentText(textOrEmpty);
if (notificationManager.areNotificationsEnabled()) {
notificationManager.notify(getNotificationId(), notificationBuilder.build()); notificationManager.notify(getNotificationId(), notificationBuilder.build());
} }
}
protected NotificationCompat.Builder createNotification() { protected NotificationCompat.Builder createNotification() {
return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id)) return new NotificationCompat.Builder(this, getString(R.string.notification_channel_id))

View file

@ -72,8 +72,10 @@ public final class NotificationUtil {
notificationBuilder = createNotification(); notificationBuilder = createNotification();
} }
updateNotification(); updateNotification();
if (notificationManager.areNotificationsEnabled()) {
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
} }
}
public synchronized void updateThumbnail() { public synchronized void updateThumbnail() {
if (notificationBuilder != null) { if (notificationBuilder != null) {
@ -84,9 +86,11 @@ public final class NotificationUtil {
} }
setLargeIcon(notificationBuilder); setLargeIcon(notificationBuilder);
if (notificationManager.areNotificationsEnabled()) {
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build()); notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
} }
} }
}
private synchronized NotificationCompat.Builder createNotification() { private synchronized NotificationCompat.Builder createNotification() {
if (DEBUG) { if (DEBUG) {