Bug 1811795 - Use a notification delegate in notification workers.

Notification workers in Fenix will now use notification delegate to show notifications.
fenix/113.0
mcarare 1 year ago committed by Ryan VanderMeulen
parent 61c8d0275d
commit 19302fb973

@ -12,7 +12,6 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.IBinder
import androidx.core.app.NotificationManagerCompat
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
@ -22,7 +21,6 @@ import mozilla.components.service.nimbus.messaging.FxNimbusMessaging
import mozilla.components.service.nimbus.messaging.Message
import mozilla.components.support.base.ids.SharedIdsHelper
import mozilla.components.support.utils.BootUtils
import org.mozilla.fenix.ext.areNotificationsEnabledSafe
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.onboarding.ensureMarketingChannelExists
import org.mozilla.fenix.perf.runBlockingIncrement
@ -47,11 +45,6 @@ class MessageNotificationWorker(
override fun doWork(): Result {
val context = applicationContext
val nm = NotificationManagerCompat.from(context)
if (!nm.areNotificationsEnabledSafe()) {
return Result.success()
}
val messagingStorage = context.components.analytics.messagingStorage
val messages = runBlockingIncrement { messagingStorage.getMessages() }
val nextMessage =
@ -76,7 +69,7 @@ class MessageNotificationWorker(
runBlockingIncrement { nimbusMessagingController.onMessageDisplayed(updatedMessage) }
nm.notify(
context.components.notificationsDelegate.notify(
MESSAGE_TAG,
SharedIdsHelper.getIdForTag(context, updatedMessage.id),
buildNotification(

@ -9,7 +9,6 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.annotation.VisibleForTesting
import androidx.core.app.NotificationManagerCompat
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
@ -20,6 +19,7 @@ import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.utils.IntentUtils
@ -51,12 +51,11 @@ class ReEngagementNotificationWorker(
}
val channelId = ensureMarketingChannelExists(applicationContext)
NotificationManagerCompat.from(applicationContext)
.notify(
NOTIFICATION_TAG,
RE_ENGAGEMENT_NOTIFICATION_ID,
buildNotification(channelId),
)
applicationContext.components.notificationsDelegate.notify(
NOTIFICATION_TAG,
RE_ENGAGEMENT_NOTIFICATION_ID,
buildNotification(channelId),
)
// re-engagement notification should only be shown once
settings.reEngagementNotificationShown = true

Loading…
Cancel
Save