Skip to content

Commit

Permalink
Merge pull request #2018 from OneSignal/fix/always-initWithContext-on…
Browse files Browse the repository at this point in the history
…-process-entry-points

[Fix] Call initWithContext on all entry points
  • Loading branch information
jkasten2 authored Mar 12, 2024
2 parents 94c9fb7 + 5aa610c commit 3c79306
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ internal class NotificationGenerationWorkManager : INotificationGenerationWorkMa

class NotificationGenerationWorker(context: Context, workerParams: WorkerParameters) : CoroutineWorker(context, workerParams) {
override suspend fun doWork(): Result {
if (!OneSignal.isInitialized) {
return Result.failure()
if (!OneSignal.initWithContext(applicationContext)) {
return Result.success()
}

val notificationProcessor: INotificationGenerationProcessor = OneSignal.getService()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ internal class ReceiveReceiptWorkManager(
}

class ReceiveReceiptWorker(context: Context, workerParams: WorkerParameters) : CoroutineWorker(context, workerParams) {
private var receiveReceiptProcessor: IReceiveReceiptProcessor = OneSignal.getService()

override suspend fun doWork(): Result {
val inputData = inputData
if (!OneSignal.initWithContext(applicationContext)) {
return Result.success()
}

val notificationId = inputData.getString(OS_NOTIFICATION_ID)!!
val appId = inputData.getString(OS_APP_ID)!!
val subscriptionId = inputData.getString(OS_SUBSCRIPTION_ID)!!

val receiveReceiptProcessor = OneSignal.getService<IReceiveReceiptProcessor>()
receiveReceiptProcessor.sendReceiveReceipt(appId, subscriptionId, notificationId)
return Result.success()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ import com.onesignal.notifications.internal.registration.impl.IPushRegistratorCa
class ADMMessageHandler : ADMMessageHandlerBase("ADMMessageHandler") {
override fun onMessage(intent: Intent) {
val context = applicationContext
if (!OneSignal.initWithContext(context)) {
return
}

val bundle = intent.extras

val bundleProcessor = OneSignal.getService<INotificationBundleProcessor>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ class ADMMessageHandlerJob : ADMMessageHandlerJobBase() {
context: Context?,
intent: Intent?,
) {
val bundle = intent?.extras

if (context == null) {
return
}
if (!OneSignal.initWithContext(context.applicationContext)) {
return
}
val bundleProcessor = OneSignal.getService<INotificationBundleProcessor>()

val bundle = intent?.extras

bundleProcessor.processBundleFromReceiver(context!!, bundle!!)
}

Expand Down

0 comments on commit 3c79306

Please sign in to comment.