From 4e8b156c9846483086513987e38ef45a33f4fa99 Mon Sep 17 00:00:00 2001 From: megamegax Date: Thu, 14 Nov 2024 15:28:29 +0100 Subject: [PATCH] feat(client-id): rename hardwareId to clientId SDK-89 Co-authored-by: LasOri <24588073+LasOri@users.noreply.github.com> Co-authored-by: LordAndras <49073629+LordAndras@users.noreply.github.com> --- .../java/com/emarsys/core/DeviceInfoTest.kt | 30 ++-- .../clientid/ClientIdContentResolverTest.kt | 124 +++++++++++++++++ .../HardwareIdContentResolverTest.kt | 124 ----------------- .../crypto/ClientIdentificationCryptoTest.kt | 61 ++++++++ .../HardwareIdentificationCryptoTest.kt | 60 -------- .../AbstractSqliteRepositoryTest.kt | 4 +- .../core/di/FakeCoreDependencyContainer.kt | 6 +- .../provider/clientid/ClientIdProviderTest.kt | 131 ++++++++++++++++++ .../hardwareid/HardwareIdProviderTest.kt | 131 ------------------ .../com/emarsys/core/util/ImageUtilsTest.kt | 10 +- .../emarsys/core/util/TimestampUtilsTest.kt | 12 +- .../core/util/log/LogShardListMergerTest.kt | 4 +- .../clientid/ClientIdContentResolver.kt | 45 ++++++ .../hardwareid/HardwareIdContentResolver.kt | 45 ------ .../core/crypto/ClientIdentificationCrypto.kt | 31 +++++ .../crypto/HardwareIdentificationCrypto.kt | 28 ---- .../emarsys/core/database/DatabaseContract.kt | 15 +- ...ntification.kt => ClientIdentification.kt} | 6 +- .../emarsys/core/device/ClientRepository.kt | 43 ++++++ .../com/emarsys/core/device/DeviceInfo.kt | 8 +- ...terByHardwareId.kt => FilterByClientId.kt} | 2 +- .../emarsys/core/device/HardwareRepository.kt | 39 ------ .../java/com/emarsys/core/di/CoreComponent.kt | 6 +- .../provider/clientid/ClientIdProvider.kt | 70 ++++++++++ .../provider/hardwareid/HardwareIdProvider.kt | 63 --------- .../core/util/log/LogShardListMerger.java | 2 +- .../java/com/emarsys/testUtil/E2ETestUtils.kt | 2 +- .../fake/FakeFirebaseDependencyContainer.kt | 6 +- .../EmarsysFirebaseMessagingServiceTest.kt | 2 +- .../fake/FakeHuaweiDependencyContainer.kt | 6 +- .../EmarsysHuaweiMessagingServiceTest.kt | 2 +- .../emarsys/DefaultInboxIntegrationTest.kt | 6 +- .../java/com/emarsys/EmarsysTest.kt | 10 +- .../emarsys/MobileEngageIntegrationTest.kt | 6 +- ...ngageRefreshContactTokenIntegrationTest.kt | 6 +- .../com/emarsys/PredictIntegrationTest.kt | 6 +- .../java/com/emarsys/config/ConfigTest.kt | 10 +- .../com/emarsys/di/FakeDependencyContainer.kt | 6 +- ...lientIdentificationContentProviderTest.kt} | 8 +- .../main/java/com/emarsys/config/Config.kt | 11 +- .../main/java/com/emarsys/config/ConfigApi.kt | 3 + .../com/emarsys/di/DefaultEmarsysComponent.kt | 36 ++--- ...edHardwareIdentificationContentProvider.kt | 13 +- .../emarsys/EmarsysRequestModelFactoryTest.kt | 4 +- .../config/DefaultConfigInternalTest.kt | 12 +- .../config/RemoteConfigResponseMapperTest.kt | 16 +-- .../fake/FakeEmarsysDependencyContainer.kt | 6 +- .../java/com/emarsys/config/ConfigInternal.kt | 2 +- .../emarsys/config/DefaultConfigInternal.kt | 4 +- .../config/RemoteConfigResponseMapper.kt | 10 +- .../DefaultMobileEngageInternalTest.kt | 4 +- .../FakeMobileEngageDependencyContainer.kt | 6 +- .../RequestRepositoryProxyTest.kt | 2 +- .../MobileEngageRequestModelFactoryTest.kt | 4 +- .../mapper/ContactTokenHeaderMapperTest.kt | 4 +- .../mapper/DefaultRequestHeaderMapperTest.kt | 4 +- .../DeviceEventStateRequestMapperTest.kt | 2 +- .../mapper/MobileEngageHeaderMapperTest.kt | 10 +- .../mapper/OpenIdTokenRequestMapperTest.kt | 4 +- .../service/MessagingServiceUtilsTest.kt | 10 +- .../util/RequestPayloadUtilsTest.kt | 4 +- .../mapper/MobileEngageHeaderMapper.kt | 2 +- .../request/PredictRequestModelBuilderTest.kt | 4 +- .../com/emarsys/sample/SampleApplication.kt | 2 +- .../sample/dashboard/DashboardViewModel.kt | 2 +- .../kotlin/com/emarsys/sample/pref/Prefs.kt | 4 +- 66 files changed, 696 insertions(+), 665 deletions(-) create mode 100644 core/src/androidTest/java/com/emarsys/core/contentresolver/clientid/ClientIdContentResolverTest.kt delete mode 100644 core/src/androidTest/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolverTest.kt create mode 100644 core/src/androidTest/java/com/emarsys/core/crypto/ClientIdentificationCryptoTest.kt delete mode 100644 core/src/androidTest/java/com/emarsys/core/crypto/HardwareIdentificationCryptoTest.kt create mode 100644 core/src/androidTest/java/com/emarsys/core/provider/clientid/ClientIdProviderTest.kt delete mode 100644 core/src/androidTest/java/com/emarsys/core/provider/hardwareid/HardwareIdProviderTest.kt create mode 100644 core/src/main/java/com/emarsys/core/contentresolver/clientid/ClientIdContentResolver.kt delete mode 100644 core/src/main/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolver.kt create mode 100644 core/src/main/java/com/emarsys/core/crypto/ClientIdentificationCrypto.kt delete mode 100644 core/src/main/java/com/emarsys/core/crypto/HardwareIdentificationCrypto.kt rename core/src/main/java/com/emarsys/core/device/{HardwareIdentification.kt => ClientIdentification.kt} (55%) create mode 100644 core/src/main/java/com/emarsys/core/device/ClientRepository.kt rename core/src/main/java/com/emarsys/core/device/{FilterByHardwareId.kt => FilterByClientId.kt} (90%) delete mode 100644 core/src/main/java/com/emarsys/core/device/HardwareRepository.kt create mode 100644 core/src/main/java/com/emarsys/core/provider/clientid/ClientIdProvider.kt delete mode 100644 core/src/main/java/com/emarsys/core/provider/hardwareid/HardwareIdProvider.kt rename emarsys-sdk/src/androidTest/java/com/emarsys/provider/{SharedHardwareIdentificationContentProviderTest.kt => SharedClientIdentificationContentProviderTest.kt} (90%) diff --git a/core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt b/core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt index 9acb7efeb..14b92100d 100644 --- a/core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/DeviceInfoTest.kt @@ -10,7 +10,7 @@ import com.emarsys.core.api.notification.ChannelSettings import com.emarsys.core.api.notification.NotificationSettings import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.core.util.AndroidVersionUtils import com.emarsys.testUtil.AnnotationSpec @@ -32,7 +32,7 @@ import java.util.* class DeviceInfoTest : AnnotationSpec() { companion object { - private const val HARDWARE_ID = "hwid" + private const val CLIENT_ID = "hwid" private const val SDK_VERSION = "sdkVersion" private const val LANGUAGE = "en-US" private const val APP_VERSION = "2.0" @@ -41,7 +41,7 @@ class DeviceInfoTest : AnnotationSpec() { private lateinit var deviceInfo: DeviceInfo private lateinit var tz: TimeZone private lateinit var context: Context - private lateinit var mockHardwareIdProvider: HardwareIdProvider + private lateinit var mockClientIdProvider: ClientIdProvider private lateinit var mockLanguageProvider: LanguageProvider private lateinit var mockVersionProvider: VersionProvider private lateinit var mockNotificationManagerHelper: NotificationSettings @@ -52,8 +52,8 @@ class DeviceInfoTest : AnnotationSpec() { tz = TimeZone.getTimeZone("Asia/Tokyo") TimeZone.setDefault(tz) context = getTargetContext().applicationContext - mockHardwareIdProvider = mock { - on { provideHardwareId() } doReturn HARDWARE_ID + mockClientIdProvider = mock { + on { provideClientId() } doReturn CLIENT_ID } mockLanguageProvider = mock { on { provideLanguage(any()) } doReturn LANGUAGE @@ -64,7 +64,7 @@ class DeviceInfoTest : AnnotationSpec() { mockNotificationManagerHelper = mock() deviceInfo = DeviceInfo( - context, mockHardwareIdProvider, mockVersionProvider, + context, mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationManagerHelper, isAutomaticPushSendingEnabled = true, isGooglePlayAvailable = true ) @@ -78,7 +78,7 @@ class DeviceInfoTest : AnnotationSpec() { @Test fun testConstructor_initializesFields() { with(deviceInfo) { - hardwareId shouldNotBe null + clientId shouldNotBe null platform shouldNotBe null language shouldNotBe null timezone shouldNotBe null @@ -106,7 +106,7 @@ class DeviceInfoTest : AnnotationSpec() { whenever(packageManager.getPackageInfo(packageName, 0)).thenReturn(packageInfo) whenever(mockContext.applicationInfo).thenReturn(Mockito.mock(ApplicationInfo::class.java)) val info = DeviceInfo( - mockContext, mockHardwareIdProvider, mockVersionProvider, + mockContext, mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationManagerHelper, isAutomaticPushSendingEnabled = true, isGooglePlayAvailable = true ) @@ -140,7 +140,7 @@ class DeviceInfoTest : AnnotationSpec() { fun testIsDebugMode_withDebugApplication() { val mockDebugContext = applicationDebug val debugDeviceInfo = DeviceInfo( - mockDebugContext, mockHardwareIdProvider, + mockDebugContext, mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationManagerHelper, isAutomaticPushSendingEnabled = true, isGooglePlayAvailable = true ) @@ -152,7 +152,7 @@ class DeviceInfoTest : AnnotationSpec() { val mockReleaseContext = applicationRelease val releaseDeviceInfo = DeviceInfo( mockReleaseContext, - mockHardwareIdProvider, + mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationManagerHelper, @@ -163,9 +163,9 @@ class DeviceInfoTest : AnnotationSpec() { } @Test - fun testHardwareId_isAcquiredFromHardwareIdProvider() { - Mockito.verify(mockHardwareIdProvider).provideHardwareId() - HARDWARE_ID shouldBe deviceInfo.hardwareId + fun testClientId_isAcquiredFromClientIdProvider() { + Mockito.verify(mockClientIdProvider).provideClientId() + CLIENT_ID shouldBe deviceInfo.clientId } @Test @@ -189,7 +189,7 @@ class DeviceInfoTest : AnnotationSpec() { whenever(mockContext.applicationInfo).thenReturn(Mockito.mock(ApplicationInfo::class.java)) deviceInfo = DeviceInfo( - mockContext, mockHardwareIdProvider, mockVersionProvider, + mockContext, mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationManagerHelper, isAutomaticPushSendingEnabled = true, isGooglePlayAvailable = true ) @@ -250,7 +250,7 @@ class DeviceInfoTest : AnnotationSpec() { whenever(mockContext.applicationInfo).thenReturn(Mockito.mock(ApplicationInfo::class.java)) deviceInfo = DeviceInfo( - mockContext, mockHardwareIdProvider, mockVersionProvider, + mockContext, mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationManagerHelper, isAutomaticPushSendingEnabled = true, isGooglePlayAvailable = false ) diff --git a/core/src/androidTest/java/com/emarsys/core/contentresolver/clientid/ClientIdContentResolverTest.kt b/core/src/androidTest/java/com/emarsys/core/contentresolver/clientid/ClientIdContentResolverTest.kt new file mode 100644 index 000000000..49239ce6c --- /dev/null +++ b/core/src/androidTest/java/com/emarsys/core/contentresolver/clientid/ClientIdContentResolverTest.kt @@ -0,0 +1,124 @@ +import android.database.Cursor +import android.net.Uri +import com.emarsys.core.contentresolver.EmarsysContentResolver +import com.emarsys.core.contentresolver.clientid.ClientIdContentResolver +import com.emarsys.core.crypto.ClientIdentificationCrypto +import com.emarsys.core.database.DatabaseContract +import com.emarsys.core.device.ClientIdentification +import com.emarsys.testUtil.AnnotationSpec +import io.kotest.matchers.shouldBe +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify + +class ClientIdContentResolverTest : AnnotationSpec() { + + companion object { + private val SHARED_PACKAGE_NAMES = + listOf("emarsys.test", "com.emarsys.test", "com.android.test") + private const val ENCRYPTED_ClIENT_ID = "encrypted_shared_hardware_id" + private const val SALT = "testSalt" + private const val IV = "testIv" + + } + + private var mockEmarsysContentResolver: EmarsysContentResolver = mockk() + private lateinit var contentResolver: ClientIdContentResolver + private lateinit var mockClientIdentificationCrypto: ClientIdentificationCrypto + private lateinit var mockCursor: Cursor + + @Before + fun setUp() { + mockCursor = mockk(relaxed = true) { + every { moveToFirst() } returns true + every { getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_CLIENT_ID) } returns 0 + every { getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_SALT) } returns 1 + every { getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_IV) } returns 2 + every { getString(0) } returns ENCRYPTED_ClIENT_ID + every { getString(1) } returns SALT + every { getString(2) } returns IV + } + every { + mockEmarsysContentResolver.query( + any(), + any(), + any(), + any(), + any() + ) + } returns mockCursor + + mockClientIdentificationCrypto = mockk() + every { + mockClientIdentificationCrypto.decrypt( + any(), + any(), + any() + ) + } returns "CLIENT_ID" + every { mockClientIdentificationCrypto.encrypt(any()) } returns ClientIdentification( + ENCRYPTED_ClIENT_ID, + SALT, + IV + ) + contentResolver = ClientIdContentResolver( + mockEmarsysContentResolver, + mockClientIdentificationCrypto, + SHARED_PACKAGE_NAMES + ) + } + + @Test + fun testProvideClientId_shouldGetClientId_fromContentResolver() { + contentResolver.resolveClientId() + + verify { mockClientIdentificationCrypto.decrypt(ENCRYPTED_ClIENT_ID, SALT, IV) } + } + + @Test + fun testProvideClientId_shouldNotGetClientId_fromContentResolver() { + val mockCursor: Cursor = mockk { + every { moveToFirst() } returns false + every { getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_CLIENT_ID) } returns 0 + every { getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_SALT) } returns 1 + every { getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_IV) } returns 2 + every { getString(0) } returns ENCRYPTED_ClIENT_ID + every { getString(1) } returns SALT + every { getString(2) } returns IV + } + every { + mockEmarsysContentResolver.query( + any(), + any(), + any(), + any(), + any() + ) + } returns mockCursor + val contentResolver = ClientIdContentResolver( + mockEmarsysContentResolver, + mockClientIdentificationCrypto, + SHARED_PACKAGE_NAMES + ) + contentResolver.resolveClientId() + + verify(exactly = 0) { mockClientIdentificationCrypto.decrypt(any(), any(), any()) } + verify(exactly = 0) { mockClientIdentificationCrypto.encrypt(any()) } + } + + @Test + fun testProvideClientId_shouldReturnFalse_whenSharedPackageNamesIsMissing() { + val contentResolver = + ClientIdContentResolver( + mockEmarsysContentResolver, + mockClientIdentificationCrypto, + null + ) + + val result = contentResolver.resolveClientId() + + verify(exactly = 0) { mockClientIdentificationCrypto.decrypt(any(), any(), any()) } + verify(exactly = 0) { mockClientIdentificationCrypto.encrypt(any()) } + result shouldBe null + } +} diff --git a/core/src/androidTest/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolverTest.kt b/core/src/androidTest/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolverTest.kt deleted file mode 100644 index 070f4e3e0..000000000 --- a/core/src/androidTest/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolverTest.kt +++ /dev/null @@ -1,124 +0,0 @@ -import android.database.Cursor -import android.net.Uri -import com.emarsys.core.contentresolver.EmarsysContentResolver -import com.emarsys.core.contentresolver.hardwareid.HardwareIdContentResolver -import com.emarsys.core.crypto.HardwareIdentificationCrypto -import com.emarsys.core.database.DatabaseContract -import com.emarsys.core.device.HardwareIdentification -import com.emarsys.testUtil.AnnotationSpec -import io.kotest.matchers.shouldBe -import io.mockk.every -import io.mockk.mockk -import io.mockk.verify - -class HardwareIdContentResolverTest : AnnotationSpec() { - - companion object { - private val SHARED_PACKAGE_NAMES = - listOf("emarsys.test", "com.emarsys.test", "com.android.test") - private const val ENCRYPTED_HARDWARE_ID = "encrypted_shared_hardware_id" - private const val SALT = "testSalt" - private const val IV = "testIv" - - } - - private var mockEmarsysContentResolver: EmarsysContentResolver = mockk() - private lateinit var contentResolver: HardwareIdContentResolver - private lateinit var mockHardwareIdentificationCrypto: HardwareIdentificationCrypto - private lateinit var mockCursor: Cursor - - @Before - fun setUp() { - mockCursor = mockk(relaxed = true) { - every { moveToFirst() } returns true - every { getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_HARDWARE_ID) } returns 0 - every { getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_SALT) } returns 1 - every { getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_IV) } returns 2 - every { getString(0) } returns ENCRYPTED_HARDWARE_ID - every { getString(1) } returns SALT - every { getString(2) } returns IV - } - every { - mockEmarsysContentResolver.query( - any(), - any(), - any(), - any(), - any() - ) - } returns mockCursor - - mockHardwareIdentificationCrypto = mockk() - every { - mockHardwareIdentificationCrypto.decrypt( - any(), - any(), - any() - ) - } returns "HARDWARE_ID" - every { mockHardwareIdentificationCrypto.encrypt(any()) } returns HardwareIdentification( - ENCRYPTED_HARDWARE_ID, - SALT, - IV - ) - contentResolver = HardwareIdContentResolver( - mockEmarsysContentResolver, - mockHardwareIdentificationCrypto, - SHARED_PACKAGE_NAMES - ) - } - - @Test - fun testProvideHardwareId_shouldGetHardwareId_fromContentResolver() { - contentResolver.resolveHardwareId() - - verify { mockHardwareIdentificationCrypto.decrypt(ENCRYPTED_HARDWARE_ID, SALT, IV) } - } - - @Test - fun testProvideHardwareId_shouldNotGetHardwareId_fromContentResolver() { - val mockCursor: Cursor = mockk { - every { moveToFirst() } returns false - every { getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_HARDWARE_ID) } returns 0 - every { getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_SALT) } returns 1 - every { getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_IV) } returns 2 - every { getString(0) } returns ENCRYPTED_HARDWARE_ID - every { getString(1) } returns SALT - every { getString(2) } returns IV - } - every { - mockEmarsysContentResolver.query( - any(), - any(), - any(), - any(), - any() - ) - } returns mockCursor - val contentResolver = HardwareIdContentResolver( - mockEmarsysContentResolver, - mockHardwareIdentificationCrypto, - SHARED_PACKAGE_NAMES - ) - contentResolver.resolveHardwareId() - - verify(exactly = 0) { mockHardwareIdentificationCrypto.decrypt(any(), any(), any()) } - verify(exactly = 0) { mockHardwareIdentificationCrypto.encrypt(any()) } - } - - @Test - fun testProvideHardwareId_shouldReturnFalse_whenSharedPackageNamesIsMissing() { - val contentResolver = - HardwareIdContentResolver( - mockEmarsysContentResolver, - mockHardwareIdentificationCrypto, - null - ) - - val result = contentResolver.resolveHardwareId() - - verify(exactly = 0) { mockHardwareIdentificationCrypto.decrypt(any(), any(), any()) } - verify(exactly = 0) { mockHardwareIdentificationCrypto.encrypt(any()) } - result shouldBe null - } -} diff --git a/core/src/androidTest/java/com/emarsys/core/crypto/ClientIdentificationCryptoTest.kt b/core/src/androidTest/java/com/emarsys/core/crypto/ClientIdentificationCryptoTest.kt new file mode 100644 index 000000000..ce3c4c930 --- /dev/null +++ b/core/src/androidTest/java/com/emarsys/core/crypto/ClientIdentificationCryptoTest.kt @@ -0,0 +1,61 @@ +package com.emarsys.core.crypto + +import com.emarsys.core.device.ClientIdentification +import com.emarsys.testUtil.AnnotationSpec +import io.kotest.matchers.shouldBe +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever + +class ClientIdentificationCryptoTest : AnnotationSpec() { + + companion object { + private const val SECRET = "SECRET" + private const val CLIENT_ID = "testClientId" + private const val ENCRYPTED_CLIENT_ID = "testEncryptedClientId" + private const val SALT = "testSalt" + private const val IV = "testIv" + private val HARDWARE = ClientIdentification(CLIENT_ID, null, null, null) + private val ENCRYPTED_HARDWARE = + ClientIdentification(CLIENT_ID, ENCRYPTED_CLIENT_ID, SALT, IV) + } + + private lateinit var clientIdentificationCryptoWithSecret: ClientIdentificationCrypto + private lateinit var clientIdentificationCryptoWithoutSecret: ClientIdentificationCrypto + private lateinit var mockCrypto: Crypto + + @Before + fun setUp() { + mockCrypto = mock() + + clientIdentificationCryptoWithSecret = ClientIdentificationCrypto(SECRET, mockCrypto) + clientIdentificationCryptoWithoutSecret = ClientIdentificationCrypto(null, mockCrypto) + } + + @Test + fun testEncrypt_doNothing_whenSecretIsMissing() { + val result = clientIdentificationCryptoWithoutSecret.encrypt(HARDWARE) + + result shouldBe HARDWARE + } + + @Test + fun testEncrypt_shouldEncrypt_whenSecretIsGiven() { + whenever(mockCrypto.encrypt(CLIENT_ID, SECRET)).thenReturn( + mapOf( + "encryptedValue" to ENCRYPTED_CLIENT_ID, + "salt" to SALT, + "iv" to IV)) + val result = clientIdentificationCryptoWithSecret.encrypt(HARDWARE) + + result shouldBe ENCRYPTED_HARDWARE + } + + @Test + fun testDecrypt_shouldGiveBack_clientId_fromEncryptedHardware() { + whenever(mockCrypto.decrypt(ENCRYPTED_CLIENT_ID, SECRET, SALT, IV)).thenReturn(CLIENT_ID) + + val result = clientIdentificationCryptoWithSecret.decrypt(ENCRYPTED_CLIENT_ID, SALT, IV) + + result shouldBe CLIENT_ID + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/com/emarsys/core/crypto/HardwareIdentificationCryptoTest.kt b/core/src/androidTest/java/com/emarsys/core/crypto/HardwareIdentificationCryptoTest.kt deleted file mode 100644 index e6ae28896..000000000 --- a/core/src/androidTest/java/com/emarsys/core/crypto/HardwareIdentificationCryptoTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -package com.emarsys.core.crypto - -import com.emarsys.core.device.HardwareIdentification -import com.emarsys.testUtil.AnnotationSpec -import io.kotest.matchers.shouldBe -import org.mockito.kotlin.mock -import org.mockito.kotlin.whenever - -class HardwareIdentificationCryptoTest : AnnotationSpec() { - - companion object { - private const val SECRET = "SECRET" - private const val HARDWARE_ID = "testHardwareId" - private const val ENCRYPTED_HARDWARE_ID = "testEncryptedHardwareId" - private const val SALT = "testSalt" - private const val IV = "testIv" - private val HARDWARE = HardwareIdentification(HARDWARE_ID, null, null, null) - private val ENCRYPTED_HARDWARE = - HardwareIdentification(HARDWARE_ID, ENCRYPTED_HARDWARE_ID, SALT, IV) - } - - private lateinit var hardwareIdentificationCryptoWithSecret: HardwareIdentificationCrypto - private lateinit var hardwareIdentificationCryptoWithoutSecret: HardwareIdentificationCrypto - private lateinit var mockCrypto: Crypto - - @Before - fun setUp() { - mockCrypto = mock() - - hardwareIdentificationCryptoWithSecret = HardwareIdentificationCrypto(SECRET, mockCrypto) - hardwareIdentificationCryptoWithoutSecret = HardwareIdentificationCrypto(null, mockCrypto) - } - - @Test - fun testEncrypt_doNothing_whenSecretIsMissing() { - val result = hardwareIdentificationCryptoWithoutSecret.encrypt(HARDWARE) - - result shouldBe HARDWARE - } - - @Test - fun testEncrypt_shouldEncrypt_whenSecretIsGiven() { - whenever(mockCrypto.encrypt(HARDWARE_ID, SECRET)).thenReturn(mapOf( - "encryptedValue" to ENCRYPTED_HARDWARE_ID, - "salt" to SALT, - "iv" to IV)) - val result = hardwareIdentificationCryptoWithSecret.encrypt(HARDWARE) - - result shouldBe ENCRYPTED_HARDWARE - } - - @Test - fun testDecrypt_shouldGiveBack_hardwareId_fromEncryptedHardware(){ - whenever(mockCrypto.decrypt(ENCRYPTED_HARDWARE_ID, SECRET, SALT, IV)).thenReturn(HARDWARE_ID) - - val result = hardwareIdentificationCryptoWithSecret.decrypt(ENCRYPTED_HARDWARE_ID, SALT, IV) - - result shouldBe HARDWARE_ID - } -} \ No newline at end of file diff --git a/core/src/androidTest/java/com/emarsys/core/database/repository/AbstractSqliteRepositoryTest.kt b/core/src/androidTest/java/com/emarsys/core/database/repository/AbstractSqliteRepositoryTest.kt index 2da00ac76..ec89eced5 100644 --- a/core/src/androidTest/java/com/emarsys/core/database/repository/AbstractSqliteRepositoryTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/database/repository/AbstractSqliteRepositoryTest.kt @@ -14,7 +14,7 @@ import com.emarsys.core.database.DatabaseContract.REQUEST_COLUMN_NAME_TTL import com.emarsys.core.database.DatabaseContract.REQUEST_COLUMN_NAME_URL import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.database.helper.DbHelper -import com.emarsys.core.device.FilterByHardwareId +import com.emarsys.core.device.FilterByClientId import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider @@ -119,7 +119,7 @@ class AbstractSqliteRepositoryTest : AnnotationSpec() { whenever(dbMock.update(any(), any(), any(), any())).thenReturn(1) val input = anyNotNull() - val result = repository.update(input, eq(FilterByHardwareId("id"))) + val result = repository.update(input, eq(FilterByClientId("id"))) verify(repository).contentValuesFromItem(input) verify(dbMock).beginTransaction() diff --git a/core/src/androidTest/java/com/emarsys/core/di/FakeCoreDependencyContainer.kt b/core/src/androidTest/java/com/emarsys/core/di/FakeCoreDependencyContainer.kt index 5c784ed42..428a01e53 100644 --- a/core/src/androidTest/java/com/emarsys/core/di/FakeCoreDependencyContainer.kt +++ b/core/src/androidTest/java/com/emarsys/core/di/FakeCoreDependencyContainer.kt @@ -14,7 +14,7 @@ import com.emarsys.core.database.repository.Repository import com.emarsys.core.database.repository.SqlSpecification import com.emarsys.core.device.DeviceInfo import com.emarsys.core.handler.ConcurrentHandlerHolder -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.RequestManager @@ -43,9 +43,9 @@ class FakeCoreDependencyContainer( override val keyValueStore: KeyValueStore = mock(), override val sharedPreferences: SharedPreferences = mock(), override val sharedPreferencesV3: SharedPreferences = mock(), - override val hardwareIdProvider: HardwareIdProvider = mock(), + override val clientIdProvider: ClientIdProvider = mock(), override val coreDbHelper: CoreDbHelper = mock(), - override val hardwareIdStorage: Storage = mock(), + override val clientIdStorage: Storage = mock(), override val crypto: Crypto = mock(), override val requestManager: RequestManager = mock(), override val worker: Worker = mock(), diff --git a/core/src/androidTest/java/com/emarsys/core/provider/clientid/ClientIdProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/provider/clientid/ClientIdProviderTest.kt new file mode 100644 index 000000000..8ca26683e --- /dev/null +++ b/core/src/androidTest/java/com/emarsys/core/provider/clientid/ClientIdProviderTest.kt @@ -0,0 +1,131 @@ +package com.emarsys.core.provider.clientid + +import com.emarsys.core.contentresolver.clientid.ClientIdContentResolver +import com.emarsys.core.crypto.ClientIdentificationCrypto +import com.emarsys.core.database.repository.Repository +import com.emarsys.core.database.repository.SqlSpecification +import com.emarsys.core.device.ClientIdentification +import com.emarsys.core.provider.uuid.UUIDProvider +import com.emarsys.core.storage.Storage +import com.emarsys.testUtil.AnnotationSpec +import com.emarsys.testUtil.mockito.whenever +import io.kotest.matchers.shouldBe +import kotlinx.coroutines.runBlocking +import org.mockito.kotlin.any +import org.mockito.kotlin.doReturn +import org.mockito.kotlin.mock +import org.mockito.kotlin.verify +import org.mockito.kotlin.verifyNoInteractions + + +class ClientIdProviderTest : AnnotationSpec() { + + companion object { + private const val CLIENT_ID = "hw_value" + internal const val SHARED_CLIENT_ID = "shared_hw_value" + internal const val ENCRYPTED_CLIENT_ID = "encrypted_shared_hardware_id" + internal const val SALT = "testSalt" + internal const val IV = "testIv" + private val CLIENT = ClientIdentification(CLIENT_ID) + private val SHARED_CLIENT = ClientIdentification(SHARED_CLIENT_ID) + private val ENCRYPTED_CLIENT = + ClientIdentification(CLIENT_ID, "encrypted_hardware_id", "testSalt", "testIv") + private val ENCRYPTED_SHARED_HARDWARE = ClientIdentification( + SHARED_CLIENT_ID, + "encrypted_shared_hardware_id", + "testSalt", + "testIv" + ) + } + + private lateinit var mockClientIdentificationCrypto: ClientIdentificationCrypto + private lateinit var mockClientIdContentResolver: ClientIdContentResolver + private lateinit var mockStorage: Storage + private lateinit var clientIdProvider: ClientIdProvider + private lateinit var mockUUIDProvider: UUIDProvider + private lateinit var mockRepository: Repository + + + @Before + fun setUp() { + mockStorage = mock() + mockUUIDProvider = mock { + on { provideId() } doReturn CLIENT_ID + } + + mockRepository = mock() + mockClientIdentificationCrypto = mock { + on { encrypt(CLIENT) } doReturn ENCRYPTED_CLIENT + on { encrypt(SHARED_CLIENT) } doReturn ENCRYPTED_SHARED_HARDWARE + on { decrypt(ENCRYPTED_CLIENT_ID, SALT, IV) } doReturn SHARED_CLIENT_ID + } + mockClientIdContentResolver = mock() + + clientIdProvider = ClientIdProvider( + mockUUIDProvider, + mockRepository, + mockStorage, + mockClientIdContentResolver, + mockClientIdentificationCrypto + ) + } + + @Test + fun testProvideClientId_shouldGetClientId_fromRepository_ifExists() { + whenever(mockRepository.query(any())).thenReturn(listOf(CLIENT)) + val result = clientIdProvider.provideClientId() + + verify(mockRepository).query(any()) + result shouldBe CLIENT_ID + } + + @Test + fun testProvideClientId_shouldGetClientId_fromStorage_andStoreInRepository_ifNotInRepository_andSecretNotSet() { + whenever(mockStorage.get()).thenReturn(CLIENT_ID) + whenever(mockClientIdentificationCrypto.encrypt(CLIENT)).thenReturn(CLIENT) + + runBlocking { + val result = clientIdProvider.provideClientId() + verify(mockRepository).query(any()) + verify(mockClientIdentificationCrypto).encrypt(CLIENT) + verify(mockStorage).get() + verify(mockRepository).add(CLIENT) + result shouldBe CLIENT_ID + } + } + + @Test + fun testProvideClientId_shouldGetClientId_fromContentResolver_andStoreInRepository_ifNotInRepositoryNorStorage() { + whenever(mockClientIdContentResolver.resolveClientId()).thenReturn(SHARED_CLIENT_ID) + + runBlocking { + val result = clientIdProvider.provideClientId() + verify(mockRepository).add( + ClientIdentification( + SHARED_CLIENT_ID, + ENCRYPTED_CLIENT_ID, + SALT, + IV + ) + ) + verify(mockClientIdContentResolver).resolveClientId() + verifyNoInteractions(mockUUIDProvider) + + result shouldBe SHARED_CLIENT_ID + } + } + + @Test + fun testProvideClientId_shouldGenerateClientId_andStoreInRepository_ifNotInRepositoryNorStorageNorContentResolver() { + whenever(mockClientIdContentResolver.resolveClientId()).thenReturn(null) + whenever(mockClientIdentificationCrypto.encrypt(CLIENT)).thenReturn(CLIENT) + whenever(mockUUIDProvider.provideId()).thenReturn(CLIENT_ID) + runBlocking { + val result = clientIdProvider.provideClientId() + verify(mockRepository).add(CLIENT) + verify(mockUUIDProvider).provideId() + + result shouldBe CLIENT_ID + } + } +} \ No newline at end of file diff --git a/core/src/androidTest/java/com/emarsys/core/provider/hardwareid/HardwareIdProviderTest.kt b/core/src/androidTest/java/com/emarsys/core/provider/hardwareid/HardwareIdProviderTest.kt deleted file mode 100644 index e1c397dcf..000000000 --- a/core/src/androidTest/java/com/emarsys/core/provider/hardwareid/HardwareIdProviderTest.kt +++ /dev/null @@ -1,131 +0,0 @@ -package com.emarsys.core.provider.hardwareid - -import com.emarsys.core.contentresolver.hardwareid.HardwareIdContentResolver -import com.emarsys.core.crypto.HardwareIdentificationCrypto -import com.emarsys.core.database.repository.Repository -import com.emarsys.core.database.repository.SqlSpecification -import com.emarsys.core.device.HardwareIdentification -import com.emarsys.core.provider.uuid.UUIDProvider -import com.emarsys.core.storage.Storage -import com.emarsys.testUtil.AnnotationSpec -import com.emarsys.testUtil.mockito.whenever -import io.kotest.matchers.shouldBe -import kotlinx.coroutines.runBlocking -import org.mockito.kotlin.any -import org.mockito.kotlin.doReturn -import org.mockito.kotlin.mock -import org.mockito.kotlin.verify -import org.mockito.kotlin.verifyNoInteractions - - -class HardwareIdProviderTest : AnnotationSpec() { - - companion object { - private const val HARDWARE_ID = "hw_value" - internal const val SHARED_HARDWARE_ID = "shared_hw_value" - internal const val ENCRYPTED_HARDWARE_ID = "encrypted_shared_hardware_id" - internal const val SALT = "testSalt" - internal const val IV = "testIv" - private val HARDWARE = HardwareIdentification(HARDWARE_ID) - private val SHARED_HARDWARE = HardwareIdentification(SHARED_HARDWARE_ID) - private val ENCRYPTED_HARDWARE = - HardwareIdentification(HARDWARE_ID, "encrypted_hardware_id", "testSalt", "testIv") - private val ENCRYPTED_SHARED_HARDWARE = HardwareIdentification( - SHARED_HARDWARE_ID, - "encrypted_shared_hardware_id", - "testSalt", - "testIv" - ) - } - - private lateinit var mockHardwareIdentificationCrypto: HardwareIdentificationCrypto - private lateinit var mockHardwareIdContentResolver: HardwareIdContentResolver - private lateinit var mockStorage: Storage - private lateinit var hardwareIdProvider: HardwareIdProvider - private lateinit var mockUUIDProvider: UUIDProvider - private lateinit var mockRepository: Repository - - - @Before - fun setUp() { - mockStorage = mock() - mockUUIDProvider = mock { - on { provideId() } doReturn HARDWARE_ID - } - - mockRepository = mock() - mockHardwareIdentificationCrypto = mock { - on { encrypt(HARDWARE) } doReturn ENCRYPTED_HARDWARE - on { encrypt(SHARED_HARDWARE) } doReturn ENCRYPTED_SHARED_HARDWARE - on { decrypt(ENCRYPTED_HARDWARE_ID, SALT, IV) } doReturn SHARED_HARDWARE_ID - } - mockHardwareIdContentResolver = mock() - - hardwareIdProvider = HardwareIdProvider( - mockUUIDProvider, - mockRepository, - mockStorage, - mockHardwareIdContentResolver, - mockHardwareIdentificationCrypto - ) - } - - @Test - fun testProvideHardwareId_shouldGetHardwareId_fromRepository_ifExists() { - whenever(mockRepository.query(any())).thenReturn(listOf(HARDWARE)) - val result = hardwareIdProvider.provideHardwareId() - - verify(mockRepository).query(any()) - result shouldBe HARDWARE_ID - } - - @Test - fun testProvideHardwareId_shouldGetHardwareId_fromStorage_andStoreInRepository_ifNotInRepository_andSecretNotSet() { - whenever(mockStorage.get()).thenReturn(HARDWARE_ID) - whenever(mockHardwareIdentificationCrypto.encrypt(HARDWARE)).thenReturn(HARDWARE) - - runBlocking { - val result = hardwareIdProvider.provideHardwareId() - verify(mockRepository).query(any()) - verify(mockHardwareIdentificationCrypto).encrypt(HARDWARE) - verify(mockStorage).get() - verify(mockRepository).add(HARDWARE) - result shouldBe HARDWARE_ID - } - } - - @Test - fun testProvideHardwareId_shouldGetHardwareId_fromContentResolver_andStoreInRepository_ifNotInRepositoryNorStorage() { - whenever(mockHardwareIdContentResolver.resolveHardwareId()).thenReturn(SHARED_HARDWARE_ID) - - runBlocking { - val result = hardwareIdProvider.provideHardwareId() - verify(mockRepository).add( - HardwareIdentification( - SHARED_HARDWARE_ID, - ENCRYPTED_HARDWARE_ID, - SALT, - IV - ) - ) - verify(mockHardwareIdContentResolver).resolveHardwareId() - verifyNoInteractions(mockUUIDProvider) - - result shouldBe SHARED_HARDWARE_ID - } - } - - @Test - fun testProvideHardwareId_shouldGenerateHardwareId_andStoreInRepository_ifNotInRepositoryNorStorageNorContentResolver() { - whenever(mockHardwareIdContentResolver.resolveHardwareId()).thenReturn(null) - whenever(mockHardwareIdentificationCrypto.encrypt(HARDWARE)).thenReturn(HARDWARE) - whenever(mockUUIDProvider.provideId()).thenReturn(HARDWARE_ID) - runBlocking { - val result = hardwareIdProvider.provideHardwareId() - verify(mockRepository).add(HARDWARE) - verify(mockUUIDProvider).provideId() - - result shouldBe HARDWARE_ID - } - } -} \ No newline at end of file diff --git a/core/src/androidTest/java/com/emarsys/core/util/ImageUtilsTest.kt b/core/src/androidTest/java/com/emarsys/core/util/ImageUtilsTest.kt index e671d1e90..62f57b69c 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/ImageUtilsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/ImageUtilsTest.kt @@ -4,7 +4,7 @@ import android.graphics.BitmapFactory import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider import com.emarsys.core.notification.NotificationManagerHelper -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext @@ -34,7 +34,7 @@ class ImageUtilsTest : AnnotationSpec() { private lateinit var mockFileDownloader: FileDownloader private lateinit var deviceInfo: DeviceInfo - private lateinit var mockHardwareIdProvider: HardwareIdProvider + private lateinit var mockClientIdProvider: ClientIdProvider private lateinit var mockLanguageProvider: LanguageProvider private lateinit var mockVersionProvider: VersionProvider @@ -59,8 +59,8 @@ class ImageUtilsTest : AnnotationSpec() { } } - mockHardwareIdProvider = mock { - on { provideHardwareId() } doReturn "hardwareId" + mockClientIdProvider = mock { + on { provideClientId() } doReturn "clientId" } mockLanguageProvider = mock { on { provideLanguage(any()) } doReturn "language" @@ -71,7 +71,7 @@ class ImageUtilsTest : AnnotationSpec() { deviceInfo = DeviceInfo( getTargetContext(), - mockHardwareIdProvider, + mockClientIdProvider, mockVersionProvider, mockLanguageProvider, Mockito.mock(NotificationManagerHelper::class.java), diff --git a/core/src/androidTest/java/com/emarsys/core/util/TimestampUtilsTest.kt b/core/src/androidTest/java/com/emarsys/core/util/TimestampUtilsTest.kt index f6bf4baf1..f8c935a79 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/TimestampUtilsTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/TimestampUtilsTest.kt @@ -3,7 +3,7 @@ package com.emarsys.core.util import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider import com.emarsys.core.notification.NotificationManagerHelper -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.testUtil.AnnotationSpec import com.emarsys.testUtil.InstrumentationRegistry.Companion.getTargetContext @@ -17,12 +17,12 @@ import java.util.TimeZone class TimestampUtilsTest : AnnotationSpec() { companion object { - private const val HARDWARE_ID = "hwid" + private const val CLIENT_ID = "clientId" private const val SDK_VERSION = "sdkVersion" private const val LANGUAGE = "en-US" } - private lateinit var mockHardwareIdProvider: HardwareIdProvider + private lateinit var mockClientIdProvider: ClientIdProvider private lateinit var mockLanguageProvider: LanguageProvider private lateinit var mockVersionProvider: VersionProvider private lateinit var mockNotificationManagerHelper: NotificationManagerHelper @@ -30,8 +30,8 @@ class TimestampUtilsTest : AnnotationSpec() { @Before fun setup() { - mockHardwareIdProvider = mock { - on { provideHardwareId() } doReturn HARDWARE_ID + mockClientIdProvider = mock { + on { provideClientId() } doReturn CLIENT_ID } mockLanguageProvider = mock { on { provideLanguage(any()) } doReturn LANGUAGE @@ -46,7 +46,7 @@ class TimestampUtilsTest : AnnotationSpec() { fun testFormatTimestampWithUTC() { val deviceTimeZone = DeviceInfo( getTargetContext(), - mockHardwareIdProvider, + mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationManagerHelper, diff --git a/core/src/androidTest/java/com/emarsys/core/util/log/LogShardListMergerTest.kt b/core/src/androidTest/java/com/emarsys/core/util/log/LogShardListMergerTest.kt index 859e74cc4..d8e92f07c 100644 --- a/core/src/androidTest/java/com/emarsys/core/util/log/LogShardListMergerTest.kt +++ b/core/src/androidTest/java/com/emarsys/core/util/log/LogShardListMergerTest.kt @@ -45,7 +45,7 @@ class LogShardListMergerTest : AnnotationSpec() { on { applicationVersion } doReturn "1.0.0" on { osVersion } doReturn "8.0" on { model } doReturn "Pixel" - on { hardwareId } doReturn "hardwareId" + on { clientId } doReturn "clientId" on { sdkVersion } doReturn "1.6.1" } @@ -156,7 +156,7 @@ class LogShardListMergerTest : AnnotationSpec() { "sdkVersion" to "1.6.1", "osVersion" to "8.0", "model" to "Pixel", - "hwId" to "hardwareId", + "hwId" to "clientId", "applicationCode" to APPLICATION_CODE, "merchantId" to MERCHANT_ID ) diff --git a/core/src/main/java/com/emarsys/core/contentresolver/clientid/ClientIdContentResolver.kt b/core/src/main/java/com/emarsys/core/contentresolver/clientid/ClientIdContentResolver.kt new file mode 100644 index 000000000..7421c41ab --- /dev/null +++ b/core/src/main/java/com/emarsys/core/contentresolver/clientid/ClientIdContentResolver.kt @@ -0,0 +1,45 @@ +package com.emarsys.core.contentresolver.clientid + +import com.emarsys.core.Mockable +import com.emarsys.core.contentresolver.EmarsysContentResolver +import com.emarsys.core.crypto.ClientIdentificationCrypto +import com.emarsys.core.database.DatabaseContract + +@Mockable +class ClientIdContentResolver( + private val emarsysContentResolver: EmarsysContentResolver, + private val crypto: ClientIdentificationCrypto, + private val sharedPackageNames: List? +) { + + fun resolveClientId(): String? { + var index = 0 + var sharedClientId: String? = null + var encryptedClientId: String? = null + if (sharedPackageNames != null) { + while (encryptedClientId == null && index < sharedPackageNames.size) { + val cursor = emarsysContentResolver.query( + DatabaseContract.getClientIdProviderUri(sharedPackageNames[index]), + arrayOf( + DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_CLIENT_ID, + DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_SALT, + DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_IV + ), + null, null, null + ) + if (cursor != null && cursor.moveToFirst()) { + encryptedClientId = + cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_CLIENT_ID)) + val salt = + cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_SALT)) + val iv = + cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_IV)) + sharedClientId = crypto.decrypt(encryptedClientId, salt, iv) + cursor.close() + } + index++ + } + } + return sharedClientId + } +} \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolver.kt b/core/src/main/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolver.kt deleted file mode 100644 index db4114565..000000000 --- a/core/src/main/java/com/emarsys/core/contentresolver/hardwareid/HardwareIdContentResolver.kt +++ /dev/null @@ -1,45 +0,0 @@ -package com.emarsys.core.contentresolver.hardwareid - -import com.emarsys.core.Mockable -import com.emarsys.core.contentresolver.EmarsysContentResolver -import com.emarsys.core.crypto.HardwareIdentificationCrypto -import com.emarsys.core.database.DatabaseContract - -@Mockable -class HardwareIdContentResolver( - private val emarsysContentResolver: EmarsysContentResolver, - private val crypto: HardwareIdentificationCrypto, - private val sharedPackageNames: List? -) { - - fun resolveHardwareId(): String? { - var index = 0 - var sharedHardwareId: String? = null - var encryptedHardwareId: String? = null - if (sharedPackageNames != null) { - while (encryptedHardwareId == null && index < sharedPackageNames.size) { - val cursor = emarsysContentResolver.query( - DatabaseContract.getHardwareIdProviderUri(sharedPackageNames[index]), - arrayOf( - DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_HARDWARE_ID, - DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_SALT, - DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_IV - ), - null, null, null - ) - if (cursor != null && cursor.moveToFirst()) { - encryptedHardwareId = - cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_HARDWARE_ID)) - val salt = - cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_SALT)) - val iv = - cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_IV)) - sharedHardwareId = crypto.decrypt(encryptedHardwareId, salt, iv) - cursor.close() - } - index++ - } - } - return sharedHardwareId - } -} \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/crypto/ClientIdentificationCrypto.kt b/core/src/main/java/com/emarsys/core/crypto/ClientIdentificationCrypto.kt new file mode 100644 index 000000000..34a00596b --- /dev/null +++ b/core/src/main/java/com/emarsys/core/crypto/ClientIdentificationCrypto.kt @@ -0,0 +1,31 @@ +package com.emarsys.core.crypto + +import com.emarsys.core.Mockable +import com.emarsys.core.device.ClientIdentification + +@Mockable +class ClientIdentificationCrypto( + private var secret: String?, + private val crypto: Crypto +) { + + fun encrypt(clientIdentification: ClientIdentification): ClientIdentification { + var result = clientIdentification + if (secret != null) { + val encryptedClientIdentification = + crypto.encrypt(clientIdentification.clientId, secret!!) + result = result.copy( + encryptedClientId = encryptedClientIdentification["encryptedValue"], + salt = encryptedClientIdentification["salt"], + iv = encryptedClientIdentification["iv"] + ) + } + return result + } + + fun decrypt(encryptedClientId: String, salt: String, iv: String): String? { + return secret?.let { + crypto.decrypt(encryptedClientId, it, salt, iv) + } + } +} \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/crypto/HardwareIdentificationCrypto.kt b/core/src/main/java/com/emarsys/core/crypto/HardwareIdentificationCrypto.kt deleted file mode 100644 index 7d2bb6e00..000000000 --- a/core/src/main/java/com/emarsys/core/crypto/HardwareIdentificationCrypto.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.emarsys.core.crypto - -import com.emarsys.core.Mockable -import com.emarsys.core.device.HardwareIdentification - -@Mockable -class HardwareIdentificationCrypto(private var secret: String?, - private val crypto: Crypto) { - - fun encrypt(hardwareIdentification: HardwareIdentification): HardwareIdentification { - var result = hardwareIdentification - if (secret != null) { - val encryptedHardwareIdentification = crypto.encrypt(hardwareIdentification.hardwareId, secret!!) - result = result.copy( - encryptedHardwareId = encryptedHardwareIdentification["encryptedValue"], - salt = encryptedHardwareIdentification["salt"], - iv = encryptedHardwareIdentification["iv"] - ) - } - return result - } - - fun decrypt(encryptedHardwareId: String, salt: String, iv: String): String? { - return secret?.let { - crypto.decrypt(encryptedHardwareId, it, salt, iv) - } - } -} \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/database/DatabaseContract.kt b/core/src/main/java/com/emarsys/core/database/DatabaseContract.kt index 50c92f51c..f9d168348 100644 --- a/core/src/main/java/com/emarsys/core/database/DatabaseContract.kt +++ b/core/src/main/java/com/emarsys/core/database/DatabaseContract.kt @@ -7,7 +7,7 @@ object DatabaseContract { const val SHARD_TABLE_NAME = "shard" const val DISPLAYED_IAM_TABLE_NAME = "displayed_iam" const val BUTTON_CLICKED_TABLE_NAME = "button_clicked" - const val HARDWARE_IDENTIFICATION_TABLE_NAME = "hardware_identification" + const val CLIENT_IDENTIFICATION_TABLE_NAME = "hardware_identification" const val REQUEST_COLUMN_NAME_REQUEST_ID = "request_id" const val REQUEST_COLUMN_NAME_METHOD = "method" const val REQUEST_COLUMN_NAME_URL = "url" @@ -25,13 +25,14 @@ object DatabaseContract { const val BUTTON_CLICKED_COLUMN_NAME_CAMPAIGN_ID = "campaign_id" const val BUTTON_CLICKED_COLUMN_NAME_BUTTON_ID = "button_id" const val BUTTON_CLICKED_COLUMN_NAME_TIMESTAMP = "timestamp" - const val HARDWARE_IDENTIFICATION_COLUMN_NAME_HARDWARE_ID = "hardware_id" - const val HARDWARE_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_HARDWARE_ID = "encrypted_hardware_id" - const val HARDWARE_IDENTIFICATION_COLUMN_NAME_SALT = "salt" - const val HARDWARE_IDENTIFICATION_COLUMN_NAME_IV = "iv" + const val CLIENT_IDENTIFICATION_COLUMN_NAME_CLIENT_ID = "hardware_id" + const val CLIENT_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_CLIENT_ID = "encrypted_hardware_id" + const val CLIENT_IDENTIFICATION_COLUMN_NAME_SALT = "salt" + const val CLIENT_IDENTIFICATION_COLUMN_NAME_IV = "iv" - fun getHardwareIdProviderUri(authority: String): Uri { - return Uri.parse("content://$authority").buildUpon().appendPath(HARDWARE_IDENTIFICATION_TABLE_NAME).build() + fun getClientIdProviderUri(authority: String): Uri { + return Uri.parse("content://$authority").buildUpon() + .appendPath(CLIENT_IDENTIFICATION_TABLE_NAME).build() } val UPGRADE_TO_1 = arrayOf( diff --git a/core/src/main/java/com/emarsys/core/device/HardwareIdentification.kt b/core/src/main/java/com/emarsys/core/device/ClientIdentification.kt similarity index 55% rename from core/src/main/java/com/emarsys/core/device/HardwareIdentification.kt rename to core/src/main/java/com/emarsys/core/device/ClientIdentification.kt index 0c8844a9e..b2a6fde82 100644 --- a/core/src/main/java/com/emarsys/core/device/HardwareIdentification.kt +++ b/core/src/main/java/com/emarsys/core/device/ClientIdentification.kt @@ -3,9 +3,9 @@ package com.emarsys.core.device import com.emarsys.core.Mockable @Mockable -data class HardwareIdentification( - val hardwareId: String, - val encryptedHardwareId: String? = null, +data class ClientIdentification( + val clientId: String, + val encryptedClientId: String? = null, val salt: String? = null, val iv: String? = null ) \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/device/ClientRepository.kt b/core/src/main/java/com/emarsys/core/device/ClientRepository.kt new file mode 100644 index 000000000..edce99dc4 --- /dev/null +++ b/core/src/main/java/com/emarsys/core/device/ClientRepository.kt @@ -0,0 +1,43 @@ +package com.emarsys.core.device + +import android.content.ContentValues +import android.database.Cursor +import com.emarsys.core.database.DatabaseContract +import com.emarsys.core.database.helper.DbHelper +import com.emarsys.core.database.repository.AbstractSqliteRepository +import com.emarsys.core.handler.ConcurrentHandlerHolder + +class ClientRepository(dbHelper: DbHelper, concurrentHandlerHolder: ConcurrentHandlerHolder) : + AbstractSqliteRepository( + DatabaseContract.CLIENT_IDENTIFICATION_TABLE_NAME, dbHelper, + concurrentHandlerHolder + ) { + + override fun contentValuesFromItem(item: ClientIdentification?): ContentValues { + val contentValues = ContentValues() + contentValues.put( + DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_CLIENT_ID, + item?.clientId + ) + contentValues.put( + DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_CLIENT_ID, + item?.encryptedClientId + ) + contentValues.put(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_SALT, item?.salt) + contentValues.put(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_IV, item?.iv) + return contentValues + } + + override fun itemFromCursor(cursor: Cursor): ClientIdentification { + val clientId = + cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_CLIENT_ID)) + val encryptedClientId = + cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_CLIENT_ID)) + val salt = + cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_SALT)) + val iv = + cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_IV)) + return ClientIdentification(clientId, encryptedClientId, salt, iv) + } + +} \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/device/DeviceInfo.kt b/core/src/main/java/com/emarsys/core/device/DeviceInfo.kt index 6207df57a..30bd999ad 100644 --- a/core/src/main/java/com/emarsys/core/device/DeviceInfo.kt +++ b/core/src/main/java/com/emarsys/core/device/DeviceInfo.kt @@ -8,7 +8,7 @@ import android.os.Build import android.util.DisplayMetrics import com.emarsys.core.Mockable import com.emarsys.core.api.notification.NotificationSettings -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.core.util.AndroidVersionUtils import org.json.JSONObject @@ -19,7 +19,7 @@ import java.util.Locale @Mockable data class DeviceInfo( private val context: Context, - private val hardwareIdProvider: HardwareIdProvider, + private val clientIdProvider: ClientIdProvider, private val versionProvider: VersionProvider, private val languageProvider: LanguageProvider, val notificationSettings: NotificationSettings, @@ -31,7 +31,7 @@ data class DeviceInfo( const val UNKNOWN_VERSION_NAME = "unknown" } - val hardwareId: String = hardwareIdProvider.provideHardwareId() + val clientId: String = clientIdProvider.provideClientId() val platform: String get() { return if (isGooglePlayAvailable) "android" else "android-huawei" @@ -66,7 +66,7 @@ data class DeviceInfo( "importance" to notificationSettings.importance, "areNotificationsEnabled" to notificationSettings.areNotificationsEnabled ), - "hwid" to hardwareId, + "hwid" to clientId, "platform" to platform, "language" to language, "timezone" to timezone, diff --git a/core/src/main/java/com/emarsys/core/device/FilterByHardwareId.kt b/core/src/main/java/com/emarsys/core/device/FilterByClientId.kt similarity index 90% rename from core/src/main/java/com/emarsys/core/device/FilterByHardwareId.kt rename to core/src/main/java/com/emarsys/core/device/FilterByClientId.kt index cb6469fd1..4c68bfe38 100644 --- a/core/src/main/java/com/emarsys/core/device/FilterByHardwareId.kt +++ b/core/src/main/java/com/emarsys/core/device/FilterByClientId.kt @@ -2,7 +2,7 @@ package com.emarsys.core.device import com.emarsys.core.database.repository.AbstractSqlSpecification -data class FilterByHardwareId( +data class FilterByClientId( private val arg: String, override val selection: String = "hardware_id=?") : AbstractSqlSpecification() { diff --git a/core/src/main/java/com/emarsys/core/device/HardwareRepository.kt b/core/src/main/java/com/emarsys/core/device/HardwareRepository.kt deleted file mode 100644 index b086b20a8..000000000 --- a/core/src/main/java/com/emarsys/core/device/HardwareRepository.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.emarsys.core.device - -import android.content.ContentValues -import android.database.Cursor -import com.emarsys.core.database.DatabaseContract -import com.emarsys.core.database.helper.DbHelper -import com.emarsys.core.database.repository.AbstractSqliteRepository -import com.emarsys.core.handler.ConcurrentHandlerHolder - -class HardwareRepository(dbHelper: DbHelper, concurrentHandlerHolder: ConcurrentHandlerHolder) : - AbstractSqliteRepository( - DatabaseContract.HARDWARE_IDENTIFICATION_TABLE_NAME, dbHelper, - concurrentHandlerHolder - ) { - - override fun contentValuesFromItem(item: HardwareIdentification?): ContentValues { - val contentValues = ContentValues() - contentValues.put( - DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_HARDWARE_ID, - item?.hardwareId - ) - contentValues.put( - DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_HARDWARE_ID, - item?.encryptedHardwareId - ) - contentValues.put(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_SALT, item?.salt) - contentValues.put(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_IV, item?.iv) - return contentValues - } - - override fun itemFromCursor(cursor: Cursor): HardwareIdentification { - val hardwareId = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_HARDWARE_ID)) - val encryptedHardwareId = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_HARDWARE_ID)) - val salt = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_SALT)) - val iv = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_IV)) - return HardwareIdentification(hardwareId, encryptedHardwareId, salt, iv) - } - -} \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/di/CoreComponent.kt b/core/src/main/java/com/emarsys/core/di/CoreComponent.kt index 893f91f0b..186904469 100644 --- a/core/src/main/java/com/emarsys/core/di/CoreComponent.kt +++ b/core/src/main/java/com/emarsys/core/di/CoreComponent.kt @@ -13,7 +13,7 @@ import com.emarsys.core.database.repository.Repository import com.emarsys.core.database.repository.SqlSpecification import com.emarsys.core.device.DeviceInfo import com.emarsys.core.handler.ConcurrentHandlerHolder -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.RequestManager @@ -78,11 +78,11 @@ interface CoreComponent { val sharedPreferencesV3: SharedPreferences - val hardwareIdProvider: HardwareIdProvider + val clientIdProvider: ClientIdProvider val coreDbHelper: CoreDbHelper - val hardwareIdStorage: Storage + val clientIdStorage: Storage val logLevelStorage: Storage diff --git a/core/src/main/java/com/emarsys/core/provider/clientid/ClientIdProvider.kt b/core/src/main/java/com/emarsys/core/provider/clientid/ClientIdProvider.kt new file mode 100644 index 000000000..74fed2d5b --- /dev/null +++ b/core/src/main/java/com/emarsys/core/provider/clientid/ClientIdProvider.kt @@ -0,0 +1,70 @@ +package com.emarsys.core.provider.clientid + +import com.emarsys.core.Mockable +import com.emarsys.core.contentresolver.clientid.ClientIdContentResolver +import com.emarsys.core.crypto.ClientIdentificationCrypto +import com.emarsys.core.database.repository.Repository +import com.emarsys.core.database.repository.SqlSpecification +import com.emarsys.core.database.repository.specification.Everything +import com.emarsys.core.device.ClientIdentification +import com.emarsys.core.device.FilterByClientId +import com.emarsys.core.provider.uuid.UUIDProvider +import com.emarsys.core.storage.Storage +import com.emarsys.core.util.log.Logger +import com.emarsys.core.util.log.entry.StatusLog + +@Mockable +class ClientIdProvider( + private val uuidProvider: UUIDProvider, + private val repository: Repository, + private val clientIdStorage: Storage, + private val clientIdContentResolver: ClientIdContentResolver, + private val clientIdentificationCrypto: ClientIdentificationCrypto +) { + + fun provideClientId(): String { + val client: ClientIdentification? = try { + repository.query(Everything()).firstOrNull() + } catch (error: Exception) { + val status = mutableMapOf() + status["message"] = error.message ?: "" + status["stackTrace"] = error.stackTrace.map { it.toString() } + Logger.error( + StatusLog( + this::class.java, + "provideClientId", + parameters = null, + status = status + ) + ) + null + } + return if (client != null) { + if (client.encryptedClientId == null) { + clientIdentificationCrypto.encrypt(client).also { + repository.update(it, FilterByClientId(it.clientId)) + } + client.clientId + } else { + client.clientId + } + } else { + getClientIdentification().also { + repository.add(it) + }.clientId + } + } + + private fun getClientIdentification(): ClientIdentification { + return (clientIdStorage.get() ?: clientIdContentResolver.resolveClientId() + ?: generateNewClientId()).asEncryptedClientIdentification() + } + + private fun generateNewClientId(): String { + return uuidProvider.provideId() + } + + private fun String.asEncryptedClientIdentification(): ClientIdentification { + return clientIdentificationCrypto.encrypt(ClientIdentification(this)) + } +} \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/provider/hardwareid/HardwareIdProvider.kt b/core/src/main/java/com/emarsys/core/provider/hardwareid/HardwareIdProvider.kt deleted file mode 100644 index 94d9f276d..000000000 --- a/core/src/main/java/com/emarsys/core/provider/hardwareid/HardwareIdProvider.kt +++ /dev/null @@ -1,63 +0,0 @@ -package com.emarsys.core.provider.hardwareid - -import com.emarsys.core.Mockable -import com.emarsys.core.contentresolver.hardwareid.HardwareIdContentResolver -import com.emarsys.core.crypto.HardwareIdentificationCrypto -import com.emarsys.core.database.repository.Repository -import com.emarsys.core.database.repository.SqlSpecification -import com.emarsys.core.database.repository.specification.Everything -import com.emarsys.core.device.FilterByHardwareId -import com.emarsys.core.device.HardwareIdentification -import com.emarsys.core.provider.uuid.UUIDProvider -import com.emarsys.core.storage.Storage -import com.emarsys.core.util.log.Logger -import com.emarsys.core.util.log.entry.StatusLog - -@Mockable -class HardwareIdProvider( - private val uuidProvider: UUIDProvider, - private val repository: Repository, - private val hwIdStorage: Storage, - private val hardwareIdContentResolver: HardwareIdContentResolver, - private val hardwareIdentificationCrypto: HardwareIdentificationCrypto -) { - - fun provideHardwareId(): String { - val hardware: HardwareIdentification? = try { - repository.query(Everything()).firstOrNull() - } catch (error: Exception) { - val status = mutableMapOf() - status["message"] = error.message ?: "" - status["stackTrace"] = error.stackTrace.map { it.toString() } - Logger.error(StatusLog(this::class.java, "provideHardwareId", parameters = null, status = status)) - null - } - return if (hardware != null) { - if (hardware.encryptedHardwareId == null) { - hardwareIdentificationCrypto.encrypt(hardware).also { - repository.update(it, FilterByHardwareId(it.hardwareId)) - } - hardware.hardwareId - } else { - hardware.hardwareId - } - } else { - getHardwareIdentification().also { - repository.add(it) - }.hardwareId - } - } - - private fun getHardwareIdentification(): HardwareIdentification { - return (hwIdStorage.get() ?: hardwareIdContentResolver.resolveHardwareId() - ?: generateNewHardwareId()).asEncryptedHardwareIdentification() - } - - private fun generateNewHardwareId(): String { - return uuidProvider.provideId() - } - - private fun String.asEncryptedHardwareIdentification(): HardwareIdentification { - return hardwareIdentificationCrypto.encrypt(HardwareIdentification(this)) - } -} \ No newline at end of file diff --git a/core/src/main/java/com/emarsys/core/util/log/LogShardListMerger.java b/core/src/main/java/com/emarsys/core/util/log/LogShardListMerger.java index 4cbf8865b..34cd66e3c 100644 --- a/core/src/main/java/com/emarsys/core/util/log/LogShardListMerger.java +++ b/core/src/main/java/com/emarsys/core/util/log/LogShardListMerger.java @@ -72,7 +72,7 @@ private Map createDeviceInfo() { data.put("sdkVersion", deviceInfo.getSdkVersion()); data.put("osVersion", deviceInfo.getOsVersion()); data.put("model", deviceInfo.getModel()); - data.put("hwId", deviceInfo.getHardwareId()); + data.put("hwId", deviceInfo.getClientId()); data.put("applicationCode", applicationCode); data.put("merchantId", merchantId); return data; diff --git a/emarsys-e2e-test/src/androidTest/java/com/emarsys/testUtil/E2ETestUtils.kt b/emarsys-e2e-test/src/androidTest/java/com/emarsys/testUtil/E2ETestUtils.kt index b13b6d9a6..f4692a6af 100644 --- a/emarsys-e2e-test/src/androidTest/java/com/emarsys/testUtil/E2ETestUtils.kt +++ b/emarsys-e2e-test/src/androidTest/java/com/emarsys/testUtil/E2ETestUtils.kt @@ -19,7 +19,7 @@ object E2ETestUtils { emarsys().contactTokenStorage.remove() emarsys().clientStateStorage.remove() emarsys().pushTokenStorage.remove() - emarsys().hardwareIdStorage.remove() + emarsys().clientIdStorage.remove() emarsys().refreshTokenStorage.remove() emarsys().contactFieldValueStorage.remove() emarsys().clientServiceStorage.remove() diff --git a/emarsys-firebase/src/androidTest/java/com/emarsys/fake/FakeFirebaseDependencyContainer.kt b/emarsys-firebase/src/androidTest/java/com/emarsys/fake/FakeFirebaseDependencyContainer.kt index 5a6cf7a32..2476a5358 100644 --- a/emarsys-firebase/src/androidTest/java/com/emarsys/fake/FakeFirebaseDependencyContainer.kt +++ b/emarsys-firebase/src/androidTest/java/com/emarsys/fake/FakeFirebaseDependencyContainer.kt @@ -19,7 +19,7 @@ import com.emarsys.core.device.DeviceInfo import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.provider.activity.CurrentActivityProvider -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.RequestManager @@ -136,9 +136,9 @@ class FakeFirebaseDependencyContainer( override val fileDownloader: FileDownloader = mock(), override val keyValueStore: KeyValueStore = mock(), override val sharedPreferences: SharedPreferences = mock(), - override val hardwareIdProvider: HardwareIdProvider = mock(), + override val clientIdProvider: ClientIdProvider = mock(), override val coreDbHelper: CoreDbHelper = mock(), - override val hardwareIdStorage: Storage = mock(), + override val clientIdStorage: Storage = mock(), override val logLevelStorage: Storage = mock(), override val crypto: Crypto = mock(), override val requestManager: RequestManager = mock(), diff --git a/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceTest.kt b/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceTest.kt index 454f491d3..6b611d8b8 100644 --- a/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceTest.kt +++ b/emarsys-firebase/src/androidTest/java/com/emarsys/service/EmarsysFirebaseMessagingServiceTest.kt @@ -95,7 +95,7 @@ class EmarsysFirebaseMessagingServiceTest : AnnotationSpec() { val deviceInfo = DeviceInfo( application, mock { - on { provideHardwareId() } doReturn "hardwareId" + on { provideClientId() } doReturn "clientId" }, mock { on { provideSdkVersion() } doReturn "version" diff --git a/emarsys-huawei/src/androidTest/java/com/emarsys/fake/FakeHuaweiDependencyContainer.kt b/emarsys-huawei/src/androidTest/java/com/emarsys/fake/FakeHuaweiDependencyContainer.kt index 550320c1e..1dbd76b3b 100644 --- a/emarsys-huawei/src/androidTest/java/com/emarsys/fake/FakeHuaweiDependencyContainer.kt +++ b/emarsys-huawei/src/androidTest/java/com/emarsys/fake/FakeHuaweiDependencyContainer.kt @@ -19,7 +19,7 @@ import com.emarsys.core.device.DeviceInfo import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.provider.activity.CurrentActivityProvider -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.RequestManager @@ -136,9 +136,9 @@ class FakeHuaweiDependencyContainer( override val fileDownloader: FileDownloader = mock(), override val keyValueStore: KeyValueStore = mock(), override val sharedPreferences: SharedPreferences = mock(), - override val hardwareIdProvider: HardwareIdProvider = mock(), + override val clientIdProvider: ClientIdProvider = mock(), override val coreDbHelper: CoreDbHelper = mock(), - override val hardwareIdStorage: Storage = mock(), + override val clientIdStorage: Storage = mock(), override val logLevelStorage: Storage = mock(), override val crypto: Crypto = mock(), override val requestManager: RequestManager = mock(), diff --git a/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceTest.kt b/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceTest.kt index e6651b09d..01e0f5703 100644 --- a/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceTest.kt +++ b/emarsys-huawei/src/androidTest/java/com/emarsys/service/EmarsysHuaweiMessagingServiceTest.kt @@ -96,7 +96,7 @@ class EmarsysHuaweiMessagingServiceTest : AnnotationSpec() { val deviceInfo = DeviceInfo( application, mock { - on { provideHardwareId() } doReturn "hardwareId" + on { provideClientId() } doReturn "clientId" }, mock { on { provideSdkVersion() } doReturn "version" diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/DefaultInboxIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/DefaultInboxIntegrationTest.kt index 08f7937b5..edfca170f 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/DefaultInboxIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/DefaultInboxIntegrationTest.kt @@ -6,7 +6,7 @@ import com.emarsys.config.EmarsysConfig import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider import com.emarsys.core.notification.NotificationManagerHelper -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.di.DefaultEmarsysComponent import com.emarsys.di.DefaultEmarsysDependencies @@ -65,8 +65,8 @@ class DefaultInboxIntegrationTest : AnnotationSpec() { latch = CountDownLatch(1) val deviceInfo = DeviceInfo( application, - mockk(relaxed = true).apply { - every { provideHardwareId() } returns "inboxv1_integration_hwid" + mockk(relaxed = true).apply { + every { provideClientId() } returns "inboxv1_integration_hwid" }, mockk(relaxed = true).apply { every { provideSdkVersion() } returns SDK_VERSION diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt index 554af42c5..93153edf0 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/EmarsysTest.kt @@ -28,7 +28,7 @@ import com.emarsys.core.database.trigger.TriggerType import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider import com.emarsys.core.feature.FeatureRegistry -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.core.request.RequestManager import com.emarsys.core.response.ResponseHandlersProcessor @@ -138,7 +138,7 @@ class EmarsysTest : AnnotationSpec() { private lateinit var mockConfig: ConfigApi private lateinit var mockConfigInternal: ConfigInternal private lateinit var mockMessageInbox: MessageInboxApi - private lateinit var mockHardwareIdProvider: HardwareIdProvider + private lateinit var mockClientIdProvider: ClientIdProvider private lateinit var mockLanguageProvider: LanguageProvider private lateinit var mockNotificationManagerHelper: NotificationSettings private lateinit var mockVersionProvider: VersionProvider @@ -195,7 +195,7 @@ class EmarsysTest : AnnotationSpec() { .merchantId(MERCHANT_ID) .build() mockRequestContext = mockk(relaxed = true) - mockHardwareIdProvider = mockk(relaxed = true) + mockClientIdProvider = mockk(relaxed = true) mockMobileEngageApi = mockk(relaxed = true) mockLoggingMobileEngageApi = mockk(relaxed = true) mockInApp = mockk(relaxed = true) @@ -217,7 +217,7 @@ class EmarsysTest : AnnotationSpec() { every { mockNotificationManagerHelper.importance } returns -1000 every { mockNotificationManagerHelper.areNotificationsEnabled } returns false - every { mockHardwareIdProvider.provideHardwareId() } returns "hwid" + every { mockClientIdProvider.provideClientId() } returns "hwid" every { mockLanguageProvider.provideLanguage(any()) } returns "language" @@ -225,7 +225,7 @@ class EmarsysTest : AnnotationSpec() { every { mockVersionProvider.provideSdkVersion() } returns "version" deviceInfo = DeviceInfo( - application, mockHardwareIdProvider, mockVersionProvider, + application, mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationManagerHelper, isAutomaticPushSendingEnabled = true, isGooglePlayAvailable = true ) diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageIntegrationTest.kt index 3ed6c4274..23fdc36f4 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageIntegrationTest.kt @@ -12,7 +12,7 @@ import com.emarsys.core.DefaultCoreCompletionHandler import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider import com.emarsys.core.notification.NotificationManagerHelper -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.core.response.ResponseModel import com.emarsys.di.DefaultEmarsysComponent @@ -85,8 +85,8 @@ class MobileEngageIntegrationTest : AnnotationSpec() { } val deviceInfo = DeviceInfo( application, - mockk(relaxed = true).apply { - every { provideHardwareId() } returns "mobileengage_integration_hwid" + mockk(relaxed = true).apply { + every { provideClientId() } returns "mobileengage_integration_hwid" }, mockk(relaxed = true).apply { every { provideSdkVersion() } returns "0.0.0-mobileengage_integration_version" diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageRefreshContactTokenIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageRefreshContactTokenIntegrationTest.kt index 39c49d8ff..6b091a97e 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageRefreshContactTokenIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/MobileEngageRefreshContactTokenIntegrationTest.kt @@ -8,7 +8,7 @@ import com.emarsys.config.EmarsysConfig import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider import com.emarsys.core.notification.NotificationManagerHelper -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.core.storage.Storage import com.emarsys.di.DefaultEmarsysComponent @@ -67,8 +67,8 @@ class MobileEngageRefreshContactTokenIntegrationTest : AnnotationSpec() { val deviceInfo = DeviceInfo( application, - mockk(relaxed = true).apply { - every { provideHardwareId() } returns "mobileengage_integration_hwid" + mockk(relaxed = true).apply { + every { provideClientId() } returns "mobileengage_integration_hwid" }, mockk(relaxed = true).apply { every { provideSdkVersion() } returns "0.0.0-mobileengage_integration_version" diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/PredictIntegrationTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/PredictIntegrationTest.kt index 943646072..39208b34a 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/PredictIntegrationTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/PredictIntegrationTest.kt @@ -9,7 +9,7 @@ import com.emarsys.core.api.result.Try import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider import com.emarsys.core.notification.NotificationManagerHelper -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.core.response.ResponseModel import com.emarsys.core.storage.Storage @@ -124,8 +124,8 @@ class PredictIntegrationTest : AnnotationSpec() { val deviceInfo = DeviceInfo( application, - mockk(relaxed = true).apply { - every { provideHardwareId() } returns "mobileengage_integration_hwid" + mockk(relaxed = true).apply { + every { provideClientId() } returns "mobileengage_integration_hwid" }, mockk(relaxed = true).apply { every { provideSdkVersion() } returns "0.0.0-mobileengage_integration_version" diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt index 6ed8cca4f..6bef5740a 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/config/ConfigTest.kt @@ -133,14 +133,14 @@ class ConfigTest : AnnotationSpec() { } @Test - fun testGetHardwareId_delegatesTo_internal() { - val hardwareId = "testHardwareId" - whenever(mockConfigInternal.hardwareId).thenReturn(hardwareId) + fun testGetClientId_delegatesTo_internal() { + val clientId = "testClientId" + whenever(mockConfigInternal.clientId).thenReturn(clientId) val result = config.hardwareId - result shouldBe hardwareId - verify(mockConfigInternal).hardwareId + result shouldBe clientId + verify(mockConfigInternal).clientId } @Test diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/di/FakeDependencyContainer.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/di/FakeDependencyContainer.kt index f8574b322..c09a1dbd1 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/di/FakeDependencyContainer.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/di/FakeDependencyContainer.kt @@ -23,7 +23,7 @@ import com.emarsys.core.device.DeviceInfo import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.provider.activity.CurrentActivityProvider -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.RequestManager @@ -175,9 +175,9 @@ class FakeDependencyContainer( override val fileDownloader: FileDownloader = mock(), override val keyValueStore: KeyValueStore = mock(), override val sharedPreferences: SharedPreferences = mock(), - override val hardwareIdProvider: HardwareIdProvider = mock(), + override val clientIdProvider: ClientIdProvider = mock(), override val coreDbHelper: CoreDbHelper = mock(), - override val hardwareIdStorage: Storage = mock(), + override val clientIdStorage: Storage = mock(), override val logLevelStorage: Storage = mock(), override val crypto: Crypto = mock(), override val requestManager: RequestManager = mock(), diff --git a/emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedHardwareIdentificationContentProviderTest.kt b/emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedClientIdentificationContentProviderTest.kt similarity index 90% rename from emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedHardwareIdentificationContentProviderTest.kt rename to emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedClientIdentificationContentProviderTest.kt index 61f29906f..ee381109c 100644 --- a/emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedHardwareIdentificationContentProviderTest.kt +++ b/emarsys-sdk/src/androidTest/java/com/emarsys/provider/SharedClientIdentificationContentProviderTest.kt @@ -11,10 +11,10 @@ import io.kotest.matchers.shouldBe import io.mockk.every import io.mockk.mockk -class SharedHardwareIdentificationContentProviderTest : AnnotationSpec() { +class SharedClientIdentificationContentProviderTest : AnnotationSpec() { private companion object { - const val ENCRYPTED_HARDWARE_ID = "encrypted_hardware_id" + const val ENCRYPTED_CLIENT_ID = "encrypted_hardware_id" const val SALT = "salt" const val IV = "iv" } @@ -27,7 +27,7 @@ class SharedHardwareIdentificationContentProviderTest : AnnotationSpec() { @Before fun setUp() { mockCursor = mockk { - every { getString(0) } returns ENCRYPTED_HARDWARE_ID + every { getString(0) } returns ENCRYPTED_CLIENT_ID every { getString(1) } returns SALT every { getString(2) } returns IV } @@ -61,7 +61,7 @@ class SharedHardwareIdentificationContentProviderTest : AnnotationSpec() { } @Test - fun testQuery_shouldReturnCursorWithEncryptedHardwareId_salt_iv() { + fun testQuery_shouldReturnCursorWithEncryptedClientId_salt_iv() { val mockContext: Context = mockk { every { packageName } returns "com.emarsys.test" } diff --git a/emarsys-sdk/src/main/java/com/emarsys/config/Config.kt b/emarsys-sdk/src/main/java/com/emarsys/config/Config.kt index 00cd12d38..c3f86970c 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/config/Config.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/config/Config.kt @@ -16,8 +16,12 @@ class Config : ConfigApi { override val merchantId: String? get() = emarsys().configInternal.merchantId + @Deprecated("Use clientId instead") override val hardwareId: String - get() = emarsys().configInternal.hardwareId + get() = emarsys().configInternal.clientId + + override val clientId: String + get() = emarsys().configInternal.clientId override val languageCode: String get() = emarsys().configInternal.language @@ -35,7 +39,10 @@ class Config : ConfigApi { emarsys().configInternal.changeApplicationCode(applicationCode, null) } - override fun changeApplicationCode(applicationCode: String?, completionListener: CompletionListener?) { + override fun changeApplicationCode( + applicationCode: String?, + completionListener: CompletionListener? + ) { emarsys().configInternal.changeApplicationCode(applicationCode, completionListener) } diff --git a/emarsys-sdk/src/main/java/com/emarsys/config/ConfigApi.kt b/emarsys-sdk/src/main/java/com/emarsys/config/ConfigApi.kt index b788d470d..06bd04351 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/config/ConfigApi.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/config/ConfigApi.kt @@ -11,8 +11,11 @@ interface ConfigApi { val merchantId: String? + @Deprecated("Use clientId instead") val hardwareId: String + val clientId: String + val languageCode: String val notificationSettings: NotificationSettings diff --git a/emarsys-sdk/src/main/java/com/emarsys/di/DefaultEmarsysComponent.kt b/emarsys-sdk/src/main/java/com/emarsys/di/DefaultEmarsysComponent.kt index 37c95633b..eed9cdbbf 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/di/DefaultEmarsysComponent.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/di/DefaultEmarsysComponent.kt @@ -32,16 +32,16 @@ import com.emarsys.core.concurrency.ConcurrentHandlerHolderFactory import com.emarsys.core.connection.ConnectionProvider import com.emarsys.core.connection.ConnectionWatchDog import com.emarsys.core.contentresolver.EmarsysContentResolver -import com.emarsys.core.contentresolver.hardwareid.HardwareIdContentResolver +import com.emarsys.core.contentresolver.clientid.ClientIdContentResolver +import com.emarsys.core.crypto.ClientIdentificationCrypto import com.emarsys.core.crypto.Crypto -import com.emarsys.core.crypto.HardwareIdentificationCrypto import com.emarsys.core.crypto.SharedPreferenceCrypto import com.emarsys.core.database.CoreSQLiteDatabase import com.emarsys.core.database.helper.CoreDbHelper import com.emarsys.core.database.repository.Repository import com.emarsys.core.database.repository.SqlSpecification +import com.emarsys.core.device.ClientRepository import com.emarsys.core.device.DeviceInfo -import com.emarsys.core.device.HardwareRepository import com.emarsys.core.device.LanguageProvider import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.handler.ConcurrentHandlerHolder @@ -50,7 +50,7 @@ import com.emarsys.core.notification.NotificationManagerProxy import com.emarsys.core.permission.PermissionChecker import com.emarsys.core.provider.activity.CurrentActivityProvider import com.emarsys.core.provider.activity.FallbackActivityProvider -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.random.RandomProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider @@ -456,7 +456,7 @@ open class DefaultEmarsysComponent(config: EmarsysConfig) : EmarsysComponent { UUIDProvider() } - override val hardwareIdStorage: Storage by lazy { + override val clientIdStorage: Storage by lazy { StringStorage(CoreStorageKey.HARDWARE_ID, sharedPreferencesV3) } @@ -468,21 +468,21 @@ open class DefaultEmarsysComponent(config: EmarsysConfig) : EmarsysComponent { Crypto(createPublicKey()) } - override val hardwareIdProvider: HardwareIdProvider by lazy { - val hardwareRepository = HardwareRepository(coreDbHelper, concurrentHandlerHolder) - val hardwareIdentificationCrypto = HardwareIdentificationCrypto(config.sharedSecret, crypto) + override val clientIdProvider: ClientIdProvider by lazy { + val clientRepository = ClientRepository(coreDbHelper, concurrentHandlerHolder) + val clientIdentificationCrypto = ClientIdentificationCrypto(config.sharedSecret, crypto) val emarsysContentResolver = EmarsysContentResolver(config.application) - val hardwareIdContentResolver = HardwareIdContentResolver( + val clientIdContentResolver = ClientIdContentResolver( emarsysContentResolver, - hardwareIdentificationCrypto, + clientIdentificationCrypto, config.sharedPackageNames ) - HardwareIdProvider( + ClientIdProvider( uuidProvider, - hardwareRepository, - hardwareIdStorage, - hardwareIdContentResolver, - hardwareIdentificationCrypto + clientRepository, + clientIdStorage, + clientIdContentResolver, + clientIdentificationCrypto ) } @@ -496,7 +496,7 @@ open class DefaultEmarsysComponent(config: EmarsysConfig) : EmarsysComponent { NotificationManagerHelper(notificationManagerProxy) DeviceInfo( config.application, - hardwareIdProvider, + clientIdProvider, VersionProvider(), LanguageProvider(), notificationSettings, @@ -934,7 +934,7 @@ open class DefaultEmarsysComponent(config: EmarsysConfig) : EmarsysComponent { deviceInfo, requestManager, emarsysRequestModelFactory, - RemoteConfigResponseMapper(RandomProvider(), hardwareIdProvider), + RemoteConfigResponseMapper(RandomProvider(), clientIdProvider), clientServiceStorage, eventServiceStorage, deepLinkServiceStorage, @@ -1080,7 +1080,7 @@ open class DefaultEmarsysComponent(config: EmarsysConfig) : EmarsysComponent { "EMARSYS_SDK", "AutomaticPushSendingEnabled : ${emarsysConfig.automaticPushTokenSendingEnabled}" ) - Log.d("EMARSYS_SDK", "HardwareId : ${hardwareIdProvider.provideHardwareId()}") + Log.d("EMARSYS_SDK", "ClientId : ${clientIdProvider.provideClientId()}") Log.d( "EMARSYS_SDK", diff --git a/emarsys-sdk/src/main/java/com/emarsys/provider/SharedHardwareIdentificationContentProvider.kt b/emarsys-sdk/src/main/java/com/emarsys/provider/SharedHardwareIdentificationContentProvider.kt index f19947fa9..c5c5b56d6 100644 --- a/emarsys-sdk/src/main/java/com/emarsys/provider/SharedHardwareIdentificationContentProvider.kt +++ b/emarsys-sdk/src/main/java/com/emarsys/provider/SharedHardwareIdentificationContentProvider.kt @@ -20,11 +20,14 @@ class SharedHardwareIdentificationContentProvider : ContentProvider() { override fun query(uri: Uri, projection: Array?, selection: String?, selectionArgs: Array?, sortOrder: String?): Cursor? { return if (context != null) { - if (uri == DatabaseContract.getHardwareIdProviderUri(context!!.packageName)) { - coreDbHelper.readableCoreDatabase.query(false, DatabaseContract.HARDWARE_IDENTIFICATION_TABLE_NAME, - arrayOf(DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_HARDWARE_ID, - DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_SALT, - DatabaseContract.HARDWARE_IDENTIFICATION_COLUMN_NAME_IV), + if (uri == DatabaseContract.getClientIdProviderUri(context!!.packageName)) { + coreDbHelper.readableCoreDatabase.query( + false, DatabaseContract.CLIENT_IDENTIFICATION_TABLE_NAME, + arrayOf( + DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_ENCRYPTED_CLIENT_ID, + DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_SALT, + DatabaseContract.CLIENT_IDENTIFICATION_COLUMN_NAME_IV + ), null, null, null, null, null, null) } else { null diff --git a/emarsys/src/androidTest/java/com/emarsys/EmarsysRequestModelFactoryTest.kt b/emarsys/src/androidTest/java/com/emarsys/EmarsysRequestModelFactoryTest.kt index 86c012a12..e761af3a2 100644 --- a/emarsys/src/androidTest/java/com/emarsys/EmarsysRequestModelFactoryTest.kt +++ b/emarsys/src/androidTest/java/com/emarsys/EmarsysRequestModelFactoryTest.kt @@ -15,7 +15,7 @@ import org.mockito.kotlin.mock class EmarsysRequestModelFactoryTest : AnnotationSpec() { companion object { - const val HARDWARE_ID = "hardware_id" + const val CLIENT_ID = "client_id" const val TIMESTAMP = 123456789L const val REQUEST_ID = "request_id" const val APPLICATION_CODE = "applicationCode" @@ -39,7 +39,7 @@ class EmarsysRequestModelFactoryTest : AnnotationSpec() { } mockDeviceInfo = mock { - on { hardwareId } doReturn HARDWARE_ID + on { clientId } doReturn CLIENT_ID } mockMobileEngageRequestContext = mock { diff --git a/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt b/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt index bb09f26a5..65f72d060 100644 --- a/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt +++ b/emarsys/src/androidTest/java/com/emarsys/config/DefaultConfigInternalTest.kt @@ -602,14 +602,14 @@ class DefaultConfigInternalTest : AnnotationSpec() { } @Test - fun testGetHardwareId_shouldReturnHWIDFromDeviceInfo() { - whenever(mockDeviceInfo.hardwareId).thenReturn("testHardwareId") - val result = configInternal.hardwareId - result shouldBe "testHardwareId" + fun testGetClientId_shouldReturnHWIDFromDeviceInfo() { + whenever(mockDeviceInfo.clientId).thenReturn("testClientId") + val result = configInternal.clientId + result shouldBe "testClientId" } @Test - fun testGetHardwareId_shouldReturnLanguageCodeFromDeviceInfo() { + fun testGetLanguage_shouldReturnLanguageCodeFromDeviceInfo() { whenever(mockDeviceInfo.language).thenReturn("testLanguage") val result = configInternal.language @@ -617,7 +617,7 @@ class DefaultConfigInternalTest : AnnotationSpec() { } @Test - fun testGetHardwareId_shouldReturnNotificationSettingsFromDeviceInfo() { + fun testGetNotificationSettings_shouldReturnNotificationSettingsFromDeviceInfo() { val notificationSettings: NotificationSettings = mock() whenever(mockDeviceInfo.notificationSettings).thenReturn(notificationSettings) val result = configInternal.notificationSettings diff --git a/emarsys/src/androidTest/java/com/emarsys/config/RemoteConfigResponseMapperTest.kt b/emarsys/src/androidTest/java/com/emarsys/config/RemoteConfigResponseMapperTest.kt index 057e9192a..f6f4769a7 100644 --- a/emarsys/src/androidTest/java/com/emarsys/config/RemoteConfigResponseMapperTest.kt +++ b/emarsys/src/androidTest/java/com/emarsys/config/RemoteConfigResponseMapperTest.kt @@ -3,7 +3,7 @@ package com.emarsys.config import com.emarsys.common.feature.InnerFeature import com.emarsys.config.model.RemoteConfig -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.random.RandomProvider import com.emarsys.core.response.ResponseModel import com.emarsys.core.util.log.LogLevel @@ -19,7 +19,7 @@ class RemoteConfigResponseMapperTest : AnnotationSpec() { private lateinit var mockResponseModel: ResponseModel private lateinit var mockRandomProvider: RandomProvider - private lateinit var mockHardwareIdProvider: HardwareIdProvider + private lateinit var mockClientIdProvider: ClientIdProvider private lateinit var remoteConfigResponseMapper: RemoteConfigResponseMapper @@ -27,12 +27,12 @@ class RemoteConfigResponseMapperTest : AnnotationSpec() { fun setup() { mockResponseModel = mock(ResponseModel::class.java) mockRandomProvider = mock(RandomProvider::class.java) - mockHardwareIdProvider = mock { - on { provideHardwareId() } doReturn "testHardwareId" + mockClientIdProvider = mock { + on { provideClientId() } doReturn "testClientId" } remoteConfigResponseMapper = - RemoteConfigResponseMapper(mockRandomProvider, mockHardwareIdProvider) + RemoteConfigResponseMapper(mockRandomProvider, mockClientIdProvider) } @Test @@ -64,7 +64,7 @@ class RemoteConfigResponseMapperTest : AnnotationSpec() { fun testMap_mapsResponseModel_to_RemoteConfig_withHwIdOverride() { whenever(mockRandomProvider.provideDouble(1.0)).thenReturn(0.6) whenever(mockResponseModel.body).thenReturn(fullRemoteConfigJson.trimIndent()) - whenever(mockHardwareIdProvider.provideHardwareId()).thenReturn("hardwareId1") + whenever(mockClientIdProvider.provideClientId()).thenReturn("clientId1") val expected = RemoteConfig( "https://mobile-events-2.eservice.emarsys.net", @@ -284,7 +284,7 @@ class RemoteConfigResponseMapperTest : AnnotationSpec() { "experimentalFeature1":false }, "overrides": { - "hardwareId1": { + "clientId1": { "serviceUrls": { "eventService": "https://mobile-events-2.eservice.emarsys.net" }, @@ -299,7 +299,7 @@ class RemoteConfigResponseMapperTest : AnnotationSpec() { "experimentalFeature1":false } }, - "hardwareId2": { + "clientId2": { "serviceUrls": { "eventService": "https://mobile-events-2.eservice.emarsys.net", "clientService": "https://me-client.eservice.emarsys.net " diff --git a/emarsys/src/androidTest/java/com/emarsys/fake/FakeEmarsysDependencyContainer.kt b/emarsys/src/androidTest/java/com/emarsys/fake/FakeEmarsysDependencyContainer.kt index 95f6d4374..cfacd20e2 100644 --- a/emarsys/src/androidTest/java/com/emarsys/fake/FakeEmarsysDependencyContainer.kt +++ b/emarsys/src/androidTest/java/com/emarsys/fake/FakeEmarsysDependencyContainer.kt @@ -20,7 +20,7 @@ import com.emarsys.core.device.DeviceInfo import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.provider.activity.CurrentActivityProvider -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.RequestManager @@ -137,9 +137,9 @@ class FakeEmarsysDependencyContainer( override val fileDownloader: FileDownloader = mock(), override val keyValueStore: KeyValueStore = mock(), override val sharedPreferences: SharedPreferences = mock(), - override val hardwareIdProvider: HardwareIdProvider = mock(), + override val clientIdProvider: ClientIdProvider = mock(), override val coreDbHelper: CoreDbHelper = mock(), - override val hardwareIdStorage: Storage = mock(), + override val clientIdStorage: Storage = mock(), override val logLevelStorage: Storage = mock(), override val crypto: Crypto = mock(), override val requestManager: RequestManager = mock(), diff --git a/emarsys/src/main/java/com/emarsys/config/ConfigInternal.kt b/emarsys/src/main/java/com/emarsys/config/ConfigInternal.kt index 4f25aefbf..bf6f9c909 100644 --- a/emarsys/src/main/java/com/emarsys/config/ConfigInternal.kt +++ b/emarsys/src/main/java/com/emarsys/config/ConfigInternal.kt @@ -11,7 +11,7 @@ interface ConfigInternal { val merchantId: String? - val hardwareId: String + val clientId: String val language: String diff --git a/emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt b/emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt index 707b97692..dac88b19e 100644 --- a/emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt +++ b/emarsys/src/main/java/com/emarsys/config/DefaultConfigInternal.kt @@ -54,8 +54,8 @@ class DefaultConfigInternal( override val contactFieldId: Int? get() = mobileEngageRequestContext.contactFieldId - override val hardwareId: String - get() = deviceInfo.hardwareId + override val clientId: String + get() = deviceInfo.clientId override val language: String get() = deviceInfo.language diff --git a/emarsys/src/main/java/com/emarsys/config/RemoteConfigResponseMapper.kt b/emarsys/src/main/java/com/emarsys/config/RemoteConfigResponseMapper.kt index 3321d62a3..4a99f27d1 100644 --- a/emarsys/src/main/java/com/emarsys/config/RemoteConfigResponseMapper.kt +++ b/emarsys/src/main/java/com/emarsys/config/RemoteConfigResponseMapper.kt @@ -4,7 +4,7 @@ import com.emarsys.common.feature.InnerFeature import com.emarsys.config.model.RemoteConfig import com.emarsys.core.Mapper import com.emarsys.core.Mockable -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.random.RandomProvider import com.emarsys.core.response.ResponseModel import com.emarsys.core.util.JsonUtils @@ -17,12 +17,13 @@ import com.emarsys.core.util.log.entry.CrashLog import org.json.JSONException import org.json.JSONObject import java.net.URL -import java.util.* +import java.util.Locale @Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") @Mockable class RemoteConfigResponseMapper(private val randomProvider: RandomProvider, - private val hardwareIdProvider: HardwareIdProvider) : Mapper { + private val clientIdProvider: ClientIdProvider +) : Mapper { override fun map(responseModel: ResponseModel): RemoteConfig { var remoteConfig = RemoteConfig() try { @@ -52,7 +53,8 @@ class RemoteConfigResponseMapper(private val randomProvider: RandomProvider, } private fun extractOverrideJson(remoteConfigJson: JSONObject): JSONObject? { - return remoteConfigJson.optJSONObject("overrides")?.optJSONObject(hardwareIdProvider.provideHardwareId()) + return remoteConfigJson.optJSONObject("overrides") + ?.optJSONObject(clientIdProvider.provideClientId()) } private fun mapJsonToRemoteConfig(remoteConfigJson: JSONObject): RemoteConfig { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/DefaultMobileEngageInternalTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/DefaultMobileEngageInternalTest.kt index 56ac3ab49..64628d092 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/DefaultMobileEngageInternalTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/DefaultMobileEngageInternalTest.kt @@ -37,7 +37,7 @@ class DefaultMobileEngageInternalTest : AnnotationSpec() { const val CONTACT_FIELD_ID = 999 const val TIMESTAMP = 123456789L const val REQUEST_ID = "request_id" - const val HARDWARE_ID = "hardware_id" + const val CLIENT_ID = "clientId" const val APPLICATION_CODE = "app_code" const val PUSH_TOKEN = "kjhygtfdrtrtdtguyihoj3iurf8y7t6fqyua2gyi8fhu" const val PLATFORM = "android" @@ -102,7 +102,7 @@ class DefaultMobileEngageInternalTest : AnnotationSpec() { } mockDeviceInfo = mock { - on { hardwareId }.thenReturn(HARDWARE_ID) + on { clientId }.thenReturn(CLIENT_ID) on { platform }.thenReturn(PLATFORM) on { applicationVersion }.thenReturn(APPLICATION_VERSION) on { model }.thenReturn(DEVICE_MODEL) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/fake/FakeMobileEngageDependencyContainer.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/fake/FakeMobileEngageDependencyContainer.kt index c3a1b9605..0c793540f 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/fake/FakeMobileEngageDependencyContainer.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/fake/FakeMobileEngageDependencyContainer.kt @@ -19,7 +19,7 @@ import com.emarsys.core.device.DeviceInfo import com.emarsys.core.endpoint.ServiceEndpointProvider import com.emarsys.core.handler.ConcurrentHandlerHolder import com.emarsys.core.provider.activity.CurrentActivityProvider -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.timestamp.TimestampProvider import com.emarsys.core.provider.uuid.UUIDProvider import com.emarsys.core.request.RequestManager @@ -136,9 +136,9 @@ class FakeMobileEngageDependencyContainer( override val fileDownloader: FileDownloader = mock(), override val keyValueStore: KeyValueStore = mock(), override val sharedPreferences: SharedPreferences = mock(), - override val hardwareIdProvider: HardwareIdProvider = mock(), + override val clientIdProvider: ClientIdProvider = mock(), override val coreDbHelper: CoreDbHelper = mock(), - override val hardwareIdStorage: Storage = mock(), + override val clientIdStorage: Storage = mock(), override val logLevelStorage: Storage = mock(), override val crypto: Crypto = mock(), override val requestManager: RequestManager = mock(), diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/requestRepositoryProxy/RequestRepositoryProxyTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/requestRepositoryProxy/RequestRepositoryProxyTest.kt index 0b314dc34..0e2ef8981 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/requestRepositoryProxy/RequestRepositoryProxyTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/iam/model/requestRepositoryProxy/RequestRepositoryProxyTest.kt @@ -439,7 +439,7 @@ class RequestRepositoryProxyTest : AnnotationSpec() { payload["clicks"] = ArrayList() payload["viewed_messages"] = ArrayList() payload["events"] = listOf>(event) - payload["hardware_id"] = "dummy_hardware_id" + val headers: MutableMap = HashMap() headers["custom_event_header1"] = "custom_event_value1" headers["custom_event_header2"] = "custom_event_value2" diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/MobileEngageRequestModelFactoryTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/MobileEngageRequestModelFactoryTest.kt index 9179e6eba..4c79273ed 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/MobileEngageRequestModelFactoryTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/MobileEngageRequestModelFactoryTest.kt @@ -27,7 +27,7 @@ class MobileEngageRequestModelFactoryTest : AnnotationSpec() { private companion object { const val TIMESTAMP = 123456789L const val REQUEST_ID = "request_id" - const val HARDWARE_ID = "hardware_id" + const val CLIENT_ID = "clientId" const val APPLICATION_CODE = "app_code" const val PUSH_TOKEN = "kjhygtfdrtrtdtguyihoj3iurf8y7t6fqyua2gyi8fhu" const val REFRESH_TOKEN = @@ -77,7 +77,7 @@ class MobileEngageRequestModelFactoryTest : AnnotationSpec() { on { provideTimestamp() } doReturn TIMESTAMP } mockDeviceInfo = mock { - on { hardwareId } doReturn HARDWARE_ID + on { clientId } doReturn CLIENT_ID on { isDebugMode } doReturn true on { notificationSettings } doReturn mockNotificationSettings } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/ContactTokenHeaderMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/ContactTokenHeaderMapperTest.kt index 557510880..101430339 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/ContactTokenHeaderMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/ContactTokenHeaderMapperTest.kt @@ -25,7 +25,7 @@ class ContactTokenHeaderMapperTest : AnnotationSpec() { const val REFRESH_TOKEN = "refreshToken" const val TIMESTAMP = 123456789L const val REQUEST_ID = "request_id" - const val HARDWARE_ID = "hwid" + const val CLIENT_ID = "clientId" const val APPLICATION_CODE = "applicationCode" } @@ -50,7 +50,7 @@ class ContactTokenHeaderMapperTest : AnnotationSpec() { } mockDeviceInfo = mock { - on { hardwareId } doReturn HARDWARE_ID + on { clientId } doReturn CLIENT_ID } mockUuidProvider = mock { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DefaultRequestHeaderMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DefaultRequestHeaderMapperTest.kt index ad737ebe0..6ad9cc35e 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DefaultRequestHeaderMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DefaultRequestHeaderMapperTest.kt @@ -17,7 +17,7 @@ class DefaultRequestHeaderMapperTest : AnnotationSpec() { private companion object { const val TIMESTAMP = 234123L const val REQUEST_ID = "request_id" - const val HARDWARE_ID = "hwid" + const val CLIENT_ID = "hwid" const val APPLICATION_CODE = "applicationCode" const val SDK_VERSION = "sdkVersion" } @@ -31,7 +31,7 @@ class DefaultRequestHeaderMapperTest : AnnotationSpec() { @Suppress("UNCHECKED_CAST") fun setUp() { mockDeviceInfo = mock { - on { hardwareId } doReturn HARDWARE_ID + on { clientId } doReturn CLIENT_ID on { sdkVersion } doReturn SDK_VERSION on { isDebugMode } doReturn true } diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DeviceEventStateRequestMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DeviceEventStateRequestMapperTest.kt index a58fcf4b0..5baf9f6e3 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DeviceEventStateRequestMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/DeviceEventStateRequestMapperTest.kt @@ -35,7 +35,7 @@ class DeviceEventStateRequestMapperTest : AnnotationSpec() { fun setUp() { FeatureRegistry.enableFeature(InnerFeature.EVENT_SERVICE_V4) val mockDeviceInfo: DeviceInfo = mock { - on { hardwareId } doReturn "TEST_HARDWARE_ID" + on { clientId } doReturn "TEST_CLIENT_ID" } mockRequestContext = mock { on { deviceInfo } doReturn mockDeviceInfo diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapperTest.kt index 931c52e1f..b1fb802f2 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapperTest.kt @@ -24,7 +24,7 @@ MobileEngageHeaderMapperTest : AnnotationSpec() { const val CLIENT_STATE = "client-state" const val TIMESTAMP = 123456789L const val REQUEST_ID = "request_id" - const val HARDWARE_ID = "hwid" + const val CLIENT_ID = "hwid" const val APPLICATION_CODE = "applicationCode" } @@ -45,7 +45,7 @@ MobileEngageHeaderMapperTest : AnnotationSpec() { } mockDeviceInfo = mock { - on { hardwareId } doReturn HARDWARE_ID + on { clientId } doReturn CLIENT_ID } mockUuidProvider = mock { @@ -75,7 +75,7 @@ MobileEngageHeaderMapperTest : AnnotationSpec() { val expectedRequestModels = createMobileEngageRequest(extraHeaders = mapOf( "X-Client-State" to CLIENT_STATE, - "X-Client-Id" to HARDWARE_ID, + "X-Client-Id" to CLIENT_ID, "X-Request-Order" to TIMESTAMP.toString() )) @@ -91,7 +91,7 @@ MobileEngageHeaderMapperTest : AnnotationSpec() { val expectedRequestModels = createCustomEventCompositeRequest(extraHeaders = mapOf( "X-Client-State" to CLIENT_STATE, - "X-Client-Id" to HARDWARE_ID, + "X-Client-Id" to CLIENT_ID, "X-Request-Order" to TIMESTAMP.toString() )) @@ -104,7 +104,7 @@ MobileEngageHeaderMapperTest : AnnotationSpec() { fun testMap_shouldLeaveOutClientStateHeader_whenValueIsMissing() { val originalRequestModels = createMobileEngageRequest(extraHeaders = mapOf( "X-Request-Order" to TIMESTAMP.toString(), - "X-Client-Id" to HARDWARE_ID, + "X-Client-Id" to CLIENT_ID, )) whenever(mockClientStateStorage.get()).thenReturn(null) diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/OpenIdTokenRequestMapperTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/OpenIdTokenRequestMapperTest.kt index 1049cd843..670382e73 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/OpenIdTokenRequestMapperTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/request/mapper/OpenIdTokenRequestMapperTest.kt @@ -21,7 +21,7 @@ class OpenIdTokenRequestMapperTest : AnnotationSpec() { const val OPEN_ID_TOKEN = "openIdToken" const val TIMESTAMP = 123456789L const val REQUEST_ID = "request_id" - const val HARDWARE_ID = "hwid" + const val CLIENT_ID = "hwid" const val APPLICATION_CODE = "applicationCode" } @@ -36,7 +36,7 @@ class OpenIdTokenRequestMapperTest : AnnotationSpec() { @Before fun setUp() { mockDeviceInfo = mock { - on { hardwareId } doReturn HARDWARE_ID + on { clientId } doReturn CLIENT_ID } mockUuidProvider = mock { diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/MessagingServiceUtilsTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/MessagingServiceUtilsTest.kt index d6f8958a6..0f8094fcd 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/MessagingServiceUtilsTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/service/MessagingServiceUtilsTest.kt @@ -15,7 +15,7 @@ import com.emarsys.core.api.notification.ChannelSettings import com.emarsys.core.api.notification.NotificationSettings import com.emarsys.core.device.DeviceInfo import com.emarsys.core.device.LanguageProvider -import com.emarsys.core.provider.hardwareid.HardwareIdProvider +import com.emarsys.core.provider.clientid.ClientIdProvider import com.emarsys.core.provider.version.VersionProvider import com.emarsys.core.util.FileDownloader import com.emarsys.mobileengage.di.mobileEngage @@ -50,7 +50,7 @@ class MessagingServiceUtilsTest : AnnotationSpec() { const val TITLE = "title" const val BODY = "body" const val CHANNEL_ID = "channelId" - const val HARDWARE_ID = "hwid" + const val CLIENT_ID = "hwid" const val SDK_VERSION = "sdkVersion" const val LANGUAGE = "en-US" const val IMAGE_URL = "https://emarsys.com/image" @@ -97,7 +97,7 @@ class MessagingServiceUtilsTest : AnnotationSpec() { fun init() { context = getTargetContext() val mockNotificationSettings: NotificationSettings = mock() - val mockHardwareIdProvider: HardwareIdProvider = mock() + val mockClientIdProvider: ClientIdProvider = mock() val mockVersionProvider: VersionProvider = mock() val mockLanguageProvider: LanguageProvider = mock() val channelSettings = ChannelSettings(channelId = CHANNEL_ID) @@ -124,7 +124,7 @@ class MessagingServiceUtilsTest : AnnotationSpec() { mockSilentNotificationInformationListenerProvider = mock() whenever(mockNotificationSettings.channelSettings).thenReturn(listOf(channelSettings)) - whenever(mockHardwareIdProvider.provideHardwareId()).thenReturn(HARDWARE_ID) + whenever(mockClientIdProvider.provideClientId()).thenReturn(CLIENT_ID) whenever( mockLanguageProvider.provideLanguage( ArgumentMatchers.any( @@ -136,7 +136,7 @@ class MessagingServiceUtilsTest : AnnotationSpec() { whenever(mockVersionProvider.provideSdkVersion()).thenReturn(SDK_VERSION) deviceInfo = DeviceInfo( context, - mockHardwareIdProvider, + mockClientIdProvider, mockVersionProvider, mockLanguageProvider, mockNotificationSettings, diff --git a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestPayloadUtilsTest.kt b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestPayloadUtilsTest.kt index aaa5d63c9..a99a50f31 100644 --- a/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestPayloadUtilsTest.kt +++ b/mobile-engage/src/androidTest/java/com/emarsys/mobileengage/util/RequestPayloadUtilsTest.kt @@ -25,7 +25,7 @@ class RequestPayloadUtilsTest : AnnotationSpec() { private companion object { const val PUSH_TOKEN = "pushToken" const val APPLICATION_CODE = "applicationCode" - const val HARDWARE_ID = "hardwareId" + const val CLIENT_ID = "clientId" const val PLATFORM = "android" const val APPLICATION_VERSION = "1.0.2" const val DEVICE_MODEL = "GT-9100" @@ -86,7 +86,7 @@ class RequestPayloadUtilsTest : AnnotationSpec() { on { sdkVersion } doReturn SDK_VERSION on { language } doReturn LANGUAGE on { timezone } doReturn TIMEZONE - on { hardwareId } doReturn HARDWARE_ID + on { clientId } doReturn CLIENT_ID on { notificationSettings } doReturn mockNotificationSettings } diff --git a/mobile-engage/src/main/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapper.kt b/mobile-engage/src/main/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapper.kt index a25f110f7..c563cc20c 100644 --- a/mobile-engage/src/main/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapper.kt +++ b/mobile-engage/src/main/java/com/emarsys/mobileengage/request/mapper/MobileEngageHeaderMapper.kt @@ -14,7 +14,7 @@ class MobileEngageHeaderMapper(override val requestContext: MobileEngageRequestC updatedHeaders["X-Client-State"] = it } updatedHeaders["X-Request-Order"] = requestContext.timestampProvider.provideTimestamp().toString() - updatedHeaders["X-Client-Id"] = requestContext.deviceInfo.hardwareId + updatedHeaders["X-Client-Id"] = requestContext.deviceInfo.clientId return updatedHeaders } diff --git a/predict/src/androidTest/java/com/emarsys/predict/request/PredictRequestModelBuilderTest.kt b/predict/src/androidTest/java/com/emarsys/predict/request/PredictRequestModelBuilderTest.kt index fd19609ff..78822caef 100644 --- a/predict/src/androidTest/java/com/emarsys/predict/request/PredictRequestModelBuilderTest.kt +++ b/predict/src/androidTest/java/com/emarsys/predict/request/PredictRequestModelBuilderTest.kt @@ -30,7 +30,7 @@ class PredictRequestModelBuilderTest : AnnotationSpec() { private companion object { const val TIMESTAMP = 123456789L const val REQUEST_ID = "request_id" - const val HARDWARE_ID = "hardware_id" + const val CLIENT_ID = "clientId" const val MERCHANT_ID = "merchantId" const val OS_VERSION = "1.0.0" const val PLATFORM = "android" @@ -77,7 +77,7 @@ class PredictRequestModelBuilderTest : AnnotationSpec() { whenever(provideTimestamp()).thenReturn(TIMESTAMP) } mockDeviceInfo = mock(DeviceInfo::class.java).apply { - whenever(hardwareId).thenReturn(HARDWARE_ID) + whenever(clientId).thenReturn(CLIENT_ID) } mockRequestContext = mock(PredictRequestContext::class.java).apply { diff --git a/sample/src/main/kotlin/com/emarsys/sample/SampleApplication.kt b/sample/src/main/kotlin/com/emarsys/sample/SampleApplication.kt index 3a09df480..7146fa6f1 100644 --- a/sample/src/main/kotlin/com/emarsys/sample/SampleApplication.kt +++ b/sample/src/main/kotlin/com/emarsys/sample/SampleApplication.kt @@ -35,7 +35,7 @@ class SampleApplication : Application(), EventHandler, NotificationInformationLi Emarsys.setup(config) Prefs.loggedIn = false - Prefs.hardwareId = Emarsys.config.hardwareId + Prefs.clientId = Emarsys.config.clientId Prefs.languageCode = Emarsys.config.languageCode Prefs.sdkVersion = Emarsys.config.sdkVersion createNotificationChannels() diff --git a/sample/src/main/kotlin/com/emarsys/sample/dashboard/DashboardViewModel.kt b/sample/src/main/kotlin/com/emarsys/sample/dashboard/DashboardViewModel.kt index 5c74c734b..d87da3907 100644 --- a/sample/src/main/kotlin/com/emarsys/sample/dashboard/DashboardViewModel.kt +++ b/sample/src/main/kotlin/com/emarsys/sample/dashboard/DashboardViewModel.kt @@ -90,7 +90,7 @@ class DashboardViewModel : ViewModel() { "loggedIn" to isLoggedIn.value.toString(), "applicationCode" to tfAppCode.value, "merchantId" to tfMerchantId.value, - "hardwareId" to Prefs.hardwareId, + "clientId" to Prefs.clientId, "languageCode" to Prefs.languageCode, "sdkVersion" to Prefs.sdkVersion, "contactFieldValue" to tfContactFieldValue.value, diff --git a/sample/src/main/kotlin/com/emarsys/sample/pref/Prefs.kt b/sample/src/main/kotlin/com/emarsys/sample/pref/Prefs.kt index c1b4c765e..2098c1d4d 100644 --- a/sample/src/main/kotlin/com/emarsys/sample/pref/Prefs.kt +++ b/sample/src/main/kotlin/com/emarsys/sample/pref/Prefs.kt @@ -7,7 +7,7 @@ object Prefs : KotprefModel() { var sdkVersion by stringPref("") var languageCode by stringPref("") - var hardwareId by stringPref("") + var clientId by stringPref("") var applicationCode by stringPref("") var merchantId by stringPref("") var contactFieldValue by stringPref("") @@ -18,7 +18,7 @@ object Prefs : KotprefModel() { fun Prefs.update(sdkInfo: Map) { sdkVersion = sdkInfo.getOrDefault("sdkVersion", "") languageCode = sdkInfo.getOrDefault("languageCode", "") - hardwareId = sdkInfo.getOrDefault("hardwareId", "") + clientId = sdkInfo.getOrDefault("clientId", "") applicationCode = sdkInfo.getOrDefault("applicationCode", "") merchantId = sdkInfo.getOrDefault("merchantId", "") contactFieldValue = sdkInfo.getOrDefault("contactFieldValue", "")