Bug 1874675 - Replaced usages of runBlocking in MessageNotificationWorker

fenix/123.0
t-p-white 5 months ago committed by mergify[bot]
parent 0f632af5ae
commit 3694a61fb4

@ -636,12 +636,14 @@ dependencies {
implementation FenixDependencies.androidx_navigation_ui
implementation ComponentsDependencies.androidx_compose_navigation
implementation ComponentsDependencies.androidx_recyclerview
implementation ComponentsDependencies.androidx_lifecycle_common
implementation ComponentsDependencies.androidx_lifecycle_livedata
implementation ComponentsDependencies.androidx_lifecycle_process
implementation ComponentsDependencies.androidx_lifecycle_runtime
implementation ComponentsDependencies.androidx_lifecycle_viewmodel
implementation ComponentsDependencies.androidx_lifecycle_service
implementation ComponentsDependencies.androidx_core
implementation ComponentsDependencies.androidx_core_ktx
implementation FenixDependencies.androidx_core_splashscreen

@ -4,26 +4,26 @@
package org.mozilla.fenix.messaging
import android.app.Activity
import android.app.Notification
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.IBinder
import androidx.activity.ComponentActivity
import androidx.lifecycle.LifecycleService
import androidx.lifecycle.lifecycleScope
import androidx.work.CoroutineWorker
import androidx.work.ExistingPeriodicWorkPolicy
import androidx.work.PeriodicWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.WorkerParameters
import kotlinx.coroutines.launch
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.components
import org.mozilla.fenix.onboarding.ensureMarketingChannelExists
import org.mozilla.fenix.perf.runBlockingIncrement
import org.mozilla.fenix.utils.IntentUtils
import org.mozilla.fenix.utils.createBaseNotification
import java.util.concurrent.TimeUnit
@ -170,28 +170,27 @@ class MessageNotificationWorker(
* When a [Message] [Notification] is dismissed by the user record telemetry data and update the
* [Message.metadata].
*
* This [Service] is only intended to be used by the [MessageNotificationWorker.createOnDismissPendingIntent] function.
* This Service is only intended to be used by the [MessageNotificationWorker.createOnDismissPendingIntent] function.
*/
class NotificationDismissedService : Service() {
/**
* This service cannot be bound to.
*/
override fun onBind(intent: Intent?): IBinder? = null
class NotificationDismissedService : LifecycleService() {
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
super.onStartCommand(intent, flags, startId)
if (intent != null) {
val nimbusMessagingController =
FenixNimbusMessagingController(applicationContext.components.analytics.messagingStorage)
// Get the relevant message.
val message = intent.getStringExtra(DISMISSED_MESSAGE_ID)?.let { messageId ->
runBlockingIncrement { nimbusMessagingController.getMessage(messageId) }
}
lifecycleScope.launch {
// Get the relevant message.
val message = intent.getStringExtra(DISMISSED_MESSAGE_ID)?.let { messageId ->
nimbusMessagingController.getMessage(messageId)
}
if (message != null) {
// Update message as 'dismissed'.
runBlockingIncrement { nimbusMessagingController.onMessageDismissed(message.metadata) }
if (message != null) {
// Update message as 'dismissed'.
nimbusMessagingController.onMessageDismissed(message.metadata)
}
}
}
@ -203,9 +202,9 @@ class NotificationDismissedService : Service() {
* When a [Message] [Notification] is clicked by the user record telemetry data and update the
* [Message.metadata].
*
* This [Activity] is only intended to be used by the [MessageNotificationWorker.createOnClickPendingIntent] function.
* This Activity is only intended to be used by the [MessageNotificationWorker.createOnClickPendingIntent] function.
*/
class NotificationClickedReceiverActivity : Activity() {
class NotificationClickedReceiverActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -213,22 +212,24 @@ class NotificationClickedReceiverActivity : Activity() {
val nimbusMessagingController =
FenixNimbusMessagingController(components.analytics.messagingStorage)
// Get the relevant message.
val message = intent.getStringExtra(CLICKED_MESSAGE_ID)?.let { messageId ->
runBlockingIncrement { nimbusMessagingController.getMessage(messageId) }
}
lifecycleScope.launch {
// Get the relevant message.
val message = intent.getStringExtra(CLICKED_MESSAGE_ID)?.let { messageId ->
nimbusMessagingController.getMessage(messageId)
}
if (message != null) {
// Update message as 'clicked'.
runBlockingIncrement { nimbusMessagingController.onMessageClicked(message.metadata) }
if (message != null) {
// Update message as 'clicked'.
nimbusMessagingController.onMessageClicked(message.metadata)
// Create the intent.
val intent = nimbusMessagingController.getIntentForMessage(message)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
// Create the intent.
val intent = nimbusMessagingController.getIntentForMessage(message)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
// Start the message intent.
startActivity(intent)
// Start the message intent.
startActivity(intent)
}
}
// End this activity.

Loading…
Cancel
Save