From 014afcdfe1029cf5464f9744ca7ff6b0c898724c Mon Sep 17 00:00:00 2001 From: Ryan Morales Date: Mon, 7 Aug 2023 11:50:21 -0700 Subject: [PATCH 1/3] fix map casting exception use a copy of the local notification user info map instead of casting it as the cast was causing an exception due to the user info map being unmodifiable. --- .../mobile/services/ui/AndroidUIService.java | 9 ++-- .../services/ui/AndroidUIServiceTests.java | 43 +++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/AndroidUIService.java b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/AndroidUIService.java index 4c36d7ec3..8ccdb2ec0 100644 --- a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/AndroidUIService.java +++ b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/AndroidUIService.java @@ -26,6 +26,7 @@ import com.adobe.marketing.mobile.services.ServiceConstants; import com.adobe.marketing.mobile.services.ServiceProvider; import com.adobe.marketing.mobile.services.ui.internal.MessagesMonitor; +import com.adobe.marketing.mobile.util.MapUtils; import java.lang.reflect.Field; import java.security.SecureRandom; import java.util.Calendar; @@ -241,9 +242,11 @@ public void showLocalNotification(final NotificationSetting notificationSetting) intent.putExtra(NOTIFICATION_REQUEST_CODE_KEY, requestCode); intent.putExtra(NOTIFICATION_DEEPLINK_KEY, notificationSetting.getDeeplink()); intent.putExtra(NOTIFICATION_CONTENT_KEY, notificationSetting.getContent()); - intent.putExtra( - NOTIFICATION_USER_INFO_KEY, - (HashMap) notificationSetting.getUserInfo()); + final HashMap userInfo = + !MapUtils.isNullOrEmpty(notificationSetting.getUserInfo()) + ? new HashMap<>(notificationSetting.getUserInfo()) + : null; + intent.putExtra(NOTIFICATION_USER_INFO_KEY, userInfo); intent.putExtra(NOTIFICATION_SOUND_KEY, notificationSetting.getSound()); intent.putExtra(NOTIFICATION_TITLE, notificationSetting.getTitle()); diff --git a/code/core/src/test/java/com/adobe/marketing/mobile/services/ui/AndroidUIServiceTests.java b/code/core/src/test/java/com/adobe/marketing/mobile/services/ui/AndroidUIServiceTests.java index b2b6ed8f1..634fadb27 100644 --- a/code/core/src/test/java/com/adobe/marketing/mobile/services/ui/AndroidUIServiceTests.java +++ b/code/core/src/test/java/com/adobe/marketing/mobile/services/ui/AndroidUIServiceTests.java @@ -39,6 +39,9 @@ import com.adobe.marketing.mobile.services.ServiceProviderModifier; import com.adobe.marketing.mobile.services.ui.internal.MessagesMonitor; import java.util.Calendar; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -353,6 +356,46 @@ public void localNotificationWithTitleIsNotShown_When_ContextIsNull() { verify(mockAlarmManager, times(0)).set(eq(AlarmManager.RTC_WAKEUP), anyLong(), isNull()); } + @Test + public void localNotificationIsShown_When_UnmodifiableUserInfoMapIsProvided() { + // setup + Map userInfo = + new HashMap() { + { + put("key1", "value1"); + put("key2", "value2"); + } + }; + when(mockMessagesMonitor.isDisplayed()).thenReturn(false); + androidUIService.messagesMonitor = mockMessagesMonitor; + + when(mockContext.getSystemService(Context.ALARM_SERVICE)).thenReturn(mockAlarmManager); + when(mockContext.getApplicationContext()).thenReturn(mockContext); + + when(mockAppContextService.getApplicationContext()).thenReturn(mockContext); + // test + androidUIService.showLocalNotification( + NotificationSetting.build( + "id", + "content", + 123456, + 123, + "myscheme://link", + Collections.unmodifiableMap(userInfo), + "sound.wav", + null)); + // verify that the Alarm was set + ArgumentCaptor triggerTimeCaptor = ArgumentCaptor.forClass(long.class); + // The Pending Intent is null matched only because in this test we are not able to mock a + // static call + // to PendingIntent.getBroadcast() without using additional libraries - which is a no-no + verify(mockAlarmManager) + .set(eq(AlarmManager.RTC_WAKEUP), triggerTimeCaptor.capture(), isNull()); + // verify that the alarm time is within the delta of 50ms :) + long expectedTriggerTime = getTriggerTimeForFireDate(123456); + assertTrue(triggerTimeCaptor.getValue() - expectedTriggerTime < 50); + } + @Test public void showUrlStartsActivity_When_ValidUrl() { // Setup From cc4dcb27862c6520fecda0a61570a3dff30286d3 Mon Sep 17 00:00:00 2001 From: Ryan Morales Date: Mon, 7 Aug 2023 13:58:17 -0700 Subject: [PATCH 2/3] only add the user info to the intent if map is non empty --- .../adobe/marketing/mobile/services/ui/AndroidUIService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/AndroidUIService.java b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/AndroidUIService.java index 8ccdb2ec0..d1117e899 100644 --- a/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/AndroidUIService.java +++ b/code/core/src/phone/java/com/adobe/marketing/mobile/services/ui/AndroidUIService.java @@ -246,7 +246,9 @@ public void showLocalNotification(final NotificationSetting notificationSetting) !MapUtils.isNullOrEmpty(notificationSetting.getUserInfo()) ? new HashMap<>(notificationSetting.getUserInfo()) : null; - intent.putExtra(NOTIFICATION_USER_INFO_KEY, userInfo); + if (!MapUtils.isNullOrEmpty(userInfo)) { + intent.putExtra(NOTIFICATION_USER_INFO_KEY, userInfo); + } intent.putExtra(NOTIFICATION_SOUND_KEY, notificationSetting.getSound()); intent.putExtra(NOTIFICATION_TITLE, notificationSetting.getTitle()); From 59f7e719556bb449f155a26c3fa5a919f2495e72 Mon Sep 17 00:00:00 2001 From: praveek Date: Mon, 7 Aug 2023 23:47:08 +0000 Subject: [PATCH 3/3] Update versions [Core-2.3.1] --- .../java/com/adobe/marketing/mobile/internal/CoreConstants.kt | 2 +- .../src/test/java/com/adobe/marketing/mobile/MobileCoreTests.kt | 2 +- .../internal/configuration/ConfigurationExtensionTests.kt | 2 +- code/gradle.properties | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/core/src/main/java/com/adobe/marketing/mobile/internal/CoreConstants.kt b/code/core/src/main/java/com/adobe/marketing/mobile/internal/CoreConstants.kt index 0ff66f4d0..827fe9007 100644 --- a/code/core/src/main/java/com/adobe/marketing/mobile/internal/CoreConstants.kt +++ b/code/core/src/main/java/com/adobe/marketing/mobile/internal/CoreConstants.kt @@ -13,7 +13,7 @@ package com.adobe.marketing.mobile.internal internal object CoreConstants { const val LOG_TAG = "MobileCore" - const val VERSION = "2.3.0" + const val VERSION = "2.3.1" object EventDataKeys { /** diff --git a/code/core/src/test/java/com/adobe/marketing/mobile/MobileCoreTests.kt b/code/core/src/test/java/com/adobe/marketing/mobile/MobileCoreTests.kt index 84d0da242..59d59bd46 100644 --- a/code/core/src/test/java/com/adobe/marketing/mobile/MobileCoreTests.kt +++ b/code/core/src/test/java/com/adobe/marketing/mobile/MobileCoreTests.kt @@ -35,7 +35,7 @@ import kotlin.test.assertTrue @RunWith(MockitoJUnitRunner.Silent::class) class MobileCoreTests { - private var EXTENSION_VERSION = "2.3.0" + private var EXTENSION_VERSION = "2.3.1" @Mock private lateinit var mockedEventHub: EventHub diff --git a/code/core/src/test/java/com/adobe/marketing/mobile/internal/configuration/ConfigurationExtensionTests.kt b/code/core/src/test/java/com/adobe/marketing/mobile/internal/configuration/ConfigurationExtensionTests.kt index 7eafbbf33..bc0bd1813 100644 --- a/code/core/src/test/java/com/adobe/marketing/mobile/internal/configuration/ConfigurationExtensionTests.kt +++ b/code/core/src/test/java/com/adobe/marketing/mobile/internal/configuration/ConfigurationExtensionTests.kt @@ -60,7 +60,7 @@ import kotlin.test.assertTrue @RunWith(MockitoJUnitRunner.Silent::class) class ConfigurationExtensionTests { - private var EXTENSION_VERSION = "2.3.0" + private var EXTENSION_VERSION = "2.3.1" @Mock private lateinit var mockServiceProvider: ServiceProvider diff --git a/code/gradle.properties b/code/gradle.properties index e8144efde..1a050c8aa 100644 --- a/code/gradle.properties +++ b/code/gradle.properties @@ -6,7 +6,7 @@ android.useAndroidX=true # #Maven artifacts #Core extension -coreExtensionVersion=2.3.0 +coreExtensionVersion=2.3.1 coreExtensionName=core coreExtensionAARName=core-phone-release.aar coreMavenRepoName=AdobeMobileCoreSdk