Skip to content

Commit

Permalink
feat(notification): add API level check for getParcelable method
Browse files Browse the repository at this point in the history
SUITEDEV-34794

Co-authored-by: davidSchuppa <[email protected]>
Co-authored-by: LasOri <[email protected]>
Co-authored-by: megamegax <[email protected]>
Co-authored-by: matusekma <[email protected]>
  • Loading branch information
5 people committed Dec 12, 2023
1 parent 8165cfe commit c7b726a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import android.os.Build
object AndroidVersionUtils {
val isOreoOrAbove: Boolean
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
val isBelowTiramisu: Boolean
get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
val isBelowOreo: Boolean
get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.O
val isBelowQ: Boolean
get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
val isBelowS: Boolean
get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.S
val isBelowTiramisu: Boolean
get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
val isBelowUpsideDownCake: Boolean
get() = Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.emarsys.mobileengage.notification

import android.annotation.TargetApi
import android.content.Context
import android.content.Intent
import com.emarsys.core.Mockable
Expand Down Expand Up @@ -31,7 +32,7 @@ class NotificationCommandFactory(private val context: Context) {

fun createNotificationCommand(intent: Intent): Runnable {
val actionId = intent.action
val notificationData = if (AndroidVersionUtils.isBelowTiramisu) intent.getParcelableExtra("payload") else intent.getParcelableExtra("payload", NotificationData::class.java)
val notificationData = if (AndroidVersionUtils.isBelowUpsideDownCake) intent.getParcelableExtra("payload") else extractPayload(intent)
val action = getAction(notificationData, actionId)

val commands = createMandatoryCommands(notificationData)
Expand Down Expand Up @@ -64,6 +65,11 @@ class NotificationCommandFactory(private val context: Context) {
return CompositeCommand(commands.filterNotNull())
}

@TargetApi(34)
private fun extractPayload(intent: Intent): NotificationData? {
return intent.getParcelableExtra("payload", NotificationData::class.java)
}

private fun handlePushInformation(notificationData: NotificationData?): NotificationInformationCommand? {
val campaignId = notificationData?.campaignId
if (!campaignId.isNullOrEmpty()) {
Expand Down

0 comments on commit c7b726a

Please sign in to comment.