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 FenixDependencies.androidx_navigation_ui
implementation ComponentsDependencies.androidx_compose_navigation implementation ComponentsDependencies.androidx_compose_navigation
implementation ComponentsDependencies.androidx_recyclerview implementation ComponentsDependencies.androidx_recyclerview
implementation ComponentsDependencies.androidx_lifecycle_common implementation ComponentsDependencies.androidx_lifecycle_common
implementation ComponentsDependencies.androidx_lifecycle_livedata implementation ComponentsDependencies.androidx_lifecycle_livedata
implementation ComponentsDependencies.androidx_lifecycle_process implementation ComponentsDependencies.androidx_lifecycle_process
implementation ComponentsDependencies.androidx_lifecycle_runtime implementation ComponentsDependencies.androidx_lifecycle_runtime
implementation ComponentsDependencies.androidx_lifecycle_viewmodel implementation ComponentsDependencies.androidx_lifecycle_viewmodel
implementation ComponentsDependencies.androidx_lifecycle_service
implementation ComponentsDependencies.androidx_core implementation ComponentsDependencies.androidx_core
implementation ComponentsDependencies.androidx_core_ktx implementation ComponentsDependencies.androidx_core_ktx
implementation FenixDependencies.androidx_core_splashscreen implementation FenixDependencies.androidx_core_splashscreen

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

Loading…
Cancel
Save