Skip to content

Commit 71b62e0

Browse files
committed
Add missing permission checks for notifications
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
1 parent 04ad5c7 commit 71b62e0

6 files changed

Lines changed: 35 additions & 13 deletions

File tree

app/src/main/java/org/schabi/newpipe/NewVersionWorker.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ class NewVersionWorker(
8282
)
8383

8484
val notificationManager = NotificationManagerCompat.from(applicationContext)
85-
notificationManager.notify(2000, notificationBuilder.build())
85+
if (notificationManager.areNotificationsEnabled()) {
86+
notificationManager.notify(2000, notificationBuilder.build())
87+
}
8688
}
8789

8890
@Throws(IOException::class, ReCaptchaException::class)

app/src/main/java/org/schabi/newpipe/error/ErrorUtil.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ class ErrorUtil {
134134
)
135135
)
136136

137-
NotificationManagerCompat.from(context)
138-
.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
137+
val notificationManager = NotificationManagerCompat.from(context)
138+
if (notificationManager.areNotificationsEnabled()) {
139+
notificationManager
140+
.notify(ERROR_REPORT_NOTIFICATION_ID, notificationBuilder.build())
141+
}
139142

140143
ContextCompat.getMainExecutor(context).execute {
141144
// since the notification is silent, also show a toast, otherwise the user is confused

app/src/main/java/org/schabi/newpipe/local/feed/notifications/NotificationHelper.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,21 @@ class NotificationHelper(val context: Context) {
9292
// Show individual stream notifications, set channel icon only if there is actually
9393
// one
9494
showStreamNotifications(newStreams, data.serviceId, data.url, bitmap)
95-
// Show summary notification
96-
manager.notify(data.pseudoId, summaryBuilder.build())
95+
// Show summary notification if enabled
96+
if (manager.areNotificationsEnabled()) {
97+
manager.notify(data.pseudoId, summaryBuilder.build())
98+
}
9799

98100
iconLoadingTargets.remove(this) // allow it to be garbage-collected
99101
}
100102

101103
override fun onBitmapFailed(e: Exception, errorDrawable: Drawable) {
102104
// Show individual stream notifications
103105
showStreamNotifications(newStreams, data.serviceId, data.url, null)
104-
// Show summary notification
105-
manager.notify(data.pseudoId, summaryBuilder.build())
106+
// Show summary notification if enabled
107+
if (manager.areNotificationsEnabled()) {
108+
manager.notify(data.pseudoId, summaryBuilder.build())
109+
}
106110
iconLoadingTargets.remove(this) // allow it to be garbage-collected
107111
}
108112

@@ -126,7 +130,9 @@ class NotificationHelper(val context: Context) {
126130
) {
127131
for (stream in newStreams) {
128132
val notification = createStreamNotification(stream, serviceId, channelUrl, channelIcon)
129-
manager.notify(stream.url.hashCode(), notification)
133+
if (manager.areNotificationsEnabled()) {
134+
manager.notify(stream.url.hashCode(), notification)
135+
}
130136
}
131137
}
132138

app/src/main/java/org/schabi/newpipe/local/feed/service/FeedLoadService.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ class FeedLoadService : Service() {
185185
}
186186
}
187187

188-
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
188+
if (notificationManager.areNotificationsEnabled()) {
189+
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build())
190+
}
189191
}
190192

191193
// /////////////////////////////////////////////////////////////////////////

app/src/main/java/org/schabi/newpipe/local/subscription/services/BaseImportExportService.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ protected void updateNotification(final String text) {
144144
notificationBuilder.setContentText(text);
145145
}
146146

147-
notificationManager.notify(getNotificationId(), notificationBuilder.build());
147+
if (notificationManager.areNotificationsEnabled()) {
148+
notificationManager.notify(getNotificationId(), notificationBuilder.build());
149+
}
148150
}
149151

150152
protected void stopService() {
@@ -174,7 +176,10 @@ protected void postErrorResult(final String title, final String text) {
174176
.setContentTitle(title)
175177
.setStyle(new NotificationCompat.BigTextStyle().bigText(textOrEmpty))
176178
.setContentText(textOrEmpty);
177-
notificationManager.notify(getNotificationId(), notificationBuilder.build());
179+
180+
if (notificationManager.areNotificationsEnabled()) {
181+
notificationManager.notify(getNotificationId(), notificationBuilder.build());
182+
}
178183
}
179184

180185
protected NotificationCompat.Builder createNotification() {

app/src/main/java/org/schabi/newpipe/player/notification/NotificationUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public synchronized void createNotificationIfNeededAndUpdate(final boolean force
7272
notificationBuilder = createNotification();
7373
}
7474
updateNotification();
75-
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
75+
if (notificationManager.areNotificationsEnabled()) {
76+
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
77+
}
7678
}
7779

7880
public synchronized void updateThumbnail() {
@@ -84,7 +86,9 @@ public synchronized void updateThumbnail() {
8486
}
8587

8688
setLargeIcon(notificationBuilder);
87-
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
89+
if (notificationManager.areNotificationsEnabled()) {
90+
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
91+
}
8892
}
8993
}
9094

0 commit comments

Comments
 (0)