Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove CustomerIOPushReceiver #250

Merged
merged 27 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions messagingpush/api/messagingpush.api
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,16 @@ public final class io/customer/messagingpush/provider/FCMTokenProviderImpl : io/
}

public abstract interface class io/customer/messagingpush/util/DeepLinkUtil {
public abstract fun createDeepLinkExternalIntent (Landroid/content/Context;Ljava/lang/String;Z)Landroid/content/Intent;
public abstract fun createDeepLinkExternalIntent (Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;
public abstract fun createDeepLinkHostAppIntent (Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;
public abstract fun createDefaultHostAppIntent (Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;
public abstract fun createDefaultHostAppIntent (Landroid/content/Context;)Landroid/content/Intent;
}

public final class io/customer/messagingpush/util/DeepLinkUtilImpl : io/customer/messagingpush/util/DeepLinkUtil {
public fun <init> (Lio/customer/sdk/util/Logger;Lio/customer/messagingpush/MessagingPushModuleConfig;)V
public fun createDeepLinkExternalIntent (Landroid/content/Context;Ljava/lang/String;Z)Landroid/content/Intent;
public fun createDeepLinkExternalIntent (Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;
public fun createDeepLinkHostAppIntent (Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;
public fun createDefaultHostAppIntent (Landroid/content/Context;Ljava/lang/String;)Landroid/content/Intent;
public fun createDefaultHostAppIntent (Landroid/content/Context;)Landroid/content/Intent;
}

public abstract interface class io/customer/messagingpush/util/PushTrackingUtil {
Expand Down
8 changes: 0 additions & 8 deletions messagingpush/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@
</intent-filter>
</service>

<!-- Action receiver for push interactions -->
<receiver
android:name=".CustomerIOPushReceiver"
android:exported="false">
<intent-filter>
<action android:name="io.customer.messagingpush.PUSH_ACTION" />
</intent-filter>
</receiver>
<!--
Broadcast receiver for listening to push events from GoogleCloudMessaging (GCM). The receiver
listens to message broadcast emitted by Google Cloud APIs. Read class docs for more details.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ import android.os.Bundle
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.core.app.NotificationCompat
import androidx.core.app.TaskStackBuilder
import com.google.firebase.messaging.FirebaseMessagingService
import com.google.firebase.messaging.RemoteMessage
import io.customer.messagingpush.activity.NotificationClickReceiverActivity
import io.customer.messagingpush.data.model.CustomerIOParsedPushPayload
import io.customer.messagingpush.di.deepLinkUtil
import io.customer.messagingpush.di.moduleConfig
import io.customer.messagingpush.extensions.*
import io.customer.messagingpush.processor.PushMessageProcessor
import io.customer.messagingpush.util.DeepLinkUtil
import io.customer.messagingpush.util.PushTrackingUtil.Companion.DELIVERY_ID_KEY
import io.customer.messagingpush.util.PushTrackingUtil.Companion.DELIVERY_TOKEN_KEY
import io.customer.sdk.CustomerIO
Expand Down Expand Up @@ -71,9 +68,6 @@ internal class CustomerIOPushNotificationHandler(
private val moduleConfig: MessagingPushModuleConfig
get() = diGraph.moduleConfig

private val deepLinkUtil: DeepLinkUtil
get() = diGraph.deepLinkUtil

private val bundle: Bundle by lazy {
Bundle().apply {
remoteMessage.data.forEach { entry ->
Expand Down Expand Up @@ -223,51 +217,6 @@ internal class CustomerIOPushNotificationHandler(
notificationManager.notify(requestCode, notification)
}

private fun createIntentFromLink(
context: Context,
requestCode: Int,
payload: CustomerIOParsedPushPayload
): PendingIntent? {
// In Android 12, you must specify the mutability of each PendingIntent
val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}

if (context.applicationInfo.targetSdkVersion > Build.VERSION_CODES.R) {
val taskStackBuilder = moduleConfig.notificationCallback?.createTaskStackFromPayload(
context,
payload
) ?: kotlin.run {
val pushContentIntent: Intent? = deepLinkUtil.createDeepLinkHostAppIntent(
context,
payload.deepLink
) ?: deepLinkUtil.createDefaultHostAppIntent(context, payload.deepLink)
pushContentIntent?.putExtras(bundle)

return@run pushContentIntent?.let { intent ->
TaskStackBuilder.create(context).run {
addNextIntentWithParentStack(intent)
}
}
}

return taskStackBuilder?.getPendingIntent(requestCode, flags)
} else {
val pushContentIntent = Intent(CustomerIOPushReceiver.ACTION)
pushContentIntent.setClass(context, CustomerIOPushReceiver::class.java)

pushContentIntent.putExtra(CustomerIOPushReceiver.PUSH_PAYLOAD_KEY, payload)
return PendingIntent.getBroadcast(
context,
requestCode,
pushContentIntent,
flags
)
}
}

private fun createIntentForNotificationClick(
context: Context,
requestCode: Int,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package io.customer.messagingpush

import androidx.annotation.VisibleForTesting
import io.customer.base.internal.InternalCustomerIOApi
import io.customer.messagingpush.di.deepLinkUtil
import io.customer.messagingpush.di.fcmTokenProvider
import io.customer.messagingpush.di.pushTrackingUtil
import io.customer.messagingpush.lifecycle.MessagingPushLifecycleCallback
Expand Down Expand Up @@ -41,7 +40,6 @@ internal constructor(
diGraph.activityLifecycleCallbacks.registerCallback(
MessagingPushLifecycleCallback(
moduleConfig = moduleConfig,
deepLinkUtil = diGraph.deepLinkUtil,
pushTrackingUtil = diGraph.pushTrackingUtil
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,14 @@ class NotificationClickReceiverActivity : Activity(), TrackableScreen {
}

// Get the default intent for the host app
val defaultHostAppIntent = deepLinkUtil.createDefaultHostAppIntent(
context = this,
contentActionLink = null
)
val defaultHostAppIntent = deepLinkUtil.createDefaultHostAppIntent(context = this)
// Check if the deep links are handled within the host app
val deepLinkHostAppIntent = deepLink?.let { link ->
deepLinkUtil.createDeepLinkHostAppIntent(context = this, link = link)
}
// Check if the deep links can be opened outside the host app
val deepLinkExternalIntent = deepLink?.let { link ->
deepLinkUtil.createDeepLinkExternalIntent(
context = this,
link = link,
startingFromService = true
)
deepLinkUtil.createDeepLinkExternalIntent(context = this, link = link)
}
val deepLinkIntent: Intent = deepLinkHostAppIntent
?: deepLinkExternalIntent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package io.customer.messagingpush.lifecycle

import android.app.Activity
import android.content.Context
import android.os.Bundle
import androidx.lifecycle.Lifecycle
import io.customer.messagingpush.MessagingPushModuleConfig
import io.customer.messagingpush.util.DeepLinkUtil
import io.customer.messagingpush.util.PushTrackingUtil
import io.customer.sdk.lifecycle.LifecycleCallback

internal class MessagingPushLifecycleCallback internal constructor(
private val moduleConfig: MessagingPushModuleConfig,
private val deepLinkUtil: DeepLinkUtil,
private val pushTrackingUtil: PushTrackingUtil
) : LifecycleCallback {
override val eventsToObserve: List<Lifecycle.Event> = listOf(Lifecycle.Event.ON_CREATE)
Expand All @@ -24,28 +21,9 @@ internal class MessagingPushLifecycleCallback internal constructor(
if (moduleConfig.autoTrackPushEvents) {
pushTrackingUtil.parseLaunchedActivityForTracking(intentArguments)
}
launchContentAction(
activity,
intentArguments.getString(PENDING_CONTENT_ACTION_LINK)
)
}
else -> {}
}
}

private fun launchContentAction(context: Context, actionLink: String?) {
if (actionLink.isNullOrBlank()) return

deepLinkUtil.createDeepLinkExternalIntent(
context = context,
link = actionLink,
startingFromService = false
)?.let { contentIntent ->
context.startActivity(contentIntent)
else -> {}
}
}

companion object {
internal const val PENDING_CONTENT_ACTION_LINK = "CIO-Pending-Content-Action-Link"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@ interface DeepLinkUtil {
* Creates default launcher intent for host app.
*
* @param context reference to application context
* @param contentActionLink action link to add to extras so it can be
* opened after launcher activity has been created. This helps opening
* external links without affecting open metrics on Android 12 and
* onwards.
* @return launcher intent for host app; null if fail to resolve
* default launcher intent
*/
fun createDefaultHostAppIntent(context: Context, contentActionLink: String?): Intent?
fun createDefaultHostAppIntent(context: Context): Intent?

/**
* Creates intent from host app activities matching the provided link.
Expand All @@ -37,23 +33,20 @@ interface DeepLinkUtil {
*
* @param context reference to application context
* @param link link to create intent for
* @param startingFromService flag to indicate if the intent is to be
* started from service so required flags can be added
* @return intent that can open the link outside the host app; null if no
* matching intent found
*/
fun createDeepLinkExternalIntent(
context: Context,
link: String,
startingFromService: Boolean
link: String
): Intent?
}

class DeepLinkUtilImpl(
private val logger: Logger,
private val moduleConfig: MessagingPushModuleConfig
) : DeepLinkUtil {
override fun createDefaultHostAppIntent(context: Context, contentActionLink: String?): Intent? {
override fun createDefaultHostAppIntent(context: Context): Intent? {
return context.packageManager.getLaunchIntentForPackage(context.packageName)
}

Expand All @@ -67,11 +60,7 @@ class DeepLinkUtilImpl(
return intent
}

override fun createDeepLinkExternalIntent(
context: Context,
link: String,
startingFromService: Boolean
): Intent? {
override fun createDeepLinkExternalIntent(context: Context, link: String): Intent? {
// check config if the deep link should be opened by any other app or not
if (!moduleConfig.redirectDeepLinksToOtherApps) {
return null
Expand Down