From bf042cc963d3f2507e53d1410a3a1becfdfff889 Mon Sep 17 00:00:00 2001 From: Cristian Dregan Date: Fri, 10 Jun 2022 16:32:12 +0300 Subject: [PATCH] Release 1.2.3 --- OmetriaSDK/build.gradle | 2 +- .../java/com/android/ometriasdk/core/Ometria.kt | 13 ++++++++----- .../notification/OmetriaPushNotification.kt | 10 +++++++++- .../notification/PushClickBroadcastReceiver.kt | 7 +------ app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 1 + app/src/main/java/com/android/sample/SampleApp.kt | 3 +++ 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/OmetriaSDK/build.gradle b/OmetriaSDK/build.gradle index dd69ab1..6239eb1 100644 --- a/OmetriaSDK/build.gradle +++ b/OmetriaSDK/build.gradle @@ -9,7 +9,7 @@ android { minSdkVersion 21 targetSdkVersion 29 versionCode 1 - versionName "1.2.2" + versionName "1.2.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles "consumer-rules.pro" diff --git a/OmetriaSDK/src/main/java/com/android/ometriasdk/core/Ometria.kt b/OmetriaSDK/src/main/java/com/android/ometriasdk/core/Ometria.kt index d04eb1f..e98fd6e 100644 --- a/OmetriaSDK/src/main/java/com/android/ometriasdk/core/Ometria.kt +++ b/OmetriaSDK/src/main/java/com/android/ometriasdk/core/Ometria.kt @@ -4,6 +4,7 @@ import android.app.Application import android.app.Notification.COLOR_DEFAULT import android.content.Intent import android.net.Uri +import android.webkit.URLUtil import androidx.core.app.NotificationManagerCompat import androidx.lifecycle.ProcessLifecycleOwner import com.android.ometriasdk.core.Constants.Params.BASKET @@ -412,11 +413,13 @@ class Ometria private constructor() : OmetriaNotificationInteractionHandler { remoteMessage.toOmetriaNotification() override fun onNotificationInteraction(ometriaNotification: OmetriaNotification) { - ometriaNotification.deepLinkActionUrl.let { safeDeeplinkActionUrl -> - Logger.d( - Constants.Logger.PUSH_NOTIFICATIONS, - "Open URL: $safeDeeplinkActionUrl" - ) + ometriaNotification.deepLinkActionUrl?.let { safeDeeplinkActionUrl -> + if (URLUtil.isValidUrl(safeDeeplinkActionUrl).not()) { + Logger.e(Constants.Logger.PUSH_NOTIFICATIONS, "Can not open $safeDeeplinkActionUrl") + return + } + + Logger.d(Constants.Logger.PUSH_NOTIFICATIONS, "Open URL: $safeDeeplinkActionUrl") val intent = Intent(Intent.ACTION_VIEW) intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK intent.data = Uri.parse(safeDeeplinkActionUrl) diff --git a/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/OmetriaPushNotification.kt b/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/OmetriaPushNotification.kt index f8291f7..7452d24 100644 --- a/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/OmetriaPushNotification.kt +++ b/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/OmetriaPushNotification.kt @@ -1,5 +1,6 @@ package com.android.ometriasdk.notification +import android.annotation.SuppressLint import android.app.Notification import android.app.NotificationChannel import android.app.NotificationManager @@ -27,6 +28,7 @@ internal class OmetriaPushNotification( private val notificationColor: Int? ) { + @SuppressLint("LaunchActivityFromNotification") fun createPushNotification( title: String?, body: String?, @@ -38,7 +40,7 @@ internal class OmetriaPushNotification( context, System.currentTimeMillis().toInt(), getRoutingIntent(ometriaNotificationBody), - PendingIntent.FLAG_UPDATE_CURRENT + getFlags() ) val notificationBuilder = NotificationCompat.Builder(context, OMETRIA_CHANNEL_ID) @@ -76,4 +78,10 @@ internal class OmetriaPushNotification( .setClass(context, PushClickBroadcastReceiver::class.java) .putExtras(options) } + + private fun getFlags(): Int = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT + } else { + PendingIntent.FLAG_UPDATE_CURRENT + } } \ No newline at end of file diff --git a/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/PushClickBroadcastReceiver.kt b/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/PushClickBroadcastReceiver.kt index b0d2d31..7f8eb63 100644 --- a/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/PushClickBroadcastReceiver.kt +++ b/OmetriaSDK/src/main/java/com/android/ometriasdk/notification/PushClickBroadcastReceiver.kt @@ -3,7 +3,6 @@ package com.android.ometriasdk.notification import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import android.webkit.URLUtil import com.android.ometriasdk.core.Ometria import com.android.ometriasdk.core.event.OmetriaEventType import com.android.ometriasdk.core.network.toOmetriaNotification @@ -28,15 +27,11 @@ internal class PushClickBroadcastReceiver : BroadcastReceiver() { val ometriaNotificationBody = intent.getStringExtra(OMETRIA_NOTIFICATION_BODY_KEY)?.toOmetriaNotificationBody() - ometriaNotificationBody?.let { safeOmetriaNotificationBody -> - if (safeOmetriaNotificationBody.deepLinkActionUrl != null - && URLUtil.isValidUrl(safeOmetriaNotificationBody.deepLinkActionUrl) - ) { + if (safeOmetriaNotificationBody.deepLinkActionUrl != null) { Ometria.instance().notificationInteractionHandler.onDeepLinkInteraction( safeOmetriaNotificationBody.deepLinkActionUrl ) - } Ometria.instance().notificationInteractionHandler.onNotificationInteraction( safeOmetriaNotificationBody.toOmetriaNotification() diff --git a/app/build.gradle b/app/build.gradle index c203ea6..e273f41 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -11,7 +11,7 @@ android { defaultConfig { applicationId "com.android.sample" minSdkVersion 21 - targetSdkVersion 29 + targetSdkVersion 31 versionCode 1 versionName "1.0.0" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fccd4b5..407a4fe 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,7 @@ android:theme="@style/AppTheme"> diff --git a/app/src/main/java/com/android/sample/SampleApp.kt b/app/src/main/java/com/android/sample/SampleApp.kt index 65199bc..34c47b1 100644 --- a/app/src/main/java/com/android/sample/SampleApp.kt +++ b/app/src/main/java/com/android/sample/SampleApp.kt @@ -4,6 +4,7 @@ import android.app.Application import android.content.Intent import android.net.Uri import android.util.Log +import android.webkit.URLUtil import androidx.core.content.ContextCompat import com.android.ometriasdk.core.Ometria import com.android.ometriasdk.notification.OmetriaNotification @@ -55,6 +56,8 @@ class SampleApp : Application(), OmetriaNotificationInteractionHandler { private fun openBrowser(deepLink: String?) { deepLink?.let { safeDeepLink -> + if (URLUtil.isValidUrl(safeDeepLink).not()) return + Ometria.instance() .trackDeepLinkOpenedEvent(safeDeepLink, "Browser") Log.d(SampleApp::class.java.simpleName, "Open URL: $safeDeepLink")