|
|
@ -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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lifecycleScope.launch {
|
|
|
|
// Get the relevant message.
|
|
|
|
// Get the relevant message.
|
|
|
|
val message = intent.getStringExtra(DISMISSED_MESSAGE_ID)?.let { messageId ->
|
|
|
|
val message = intent.getStringExtra(DISMISSED_MESSAGE_ID)?.let { messageId ->
|
|
|
|
runBlockingIncrement { nimbusMessagingController.getMessage(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,14 +212,15 @@ class NotificationClickedReceiverActivity : Activity() {
|
|
|
|
val nimbusMessagingController =
|
|
|
|
val nimbusMessagingController =
|
|
|
|
FenixNimbusMessagingController(components.analytics.messagingStorage)
|
|
|
|
FenixNimbusMessagingController(components.analytics.messagingStorage)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lifecycleScope.launch {
|
|
|
|
// Get the relevant message.
|
|
|
|
// Get the relevant message.
|
|
|
|
val message = intent.getStringExtra(CLICKED_MESSAGE_ID)?.let { messageId ->
|
|
|
|
val message = intent.getStringExtra(CLICKED_MESSAGE_ID)?.let { messageId ->
|
|
|
|
runBlockingIncrement { nimbusMessagingController.getMessage(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)
|
|
|
@ -230,6 +230,7 @@ class NotificationClickedReceiverActivity : Activity() {
|
|
|
|
// Start the message intent.
|
|
|
|
// Start the message intent.
|
|
|
|
startActivity(intent)
|
|
|
|
startActivity(intent)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// End this activity.
|
|
|
|
// End this activity.
|
|
|
|
finish()
|
|
|
|
finish()
|
|
|
|