mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] Closes 28414: NotificationManagerCompat extension to safely check if notifications are enabled
This commit is contained in:
parent
506cf152fb
commit
d760e57572
@ -0,0 +1,20 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
|
||||
/**
|
||||
* Returns whether notifications are enabled, catches any exception that was thrown from
|
||||
* [NotificationManagerCompat.areNotificationsEnabled] and returns false.
|
||||
*/
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
fun NotificationManagerCompat.areNotificationsEnabledSafe(): Boolean {
|
||||
return try {
|
||||
areNotificationsEnabled()
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ import android.os.Build
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import org.mozilla.fenix.GleanMetrics.Events.marketingNotificationAllowed
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.areNotificationsEnabledSafe
|
||||
|
||||
// Channel ID was not updated when it was renamed to marketing. Thus, we'll have to continue
|
||||
// to use this ID as the marketing channel ID
|
||||
@ -47,12 +48,7 @@ fun ensureMarketingChannelExists(context: Context): String {
|
||||
channelEnabled = channel.importance != NotificationManager.IMPORTANCE_NONE
|
||||
}
|
||||
|
||||
@Suppress("TooGenericExceptionCaught")
|
||||
val notificationsEnabled = try {
|
||||
NotificationManagerCompat.from(context).areNotificationsEnabled()
|
||||
} catch (e: Exception) {
|
||||
false
|
||||
}
|
||||
val notificationsEnabled = NotificationManagerCompat.from(context).areNotificationsEnabledSafe()
|
||||
|
||||
marketingNotificationAllowed.set(notificationsEnabled && channelEnabled)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user