From 80f504b8ec36b4434a45df37ecced8d5673fd5a5 Mon Sep 17 00:00:00 2001 From: Nikita Ogorodnikov Date: Mon, 5 Dec 2022 11:52:14 +0100 Subject: [PATCH] RUMM-2781: Remove duplication of UserInfo and NetworkInfo classes --- dd-sdk-android/apiSurface | 36 +--- dd-sdk-android/build.gradle.kts | 2 - .../generate_core_models.gradle.kts | 20 --- .../src/main/json/core/network_info.json | 54 ------ .../src/main/json/core/user_info.json | 24 --- .../kotlin/com/datadog/android/Datadog.kt | 4 +- .../android/core/internal/CoreFeature.kt | 8 +- .../data/upload/DataUploadRunnable.kt | 2 +- .../lifecycle/ProcessLifecycleCallback.kt | 2 +- .../BroadcastReceiverNetworkInfoProvider.kt | 2 +- .../net/info/CallbackNetworkInfoProvider.kt | 2 +- .../net/info/NetworkInfoDeserializer.kt | 2 +- .../internal/net/info/NetworkInfoProvider.kt | 2 +- .../net/info/NetworkInfoSerializer.kt | 2 +- .../internal/user/DatadogUserInfoProvider.kt | 9 +- .../internal/user/MutableUserInfoProvider.kt | 4 +- .../internal/user/UserInfoDeserializer.kt | 4 +- .../internal/user/UserInfoProvider.kt | 4 +- .../internal/user/UserInfoSerializer.kt | 7 +- .../core/internal/utils/UserInfoExt.kt | 14 -- .../android/log/internal/LogsFeature.kt | 4 +- .../internal/domain/DatadogLogGenerator.kt | 59 ++----- .../log/internal/domain/LogGenerator.kt | 4 +- .../internal/domain/scope/RumActionScope.kt | 1 - .../internal/domain/scope/RumResourceScope.kt | 1 - .../rum/internal/domain/scope/RumViewScope.kt | 1 - .../internal/ndk/DatadogNdkCrashHandler.kt | 4 +- .../internal/ndk/NdkNetworkInfoDataWriter.kt | 2 +- .../rum/internal/ndk/NdkUserInfoDataWriter.kt | 4 +- .../com/datadog/android/v2/api/SdkCore.kt | 2 +- .../android/v2/api/context/NetworkInfo.kt | 157 +++++++++++++++--- .../android/v2/api/context/UserInfo.kt | 103 +++++++++++- .../datadog/android/v2/core/DatadogCore.kt | 2 +- .../datadog/android/v2/core/NoOpSdkCore.kt | 2 +- .../core/internal/DatadogContextProvider.kt | 46 +---- .../data/upload/DataUploadRunnable.kt | 2 +- .../kotlin/com/datadog/android/DatadogTest.kt | 2 +- .../android/core/internal/CoreFeatureTest.kt | 7 +- .../data/upload/DataUploadRunnableTest.kt | 2 +- .../lifecycle/ProcessLifecycleCallbackTest.kt | 2 +- ...roadcastReceiverNetworkInfoProviderTest.kt | 2 +- .../info/CallbackNetworkInfoProviderTest.kt | 2 +- .../net/info/NetworkInfoDeserializerTest.kt | 2 +- .../net/info/NetworkInfoSerializerTest.kt | 2 +- .../user/DatadogUserInfoProviderTest.kt | 4 +- .../internal/user/UserInfoDeserializerTest.kt | 4 +- .../internal/user/UserInfoSerializerTest.kt | 4 +- .../android/log/assertj/LogEventAssert.kt | 78 +-------- .../android/log/assertj/NetworkInfoAssert.kt | 2 +- .../android/log/internal/LogsFeatureTest.kt | 4 +- .../domain/DatadogLogGeneratorTest.kt | 4 +- .../domain/event/RumEventSerializerTest.kt | 2 +- .../ndk/DatadogNdkCrashHandlerTest.kt | 17 +- .../config/CoreFeatureTestConfiguration.kt | 2 +- .../android/utils/forge/Configurator.kt | 2 - .../utils/forge/CredentialsForgeryFactory.kt | 2 +- .../utils/forge/LogEventForgeryFactory.kt | 6 +- .../utils/forge/NetworkInfoForgeryFactory.kt | 2 +- .../forge/NetworkInfoV2ForgeryFactory.kt | 30 ---- .../utils/forge/SpanEventForgeryFactory.kt | 6 +- .../utils/forge/UserInfoForgeryFactory.kt | 2 +- .../utils/forge/UserInfoV2ForgeryFactory.kt | 22 --- .../api/context}/NetworkInfoTest.kt | 2 +- .../model => v2/api/context}/UserInfoTest.kt | 2 +- .../android/v2/core/DatadogCoreTest.kt | 4 +- .../internal/DatadogContextProviderTest.kt | 4 +- .../data/upload/DataUploadRunnableTest.kt | 2 +- detekt.yml | 2 + 68 files changed, 344 insertions(+), 484 deletions(-) delete mode 100644 dd-sdk-android/generate_core_models.gradle.kts delete mode 100644 dd-sdk-android/src/main/json/core/network_info.json delete mode 100644 dd-sdk-android/src/main/json/core/user_info.json rename dd-sdk-android/src/main/kotlin/com/datadog/android/{log => core}/internal/user/DatadogUserInfoProvider.kt (78%) rename dd-sdk-android/src/main/kotlin/com/datadog/android/{log => core}/internal/user/MutableUserInfoProvider.kt (83%) rename dd-sdk-android/src/main/kotlin/com/datadog/android/{log => core}/internal/user/UserInfoDeserializer.kt (91%) rename dd-sdk-android/src/main/kotlin/com/datadog/android/{log => core}/internal/user/UserInfoProvider.kt (80%) rename dd-sdk-android/src/main/kotlin/com/datadog/android/{log => core}/internal/user/UserInfoSerializer.kt (73%) delete mode 100644 dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/utils/UserInfoExt.kt rename dd-sdk-android/src/test/kotlin/com/datadog/android/{log => core}/internal/user/DatadogUserInfoProviderTest.kt (97%) rename dd-sdk-android/src/test/kotlin/com/datadog/android/{log => core}/internal/user/UserInfoDeserializerTest.kt (95%) rename dd-sdk-android/src/test/kotlin/com/datadog/android/{log => core}/internal/user/UserInfoSerializerTest.kt (93%) delete mode 100644 dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/NetworkInfoV2ForgeryFactory.kt delete mode 100644 dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/UserInfoV2ForgeryFactory.kt rename dd-sdk-android/src/test/kotlin/com/datadog/android/{core/model => v2/api/context}/NetworkInfoTest.kt (96%) rename dd-sdk-android/src/test/kotlin/com/datadog/android/{core/model => v2/api/context}/UserInfoTest.kt (96%) diff --git a/dd-sdk-android/apiSurface b/dd-sdk-android/apiSurface index f9b78e0fad..109c3ee049 100644 --- a/dd-sdk-android/apiSurface +++ b/dd-sdk-android/apiSurface @@ -135,35 +135,6 @@ enum com.datadog.android.core.configuration.VitalsUpdateFrequency - AVERAGE - RARE - NEVER -data class com.datadog.android.core.model.NetworkInfo - constructor(Connectivity = Connectivity.NETWORK_NOT_CONNECTED, kotlin.String? = null, kotlin.Long? = null, kotlin.Long? = null, kotlin.Long? = null, kotlin.Long? = null, kotlin.String? = null) - fun toJson(): com.google.gson.JsonElement - companion object - fun fromJson(kotlin.String): NetworkInfo - fun fromJsonObject(com.google.gson.JsonObject): NetworkInfo - enum Connectivity - constructor(kotlin.String) - - NETWORK_NOT_CONNECTED - - NETWORK_ETHERNET - - NETWORK_WIFI - - NETWORK_WIMAX - - NETWORK_BLUETOOTH - - NETWORK_2G - - NETWORK_3G - - NETWORK_4G - - NETWORK_5G - - NETWORK_MOBILE_OTHER - - NETWORK_CELLULAR - - NETWORK_OTHER - fun toJson(): com.google.gson.JsonElement - companion object - fun fromJson(kotlin.String): Connectivity -data class com.datadog.android.core.model.UserInfo - constructor(kotlin.String? = null, kotlin.String? = null, kotlin.String? = null, kotlin.collections.MutableMap = mutableMapOf()) - fun toJson(): com.google.gson.JsonElement - companion object - fun fromJson(kotlin.String): UserInfo - fun fromJsonObject(com.google.gson.JsonObject): UserInfo interface com.datadog.android.event.EventMapper fun map(T): T? interface com.datadog.android.event.SpanEventMapper : EventMapper @@ -2027,7 +1998,7 @@ interface com.datadog.android.v2.api.SdkCore fun setVerbosity(Int) fun getVerbosity(): Int fun setTrackingConsent(com.datadog.android.privacy.TrackingConsent) - fun setUserInfo(com.datadog.android.core.model.UserInfo) + fun setUserInfo(com.datadog.android.v2.api.context.UserInfo) fun addUserProperties(Map) fun stop() fun clearAllData() @@ -2049,8 +2020,9 @@ enum com.datadog.android.v2.api.context.DeviceType - DESKTOP - OTHER data class com.datadog.android.v2.api.context.NetworkInfo - constructor(Connectivity, String?, Long?, Long?, Long?, Long?, String?) + constructor(Connectivity = Connectivity.NETWORK_NOT_CONNECTED, kotlin.String? = null, kotlin.Long? = null, kotlin.Long? = null, kotlin.Long? = null, kotlin.Long? = null, kotlin.String? = null) enum Connectivity + constructor(kotlin.String) - NETWORK_NOT_CONNECTED - NETWORK_ETHERNET - NETWORK_WIFI @@ -2068,7 +2040,7 @@ data class com.datadog.android.v2.api.context.ProcessInfo data class com.datadog.android.v2.api.context.TimeInfo constructor(Long, Long, Long, Long) data class com.datadog.android.v2.api.context.UserInfo - constructor(String?, String?, String?, Map) + constructor(kotlin.String? = null, kotlin.String? = null, kotlin.String? = null, Map = emptyMap()) class com.datadog.android.webview.DatadogEventBridge constructor() constructor(List) diff --git a/dd-sdk-android/build.gradle.kts b/dd-sdk-android/build.gradle.kts index 6de47f1f9f..c8e5b51b9a 100644 --- a/dd-sdk-android/build.gradle.kts +++ b/dd-sdk-android/build.gradle.kts @@ -178,7 +178,6 @@ apply(from = "clone_rum_schema.gradle.kts") apply(from = "clone_telemetry_schema.gradle.kts") apply(from = "generate_rum_models.gradle.kts") apply(from = "generate_telemetry_models.gradle.kts") -apply(from = "generate_core_models.gradle.kts") apply(from = "generate_trace_models.gradle.kts") apply(from = "generate_log_models.gradle.kts") @@ -187,7 +186,6 @@ detektConfig( excludes = listOf( "**/com/datadog/android/rum/model/**", "**/com/datadog/android/telemetry/model/**", - "**/com/datadog/android/core/model/**", "**/com/datadog/android/tracing/model/**", "**/com/datadog/android/log/model/**" ) diff --git a/dd-sdk-android/generate_core_models.gradle.kts b/dd-sdk-android/generate_core_models.gradle.kts deleted file mode 100644 index 9a875ac7ad..0000000000 --- a/dd-sdk-android/generate_core_models.gradle.kts +++ /dev/null @@ -1,20 +0,0 @@ -import com.datadog.gradle.plugin.apisurface.ApiSurfacePlugin -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -val generateCoreModelsTaskName = "generateCoreModelsFromJson" - -tasks.register( - generateCoreModelsTaskName, - com.datadog.gradle.plugin.jsonschema.GenerateJsonSchemaTask::class.java -) { - inputDirPath = "src/main/json/core" - targetPackageName = "com.datadog.android.core.model" -} - -afterEvaluate { - tasks.findByName(ApiSurfacePlugin.TASK_GEN_API_SURFACE) - ?.dependsOn(generateCoreModelsTaskName) - tasks.withType(KotlinCompile::class.java).configureEach { - dependsOn(generateCoreModelsTaskName) - } -} diff --git a/dd-sdk-android/src/main/json/core/network_info.json b/dd-sdk-android/src/main/json/core/network_info.json deleted file mode 100644 index 6648cff298..0000000000 --- a/dd-sdk-android/src/main/json/core/network_info.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "NetworkInfo", - "type": "object", - "description": "Structure holding information about the available network when an event was tracked.", - "properties": { - "connectivity": { - "type": "string", - "enum": [ - "network_not_connected", - "network_ethernet", - "network_wifi", - "network_wimax", - "network_bluetooth", - "network_2G", - "network_3G", - "network_4G", - "network_5G", - "network_mobile_other", - "network_cellular", - "network_other" - ], - "default": "network_not_connected", - "description": "the type of network connectivity" - }, - "carrier_name": { - "type": "string", - "description": "the name of the mobile data carrier" - }, - "carrier_id": { - "type": "integer", - "description": "the unique id of the mobile data carrier" - }, - "up_kbps": { - "type": "integer", - "description": "the upload speed in kilobytes per second" - }, - "down_kbps": { - "type": "integer", - "description": "the download speed in kilobytes per second" - }, - "strength": { - "type": "integer", - "description": "the strength of the signal (the unit depends on the type of the signal)" - }, - "cellular_technology": { - "type": "string", - "description": "the type of cellular technology if known (e.g.: GPRS, LTE, 5G)" - } - }, - "required": [ - "connectivity" - ] -} diff --git a/dd-sdk-android/src/main/json/core/user_info.json b/dd-sdk-android/src/main/json/core/user_info.json deleted file mode 100644 index bcd71014e6..0000000000 --- a/dd-sdk-android/src/main/json/core/user_info.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "UserInfo", - "type": "object", - "description": "Structure holding information about the current user.", - "properties": { - "id": { - "type": "string", - "description": "a (unique) user identifier" - }, - "name": { - "type": "string", - "description": "the user name or alias" - }, - "email": { - "type": "string", - "description": "the user email" - } - }, - "additionalProperties": { - "type": "object", - "description": "additional custom user properties" - } -} diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/Datadog.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/Datadog.kt index 769a9ae10d..0be2af4fe6 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/Datadog.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/Datadog.kt @@ -11,11 +11,11 @@ import com.datadog.android.core.configuration.Configuration import com.datadog.android.core.configuration.Credentials import com.datadog.android.core.internal.utils.devLogger import com.datadog.android.core.internal.utils.telemetry -import com.datadog.android.core.model.UserInfo import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.GlobalRum import com.datadog.android.rum.internal.monitor.DatadogRumMonitor import com.datadog.android.v2.api.SdkCore +import com.datadog.android.v2.api.context.UserInfo import com.datadog.android.v2.core.DatadogCore import com.datadog.android.v2.core.NoOpSdkCore import com.datadog.android.v2.core.internal.HashGenerator @@ -173,7 +173,7 @@ object Datadog { id, name, email, - extraInfo.toMutableMap() + extraInfo ) ) } diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/CoreFeature.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/CoreFeature.kt index 6b6992036e..50dbe6f7b7 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/CoreFeature.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/CoreFeature.kt @@ -51,12 +51,12 @@ import com.datadog.android.core.internal.time.KronosTimeProvider import com.datadog.android.core.internal.time.LoggingSyncListener import com.datadog.android.core.internal.time.NoOpTimeProvider import com.datadog.android.core.internal.time.TimeProvider +import com.datadog.android.core.internal.user.DatadogUserInfoProvider +import com.datadog.android.core.internal.user.MutableUserInfoProvider +import com.datadog.android.core.internal.user.NoOpMutableUserInfoProvider +import com.datadog.android.core.internal.user.UserInfoDeserializer import com.datadog.android.core.internal.utils.devLogger import com.datadog.android.core.internal.utils.sdkLogger -import com.datadog.android.log.internal.user.DatadogUserInfoProvider -import com.datadog.android.log.internal.user.MutableUserInfoProvider -import com.datadog.android.log.internal.user.NoOpMutableUserInfoProvider -import com.datadog.android.log.internal.user.UserInfoDeserializer import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.internal.domain.event.RumEventDeserializer import com.datadog.android.rum.internal.ndk.DatadogNdkCrashHandler diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnable.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnable.kt index 0f8bf09ff8..d1044b7400 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnable.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnable.kt @@ -14,7 +14,7 @@ import com.datadog.android.core.internal.persistence.Batch import com.datadog.android.core.internal.persistence.DataReader import com.datadog.android.core.internal.system.SystemInfoProvider import com.datadog.android.core.internal.utils.scheduleSafe -import com.datadog.android.core.model.NetworkInfo +import com.datadog.android.v2.api.context.NetworkInfo import java.util.concurrent.ScheduledThreadPoolExecutor import java.util.concurrent.TimeUnit import kotlin.math.max diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallback.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallback.kt index 17b650c916..c0ed2e0ffa 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallback.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallback.kt @@ -11,7 +11,7 @@ import com.datadog.android.core.internal.net.info.NetworkInfoProvider import com.datadog.android.core.internal.utils.cancelUploadWorker import com.datadog.android.core.internal.utils.isWorkManagerInitialized import com.datadog.android.core.internal.utils.triggerUploadWorker -import com.datadog.android.core.model.NetworkInfo +import com.datadog.android.v2.api.context.NetworkInfo import java.lang.ref.Reference import java.lang.ref.WeakReference diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/BroadcastReceiverNetworkInfoProvider.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/BroadcastReceiverNetworkInfoProvider.kt index 5450d02579..a9ffd552f6 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/BroadcastReceiverNetworkInfoProvider.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/BroadcastReceiverNetworkInfoProvider.kt @@ -19,7 +19,7 @@ import com.datadog.android.core.internal.persistence.DataWriter import com.datadog.android.core.internal.receiver.ThreadSafeReceiver import com.datadog.android.core.internal.system.BuildSdkVersionProvider import com.datadog.android.core.internal.system.DefaultBuildSdkVersionProvider -import com.datadog.android.core.model.NetworkInfo +import com.datadog.android.v2.api.context.NetworkInfo import android.net.NetworkInfo as AndroidNetworkInfo @Suppress("DEPRECATION") diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/CallbackNetworkInfoProvider.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/CallbackNetworkInfoProvider.kt index 941b4cb4de..d47fc8ea6f 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/CallbackNetworkInfoProvider.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/CallbackNetworkInfoProvider.kt @@ -17,7 +17,7 @@ import com.datadog.android.core.internal.persistence.DataWriter import com.datadog.android.core.internal.system.BuildSdkVersionProvider import com.datadog.android.core.internal.system.DefaultBuildSdkVersionProvider import com.datadog.android.core.internal.utils.devLogger -import com.datadog.android.core.model.NetworkInfo +import com.datadog.android.v2.api.context.NetworkInfo @TargetApi(Build.VERSION_CODES.N) internal class CallbackNetworkInfoProvider( diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoDeserializer.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoDeserializer.kt index 1c491b413a..44a03e285e 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoDeserializer.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoDeserializer.kt @@ -7,9 +7,9 @@ package com.datadog.android.core.internal.net.info import com.datadog.android.core.internal.persistence.Deserializer -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.log.Logger import com.datadog.android.log.internal.utils.errorWithTelemetry +import com.datadog.android.v2.api.context.NetworkInfo import com.google.gson.JsonParseException import java.util.Locale diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoProvider.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoProvider.kt index 8a2919231d..a4eb85798c 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoProvider.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoProvider.kt @@ -7,7 +7,7 @@ package com.datadog.android.core.internal.net.info import android.content.Context -import com.datadog.android.core.model.NetworkInfo +import com.datadog.android.v2.api.context.NetworkInfo import com.datadog.tools.annotation.NoOpImplementation @NoOpImplementation diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoSerializer.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoSerializer.kt index dc59c9f8ea..50eaa38c4c 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoSerializer.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoSerializer.kt @@ -7,7 +7,7 @@ package com.datadog.android.core.internal.net.info import com.datadog.android.core.internal.persistence.Serializer -import com.datadog.android.core.model.NetworkInfo +import com.datadog.android.v2.api.context.NetworkInfo internal class NetworkInfoSerializer : Serializer { diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/DatadogUserInfoProvider.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/DatadogUserInfoProvider.kt similarity index 78% rename from dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/DatadogUserInfoProvider.kt rename to dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/DatadogUserInfoProvider.kt index d063ede812..02ab1e9c2c 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/DatadogUserInfoProvider.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/DatadogUserInfoProvider.kt @@ -4,10 +4,10 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.log.internal.user +package com.datadog.android.core.internal.user import com.datadog.android.core.internal.persistence.DataWriter -import com.datadog.android.core.model.UserInfo +import com.datadog.android.v2.api.context.UserInfo internal class DatadogUserInfoProvider( internal val dataWriter: DataWriter @@ -25,8 +25,9 @@ internal class DatadogUserInfoProvider( } override fun addUserProperties(properties: Map) { - internalUserInfo.additionalProperties - .putAll(properties) + internalUserInfo = internalUserInfo.copy( + additionalProperties = internalUserInfo.additionalProperties + properties + ) } override fun getUserInfo(): UserInfo { diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/MutableUserInfoProvider.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/MutableUserInfoProvider.kt similarity index 83% rename from dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/MutableUserInfoProvider.kt rename to dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/MutableUserInfoProvider.kt index a2457a249e..5e6524d7a3 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/MutableUserInfoProvider.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/MutableUserInfoProvider.kt @@ -4,9 +4,9 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.log.internal.user +package com.datadog.android.core.internal.user -import com.datadog.android.core.model.UserInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.tools.annotation.NoOpImplementation @NoOpImplementation diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoDeserializer.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoDeserializer.kt similarity index 91% rename from dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoDeserializer.kt rename to dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoDeserializer.kt index 7258d432da..06e2758f16 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoDeserializer.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoDeserializer.kt @@ -4,12 +4,12 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.log.internal.user +package com.datadog.android.core.internal.user import com.datadog.android.core.internal.persistence.Deserializer -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.Logger import com.datadog.android.log.internal.utils.errorWithTelemetry +import com.datadog.android.v2.api.context.UserInfo import com.google.gson.JsonParseException import java.util.Locale diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoProvider.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoProvider.kt similarity index 80% rename from dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoProvider.kt rename to dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoProvider.kt index a0428ac79a..a7fcc74a38 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoProvider.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoProvider.kt @@ -4,9 +4,9 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.log.internal.user +package com.datadog.android.core.internal.user -import com.datadog.android.core.model.UserInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.tools.annotation.NoOpImplementation @NoOpImplementation diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoSerializer.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoSerializer.kt similarity index 73% rename from dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoSerializer.kt rename to dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoSerializer.kt index 195dd9311b..1acefc5100 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/user/UserInfoSerializer.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/user/UserInfoSerializer.kt @@ -4,13 +4,12 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.log.internal.user +package com.datadog.android.core.internal.user import com.datadog.android.core.internal.persistence.Serializer -import com.datadog.android.core.model.UserInfo +import com.datadog.android.v2.api.context.UserInfo -internal class UserInfoSerializer : - Serializer { +internal class UserInfoSerializer : Serializer { override fun serialize(model: UserInfo): String { return model.toJson().asJsonObject.toString() diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/utils/UserInfoExt.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/utils/UserInfoExt.kt deleted file mode 100644 index c253bbb07b..0000000000 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/core/internal/utils/UserInfoExt.kt +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. - * This product includes software developed at Datadog (https://www.datadoghq.com/). - * Copyright 2016-Present Datadog, Inc. - */ - -package com.datadog.android.core.internal.utils - -import com.datadog.android.v2.api.context.UserInfo - -internal fun UserInfo.hasUserData(): Boolean { - return this.id != null || this.name != null || - this.email != null || this.additionalProperties.isNotEmpty() -} diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/LogsFeature.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/LogsFeature.kt index e43a4c585e..e7c9e780ed 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/LogsFeature.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/LogsFeature.kt @@ -10,8 +10,6 @@ import androidx.annotation.AnyThread import com.datadog.android.core.configuration.Configuration import com.datadog.android.core.internal.utils.devLogger import com.datadog.android.core.internal.utils.sdkLogger -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.event.MapperSerializer import com.datadog.android.log.internal.domain.DatadogLogGenerator import com.datadog.android.log.internal.domain.event.LogEventMapperWrapper @@ -19,6 +17,8 @@ import com.datadog.android.log.internal.domain.event.LogEventSerializer import com.datadog.android.log.model.LogEvent import com.datadog.android.v2.api.FeatureEventReceiver import com.datadog.android.v2.api.SdkCore +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.android.v2.core.internal.storage.DataWriter import com.datadog.android.v2.core.internal.storage.NoOpDataWriter import com.datadog.android.v2.log.internal.storage.LogsDataWriter diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/domain/DatadogLogGenerator.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/domain/DatadogLogGenerator.kt index 1a40d86e12..fbb159b67e 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/domain/DatadogLogGenerator.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/domain/DatadogLogGenerator.kt @@ -6,13 +6,13 @@ package com.datadog.android.log.internal.domain -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.LogAttributes import com.datadog.android.log.internal.utils.buildLogDateFormat import com.datadog.android.log.model.LogEvent import com.datadog.android.rum.internal.RumFeature import com.datadog.android.v2.api.context.DatadogContext +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import io.opentracing.util.GlobalTracer import java.util.Date @@ -193,48 +193,27 @@ internal class DatadogLogGenerator( datadogContext: DatadogContext, networkInfo: NetworkInfo? ): LogEvent.Network { - // TODO RUMM-0000 use V2 (RUM should write V2 version) - return if (networkInfo != null) { + return with(networkInfo ?: datadogContext.networkInfo) { LogEvent.Network( LogEvent.Client( - simCarrier = resolveSimCarrier(networkInfo), - signalStrength = networkInfo.strength?.toString(), - downlinkKbps = networkInfo.downKbps?.toString(), - uplinkKbps = networkInfo.upKbps?.toString(), - connectivity = networkInfo.connectivity.toString() - ) - ) - } else { - LogEvent.Network( - LogEvent.Client( - simCarrier = resolveSimCarrier(datadogContext.networkInfo), - signalStrength = datadogContext.networkInfo.strength?.toString(), - downlinkKbps = datadogContext.networkInfo.downKbps?.toString(), - uplinkKbps = datadogContext.networkInfo.upKbps?.toString(), - connectivity = datadogContext.networkInfo.connectivity.toString() + simCarrier = resolveSimCarrier(this), + signalStrength = strength?.toString(), + downlinkKbps = downKbps?.toString(), + uplinkKbps = upKbps?.toString(), + connectivity = connectivity.toString() ) ) } } private fun resolveUserInfo(datadogContext: DatadogContext, userInfo: UserInfo?): LogEvent.Usr { - // TODO RUMM-0000 use V2 (RUM should write V2 version) - return if (userInfo != null) { + return with(userInfo ?: datadogContext.userInfo) { LogEvent.Usr( - name = userInfo.name, - email = userInfo.email, - id = userInfo.id, - additionalProperties = userInfo.additionalProperties + name = name, + email = email, + id = id, + additionalProperties = additionalProperties.toMutableMap() ) - } else { - with(datadogContext.userInfo) { - LogEvent.Usr( - name = name, - email = email, - id = id, - additionalProperties = additionalProperties.toMutableMap() - ) - } } } @@ -307,18 +286,6 @@ internal class DatadogLogGenerator( } } - private fun resolveSimCarrier(networkInfo: com.datadog.android.v2.api.context.NetworkInfo): - LogEvent.SimCarrier? { - return if (networkInfo.carrierId != null || networkInfo.carrierName != null) { - LogEvent.SimCarrier( - id = networkInfo.carrierId?.toString(), - name = networkInfo.carrierName - ) - } else { - null - } - } - // endregion companion object { diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/domain/LogGenerator.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/domain/LogGenerator.kt index ca2b706657..b2d0c2ff16 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/domain/LogGenerator.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/log/internal/domain/LogGenerator.kt @@ -6,10 +6,10 @@ package com.datadog.android.log.internal.domain -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.model.LogEvent import com.datadog.android.v2.api.context.DatadogContext +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.tools.annotation.NoOpImplementation @NoOpImplementation diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumActionScope.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumActionScope.kt index d8c5207ac3..0643bf1eee 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumActionScope.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumActionScope.kt @@ -7,7 +7,6 @@ package com.datadog.android.rum.internal.domain.scope import androidx.annotation.WorkerThread -import com.datadog.android.core.internal.utils.hasUserData import com.datadog.android.rum.GlobalRum import com.datadog.android.rum.RumActionType import com.datadog.android.rum.internal.FeaturesContextResolver diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt index b10e74b089..acfb22bce5 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumResourceScope.kt @@ -9,7 +9,6 @@ package com.datadog.android.rum.internal.domain.scope import androidx.annotation.WorkerThread import com.datadog.android.core.internal.net.FirstPartyHostDetector import com.datadog.android.core.internal.utils.devLogger -import com.datadog.android.core.internal.utils.hasUserData import com.datadog.android.core.internal.utils.loggableStackTrace import com.datadog.android.rum.GlobalRum import com.datadog.android.rum.RumAttributes diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt index 230563cc9b..cf4c91f20c 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/domain/scope/RumViewScope.kt @@ -17,7 +17,6 @@ import com.datadog.android.core.internal.net.FirstPartyHostDetector import com.datadog.android.core.internal.system.BuildSdkVersionProvider import com.datadog.android.core.internal.system.DefaultBuildSdkVersionProvider import com.datadog.android.core.internal.utils.devLogger -import com.datadog.android.core.internal.utils.hasUserData import com.datadog.android.core.internal.utils.loggableStackTrace import com.datadog.android.core.internal.utils.resolveViewUrl import com.datadog.android.core.internal.utils.sdkLogger diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/DatadogNdkCrashHandler.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/DatadogNdkCrashHandler.kt index 15a8f7efde..72af0576b8 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/DatadogNdkCrashHandler.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/DatadogNdkCrashHandler.kt @@ -17,8 +17,6 @@ import com.datadog.android.core.internal.system.AndroidInfoProvider import com.datadog.android.core.internal.time.TimeProvider import com.datadog.android.core.internal.utils.devLogger import com.datadog.android.core.internal.utils.join -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.LogAttributes import com.datadog.android.log.Logger import com.datadog.android.log.internal.LogsFeature @@ -29,6 +27,8 @@ import com.datadog.android.rum.internal.domain.scope.tryFromSource import com.datadog.android.rum.model.ErrorEvent import com.datadog.android.rum.model.ViewEvent import com.datadog.android.v2.api.SdkCore +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.android.v2.core.internal.storage.DataWriter import java.io.File import java.util.Locale diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/NdkNetworkInfoDataWriter.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/NdkNetworkInfoDataWriter.kt index 5d0ae9c0f9..51d9b56504 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/NdkNetworkInfoDataWriter.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/NdkNetworkInfoDataWriter.kt @@ -15,8 +15,8 @@ import com.datadog.android.core.internal.persistence.file.advanced.ConsentAwareF import com.datadog.android.core.internal.persistence.file.single.SingleFileOrchestrator import com.datadog.android.core.internal.persistence.file.single.SingleItemDataWriter import com.datadog.android.core.internal.privacy.ConsentProvider -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.log.Logger +import com.datadog.android.v2.api.context.NetworkInfo import java.io.File import java.util.concurrent.ExecutorService diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/NdkUserInfoDataWriter.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/NdkUserInfoDataWriter.kt index 965a11cd2b..ebf713d523 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/NdkUserInfoDataWriter.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/ndk/NdkUserInfoDataWriter.kt @@ -14,9 +14,9 @@ import com.datadog.android.core.internal.persistence.file.advanced.ConsentAwareF import com.datadog.android.core.internal.persistence.file.single.SingleFileOrchestrator import com.datadog.android.core.internal.persistence.file.single.SingleItemDataWriter import com.datadog.android.core.internal.privacy.ConsentProvider -import com.datadog.android.core.model.UserInfo +import com.datadog.android.core.internal.user.UserInfoSerializer import com.datadog.android.log.Logger -import com.datadog.android.log.internal.user.UserInfoSerializer +import com.datadog.android.v2.api.context.UserInfo import java.io.File import java.util.concurrent.ExecutorService diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/SdkCore.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/SdkCore.kt index 640ea137ff..558563b8c6 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/SdkCore.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/SdkCore.kt @@ -7,9 +7,9 @@ package com.datadog.android.v2.api import com.datadog.android.Datadog -import com.datadog.android.core.model.UserInfo import com.datadog.android.privacy.TrackingConsent import com.datadog.android.v2.api.context.TimeInfo +import com.datadog.android.v2.api.context.UserInfo /** * SdkCore is the entry point to register Datadog features to the core registry. diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/context/NetworkInfo.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/context/NetworkInfo.kt index da5d57fbfb..2cd19b4559 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/context/NetworkInfo.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/context/NetworkInfo.kt @@ -6,6 +6,19 @@ package com.datadog.android.v2.api.context +import com.google.gson.JsonElement +import com.google.gson.JsonObject +import com.google.gson.JsonParseException +import com.google.gson.JsonParser +import com.google.gson.JsonPrimitive +import java.lang.IllegalStateException +import java.lang.NullPointerException +import java.lang.NumberFormatException +import kotlin.Long +import kotlin.String +import kotlin.jvm.JvmStatic +import kotlin.jvm.Throws + /** * Holds information about the current network state. * @@ -18,29 +31,133 @@ package com.datadog.android.v2.api.context * @property cellularTechnology the type of cellular technology if known (e.g.: GPRS, LTE, 5G) */ data class NetworkInfo( - val connectivity: Connectivity, - val carrierName: String?, - val carrierId: Long?, - val upKbps: Long?, - val downKbps: Long?, - val strength: Long?, - val cellularTechnology: String? + val connectivity: Connectivity = Connectivity.NETWORK_NOT_CONNECTED, + val carrierName: String? = null, + val carrierId: Long? = null, + val upKbps: Long? = null, + val downKbps: Long? = null, + val strength: Long? = null, + val cellularTechnology: String? = null ) { + internal fun toJson(): JsonElement { + val json = JsonObject() + json.add("connectivity", connectivity.toJson()) + carrierName?.let { carrierNameNonNull -> + json.addProperty("carrier_name", carrierNameNonNull) + } + carrierId?.let { carrierIdNonNull -> + json.addProperty("carrier_id", carrierIdNonNull) + } + upKbps?.let { upKbpsNonNull -> + json.addProperty("up_kbps", upKbpsNonNull) + } + downKbps?.let { downKbpsNonNull -> + json.addProperty("down_kbps", downKbpsNonNull) + } + strength?.let { strengthNonNull -> + json.addProperty("strength", strengthNonNull) + } + cellularTechnology?.let { cellularTechnologyNonNull -> + json.addProperty("cellular_technology", cellularTechnologyNonNull) + } + return json + } + + internal companion object { + @JvmStatic + @Throws(JsonParseException::class) + @Suppress("StringLiteralDuplication") + fun fromJson(jsonString: String): NetworkInfo { + try { + // JsonParseException is declared in the method signature + @Suppress("UnsafeThirdPartyFunctionCall") + val jsonObject = JsonParser.parseString(jsonString).asJsonObject + return fromJsonObject(jsonObject) + } catch (e: IllegalStateException) { + throw JsonParseException( + "Unable to parse json into type NetworkInfo", + e + ) + } + } + + @JvmStatic + @Throws(JsonParseException::class) + @Suppress("StringLiteralDuplication") + fun fromJsonObject(jsonObject: JsonObject): NetworkInfo { + try { + val connectivity = Connectivity.fromJson(jsonObject.get("connectivity").asString) + val carrierName = jsonObject.get("carrier_name")?.asString + val carrierId = jsonObject.get("carrier_id")?.asLong + val upKbps = jsonObject.get("up_kbps")?.asLong + val downKbps = jsonObject.get("down_kbps")?.asLong + val strength = jsonObject.get("strength")?.asLong + val cellularTechnology = jsonObject.get("cellular_technology")?.asString + return NetworkInfo( + connectivity, + carrierName, + carrierId, + upKbps, + downKbps, + strength, + cellularTechnology + ) + } catch (e: IllegalStateException) { + throw JsonParseException( + "Unable to parse json into type NetworkInfo", + e + ) + } catch (e: NumberFormatException) { + throw JsonParseException( + "Unable to parse json into type NetworkInfo", + e + ) + } catch (@Suppress("TooGenericExceptionCaught") e: NullPointerException) { + throw JsonParseException( + "Unable to parse json into type NetworkInfo", + e + ) + } + } + } + /** * The type of connectivity currently available. */ - enum class Connectivity { - NETWORK_NOT_CONNECTED, - NETWORK_ETHERNET, - NETWORK_WIFI, - NETWORK_WIMAX, - NETWORK_BLUETOOTH, - NETWORK_2G, - NETWORK_3G, - NETWORK_4G, - NETWORK_5G, - NETWORK_MOBILE_OTHER, - NETWORK_CELLULAR, - NETWORK_OTHER + enum class Connectivity( + private val jsonValue: String + ) { + NETWORK_NOT_CONNECTED("network_not_connected"), + NETWORK_ETHERNET("network_ethernet"), + NETWORK_WIFI("network_wifi"), + NETWORK_WIMAX("network_wimax"), + NETWORK_BLUETOOTH("network_bluetooth"), + NETWORK_2G("network_2G"), + NETWORK_3G("network_3G"), + NETWORK_4G("network_4G"), + NETWORK_5G("network_5G"), + NETWORK_MOBILE_OTHER("network_mobile_other"), + NETWORK_CELLULAR("network_cellular"), + NETWORK_OTHER("network_other") + ; + + internal fun toJson(): JsonElement = JsonPrimitive(jsonValue) + + internal companion object { + @JvmStatic + @Throws(JsonParseException::class) + fun fromJson(jsonString: String): Connectivity { + try { + return values().first { + it.jsonValue == jsonString + } + } catch (e: NoSuchElementException) { + throw JsonParseException( + "Unable to parse json into type NetworkInfo.Connectivity", + e + ) + } + } + } } } diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/context/UserInfo.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/context/UserInfo.kt index 0cae54d608..2df9f40792 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/context/UserInfo.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/api/context/UserInfo.kt @@ -6,6 +6,20 @@ package com.datadog.android.v2.api.context +import com.datadog.android.core.`internal`.utils.toJsonElement +import com.google.gson.JsonElement +import com.google.gson.JsonObject +import com.google.gson.JsonParseException +import com.google.gson.JsonParser +import java.lang.IllegalStateException +import java.lang.NullPointerException +import java.lang.NumberFormatException +import kotlin.Any +import kotlin.Array +import kotlin.String +import kotlin.jvm.JvmStatic +import kotlin.jvm.Throws + /** * Holds information about the current User. * @property id a unique identifier for the user, or null @@ -14,8 +28,87 @@ package com.datadog.android.v2.api.context * @property additionalProperties a dictionary of custom properties attached to the current user */ data class UserInfo( - val id: String?, - val name: String?, - val email: String?, - val additionalProperties: Map -) + val id: String? = null, + val name: String? = null, + val email: String? = null, + val additionalProperties: Map = emptyMap() +) { + internal fun hasUserData(): Boolean { + return id != null || name != null || + email != null || additionalProperties.isNotEmpty() + } + + @Suppress("StringLiteralDuplication") + internal fun toJson(): JsonElement { + val json = JsonObject() + id?.let { idNonNull -> + json.addProperty("id", idNonNull) + } + name?.let { nameNonNull -> + json.addProperty("name", nameNonNull) + } + email?.let { emailNonNull -> + json.addProperty("email", emailNonNull) + } + additionalProperties.forEach { (k, v) -> + if (k !in RESERVED_PROPERTIES) { + json.add(k, v.toJsonElement()) + } + } + return json + } + + internal companion object { + internal val RESERVED_PROPERTIES: Array = arrayOf("id", "name", "email") + + @JvmStatic + @Throws(JsonParseException::class) + @Suppress("StringLiteralDuplication") + fun fromJson(jsonString: String): UserInfo { + try { + // JsonParseException is declared in the method signature + @Suppress("UnsafeThirdPartyFunctionCall") + val jsonObject = JsonParser.parseString(jsonString).asJsonObject + return fromJsonObject(jsonObject) + } catch (e: IllegalStateException) { + throw JsonParseException( + "Unable to parse json into type UserInfo", + e + ) + } + } + + @JvmStatic + @Throws(JsonParseException::class) + @Suppress("StringLiteralDuplication") + fun fromJsonObject(jsonObject: JsonObject): UserInfo { + try { + val id = jsonObject.get("id")?.asString + val name = jsonObject.get("name")?.asString + val email = jsonObject.get("email")?.asString + val additionalProperties = mutableMapOf() + for (entry in jsonObject.entrySet()) { + if (entry.key !in RESERVED_PROPERTIES) { + additionalProperties[entry.key] = entry.value + } + } + return UserInfo(id, name, email, additionalProperties) + } catch (e: IllegalStateException) { + throw JsonParseException( + "Unable to parse json into type UserInfo", + e + ) + } catch (e: NumberFormatException) { + throw JsonParseException( + "Unable to parse json into type UserInfo", + e + ) + } catch (@Suppress("TooGenericExceptionCaught") e: NullPointerException) { + throw JsonParseException( + "Unable to parse json into type UserInfo", + e + ) + } + } + } +} diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/DatadogCore.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/DatadogCore.kt index 54ddb5a3ea..4265f9b4aa 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/DatadogCore.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/DatadogCore.kt @@ -23,7 +23,6 @@ import com.datadog.android.core.internal.time.NoOpTimeProvider import com.datadog.android.core.internal.utils.devLogger import com.datadog.android.core.internal.utils.scheduleSafe import com.datadog.android.core.internal.utils.sdkLogger -import com.datadog.android.core.model.UserInfo import com.datadog.android.error.internal.CrashReportsFeature import com.datadog.android.log.internal.LogsFeature import com.datadog.android.plugin.DatadogContext @@ -43,6 +42,7 @@ import com.datadog.android.v2.api.FeatureUploadConfiguration import com.datadog.android.v2.api.RequestFactory import com.datadog.android.v2.api.SdkCore import com.datadog.android.v2.api.context.TimeInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.android.v2.core.internal.ContextProvider import com.datadog.android.v2.core.internal.storage.NoOpDataWriter import com.datadog.android.v2.log.internal.net.LogsRequestFactory diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/NoOpSdkCore.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/NoOpSdkCore.kt index 111f7e703d..0fd5dea481 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/NoOpSdkCore.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/NoOpSdkCore.kt @@ -6,7 +6,6 @@ package com.datadog.android.v2.core -import com.datadog.android.core.model.UserInfo import com.datadog.android.privacy.TrackingConsent import com.datadog.android.v2.api.FeatureEventReceiver import com.datadog.android.v2.api.FeatureScope @@ -14,6 +13,7 @@ import com.datadog.android.v2.api.FeatureStorageConfiguration import com.datadog.android.v2.api.FeatureUploadConfiguration import com.datadog.android.v2.api.SdkCore import com.datadog.android.v2.api.context.TimeInfo +import com.datadog.android.v2.api.context.UserInfo import java.util.concurrent.TimeUnit internal class NoOpSdkCore : SdkCore { diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/internal/DatadogContextProvider.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/internal/DatadogContextProvider.kt index b49f44a92e..71ebc1e1ff 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/internal/DatadogContextProvider.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/internal/DatadogContextProvider.kt @@ -9,12 +9,9 @@ package com.datadog.android.v2.core.internal import com.datadog.android.core.internal.CoreFeature import com.datadog.android.v2.api.context.DatadogContext import com.datadog.android.v2.api.context.DeviceInfo -import com.datadog.android.v2.api.context.NetworkInfo import com.datadog.android.v2.api.context.ProcessInfo import com.datadog.android.v2.api.context.TimeInfo -import com.datadog.android.v2.api.context.UserInfo import java.util.concurrent.TimeUnit -import com.datadog.android.core.model.NetworkInfo as NetworkInfoV1 internal class DatadogContextProvider(val coreFeature: CoreFeature) : ContextProvider { override val context: DatadogContext @@ -43,17 +40,7 @@ internal class DatadogContextProvider(val coreFeature: CoreFeature) : ContextPro isMainProcess = coreFeature.isMainProcess, processImportance = CoreFeature.processImportance ), - networkInfo = with(coreFeature.networkInfoProvider.getLatestNetworkInfo()) { - NetworkInfo( - connectivity = connectivity.asV2(), - carrierName = carrierName, - carrierId = carrierId, - upKbps = upKbps, - downKbps = downKbps, - strength = strength, - cellularTechnology = cellularTechnology - ) - }, + networkInfo = coreFeature.networkInfoProvider.getLatestNetworkInfo(), deviceInfo = with(coreFeature.androidInfoProvider) { DeviceInfo( deviceName = deviceName, @@ -67,14 +54,7 @@ internal class DatadogContextProvider(val coreFeature: CoreFeature) : ContextPro architecture = architecture ) }, - userInfo = with(coreFeature.userInfoProvider.getUserInfo()) { - UserInfo( - id = id, - name = name, - email = email, - additionalProperties = additionalProperties - ) - }, + userInfo = coreFeature.userInfoProvider.getUserInfo(), trackingConsent = coreFeature.trackingConsentProvider.getConsent(), featuresContext = coreFeature.featuresContext ) @@ -87,26 +67,4 @@ internal class DatadogContextProvider(val coreFeature: CoreFeature) : ContextPro override fun getFeatureContext(feature: String): Map { return coreFeature.featuresContext[feature] ?: emptyMap() } - - private fun NetworkInfoV1.Connectivity.asV2(): NetworkInfo.Connectivity { - return when (this) { - NetworkInfoV1.Connectivity.NETWORK_NOT_CONNECTED -> - NetworkInfo.Connectivity.NETWORK_NOT_CONNECTED - NetworkInfoV1.Connectivity.NETWORK_ETHERNET -> - NetworkInfo.Connectivity.NETWORK_ETHERNET - NetworkInfoV1.Connectivity.NETWORK_WIFI -> NetworkInfo.Connectivity.NETWORK_WIFI - NetworkInfoV1.Connectivity.NETWORK_WIMAX -> NetworkInfo.Connectivity.NETWORK_WIMAX - NetworkInfoV1.Connectivity.NETWORK_BLUETOOTH -> - NetworkInfo.Connectivity.NETWORK_BLUETOOTH - NetworkInfoV1.Connectivity.NETWORK_2G -> NetworkInfo.Connectivity.NETWORK_2G - NetworkInfoV1.Connectivity.NETWORK_3G -> NetworkInfo.Connectivity.NETWORK_3G - NetworkInfoV1.Connectivity.NETWORK_4G -> NetworkInfo.Connectivity.NETWORK_4G - NetworkInfoV1.Connectivity.NETWORK_5G -> NetworkInfo.Connectivity.NETWORK_5G - NetworkInfoV1.Connectivity.NETWORK_MOBILE_OTHER -> - NetworkInfo.Connectivity.NETWORK_MOBILE_OTHER - NetworkInfoV1.Connectivity.NETWORK_CELLULAR -> - NetworkInfo.Connectivity.NETWORK_CELLULAR - NetworkInfoV1.Connectivity.NETWORK_OTHER -> NetworkInfo.Connectivity.NETWORK_OTHER - } - } } diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/internal/data/upload/DataUploadRunnable.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/internal/data/upload/DataUploadRunnable.kt index a6f0d206f1..469abe22ca 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/internal/data/upload/DataUploadRunnable.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/v2/core/internal/data/upload/DataUploadRunnable.kt @@ -13,8 +13,8 @@ import com.datadog.android.core.internal.data.upload.UploadRunnable import com.datadog.android.core.internal.net.info.NetworkInfoProvider import com.datadog.android.core.internal.system.SystemInfoProvider import com.datadog.android.core.internal.utils.scheduleSafe -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.v2.api.context.DatadogContext +import com.datadog.android.v2.api.context.NetworkInfo import com.datadog.android.v2.core.internal.ContextProvider import com.datadog.android.v2.core.internal.net.DataUploader import com.datadog.android.v2.core.internal.storage.BatchId diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/DatadogTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/DatadogTest.kt index a27267b5c1..e7ce78bedc 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/DatadogTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/DatadogTest.kt @@ -11,7 +11,6 @@ import android.content.Context import android.net.ConnectivityManager import com.datadog.android.core.configuration.Configuration import com.datadog.android.core.configuration.Credentials -import com.datadog.android.core.model.UserInfo import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.internal.RumFeature import com.datadog.android.sessionreplay.internal.SessionReplayFeature @@ -21,6 +20,7 @@ import com.datadog.android.utils.config.LoggerTestConfiguration import com.datadog.android.utils.config.MainLooperTestConfiguration import com.datadog.android.utils.extension.mockChoreographerInstance import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.UserInfo import com.datadog.android.v2.core.DatadogCore import com.datadog.android.v2.core.NoOpSdkCore import com.datadog.android.v2.core.internal.HashGenerator diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/CoreFeatureTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/CoreFeatureTest.kt index 2fc1569e43..7bb501deee 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/CoreFeatureTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/CoreFeatureTest.kt @@ -27,8 +27,8 @@ import com.datadog.android.core.internal.system.BroadcastReceiverSystemInfoProvi import com.datadog.android.core.internal.system.NoOpSystemInfoProvider import com.datadog.android.core.internal.time.KronosTimeProvider import com.datadog.android.core.internal.time.NoOpTimeProvider -import com.datadog.android.log.internal.user.DatadogUserInfoProvider -import com.datadog.android.log.internal.user.NoOpMutableUserInfoProvider +import com.datadog.android.core.internal.user.DatadogUserInfoProvider +import com.datadog.android.core.internal.user.NoOpMutableUserInfoProvider import com.datadog.android.privacy.TrackingConsent import com.datadog.android.rum.internal.ndk.DatadogNdkCrashHandler import com.datadog.android.rum.internal.ndk.NoOpNdkCrashHandler @@ -113,9 +113,6 @@ internal class CoreFeatureTest { @StringForgery(type = StringForgeryType.ALPHA_NUMERICAL) lateinit var fakeSdkInstanceId: String - @StringForgery(regex = "[a-zA-Z0-9_:./-]{0,195}[a-zA-Z0-9_./-]") - lateinit var fakeEnvName: String - @BeforeEach fun `set up`() { testedFeature = CoreFeature() diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnableTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnableTest.kt index ed613392b8..7ab6427ad7 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnableTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/data/upload/DataUploadRunnableTest.kt @@ -14,8 +14,8 @@ import com.datadog.android.core.internal.persistence.Batch import com.datadog.android.core.internal.persistence.DataReader import com.datadog.android.core.internal.system.SystemInfo import com.datadog.android.core.internal.system.SystemInfoProvider -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.NetworkInfo import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.anyOrNull import com.nhaarman.mockitokotlin2.argumentCaptor diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallbackTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallbackTest.kt index 6c946e4b26..4c18ae759f 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallbackTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/lifecycle/ProcessLifecycleCallbackTest.kt @@ -14,8 +14,8 @@ import com.datadog.android.core.internal.data.upload.UploadWorker import com.datadog.android.core.internal.net.info.NetworkInfoProvider import com.datadog.android.core.internal.utils.TAG_DATADOG_UPLOAD import com.datadog.android.core.internal.utils.UPLOAD_WORKER_NAME -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.utils.config.ApplicationContextTestConfiguration +import com.datadog.android.v2.api.context.NetworkInfo import com.datadog.tools.unit.annotations.TestConfigurationsProvider import com.datadog.tools.unit.extensions.TestConfigurationExtension import com.datadog.tools.unit.extensions.config.TestConfiguration diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/BroadcastReceiverNetworkInfoProviderTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/BroadcastReceiverNetworkInfoProviderTest.kt index da367ce46c..e05f0a879c 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/BroadcastReceiverNetworkInfoProviderTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/BroadcastReceiverNetworkInfoProviderTest.kt @@ -15,9 +15,9 @@ import android.os.Build import android.telephony.TelephonyManager import com.datadog.android.core.internal.persistence.DataWriter import com.datadog.android.core.internal.system.BuildSdkVersionProvider -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.log.assertj.NetworkInfoAssert.Companion.assertThat import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.NetworkInfo import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verifyZeroInteractions diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/CallbackNetworkInfoProviderTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/CallbackNetworkInfoProviderTest.kt index 2e89e9ce49..4b945edcdc 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/CallbackNetworkInfoProviderTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/CallbackNetworkInfoProviderTest.kt @@ -14,10 +14,10 @@ import android.os.Build import android.util.Log import com.datadog.android.core.internal.persistence.DataWriter import com.datadog.android.core.internal.system.BuildSdkVersionProvider -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.log.assertj.NetworkInfoAssert.Companion.assertThat import com.datadog.android.utils.config.LoggerTestConfiguration import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.NetworkInfo import com.datadog.tools.unit.annotations.TestConfigurationsProvider import com.datadog.tools.unit.extensions.TestConfigurationExtension import com.datadog.tools.unit.extensions.config.TestConfiguration diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoDeserializerTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoDeserializerTest.kt index a09f67d77d..09c26b1775 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoDeserializerTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoDeserializerTest.kt @@ -6,10 +6,10 @@ package com.datadog.android.core.internal.net.info -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.log.Logger import com.datadog.android.log.internal.logger.LogHandler import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.NetworkInfo import fr.xgouchet.elmyr.annotation.Forgery import fr.xgouchet.elmyr.junit5.ForgeConfiguration import fr.xgouchet.elmyr.junit5.ForgeExtension diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoSerializerTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoSerializerTest.kt index 2f882262c0..55b4b266ba 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoSerializerTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/net/info/NetworkInfoSerializerTest.kt @@ -6,8 +6,8 @@ package com.datadog.android.core.internal.net.info -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.NetworkInfo import fr.xgouchet.elmyr.annotation.Forgery import fr.xgouchet.elmyr.junit5.ForgeConfiguration import fr.xgouchet.elmyr.junit5.ForgeExtension diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/DatadogUserInfoProviderTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/DatadogUserInfoProviderTest.kt similarity index 97% rename from dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/DatadogUserInfoProviderTest.kt rename to dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/DatadogUserInfoProviderTest.kt index ab9f25cc87..b36b4c1729 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/DatadogUserInfoProviderTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/DatadogUserInfoProviderTest.kt @@ -4,12 +4,12 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.log.internal.user +package com.datadog.android.core.internal.user import com.datadog.android.core.internal.persistence.DataWriter -import com.datadog.android.core.model.UserInfo import com.datadog.android.utils.forge.Configurator import com.datadog.android.utils.forge.exhaustiveAttributes +import com.datadog.android.v2.api.context.UserInfo import com.nhaarman.mockitokotlin2.verify import fr.xgouchet.elmyr.Forge import fr.xgouchet.elmyr.annotation.Forgery diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/UserInfoDeserializerTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/UserInfoDeserializerTest.kt similarity index 95% rename from dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/UserInfoDeserializerTest.kt rename to dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/UserInfoDeserializerTest.kt index 05ff0e8c6e..6b37d57f06 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/UserInfoDeserializerTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/UserInfoDeserializerTest.kt @@ -4,13 +4,13 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.log.internal.user +package com.datadog.android.core.internal.user -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.Logger import com.datadog.android.log.internal.logger.LogHandler import com.datadog.android.utils.assertj.DeserializedMapAssert import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.UserInfo import fr.xgouchet.elmyr.annotation.Forgery import fr.xgouchet.elmyr.junit5.ForgeConfiguration import fr.xgouchet.elmyr.junit5.ForgeExtension diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/UserInfoSerializerTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/UserInfoSerializerTest.kt similarity index 93% rename from dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/UserInfoSerializerTest.kt rename to dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/UserInfoSerializerTest.kt index 5779ea64b4..b8f977400f 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/user/UserInfoSerializerTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/core/internal/user/UserInfoSerializerTest.kt @@ -4,11 +4,11 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.log.internal.user +package com.datadog.android.core.internal.user -import com.datadog.android.core.model.UserInfo import com.datadog.android.utils.assertj.DeserializedMapAssert.Companion.assertThat import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.UserInfo import fr.xgouchet.elmyr.annotation.Forgery import fr.xgouchet.elmyr.junit5.ForgeConfiguration import fr.xgouchet.elmyr.junit5.ForgeExtension diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/assertj/LogEventAssert.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/log/assertj/LogEventAssert.kt index b945c73f76..c3e6b6478f 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/assertj/LogEventAssert.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/log/assertj/LogEventAssert.kt @@ -6,10 +6,10 @@ package com.datadog.android.log.assertj -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.internal.domain.DatadogLogGenerator import com.datadog.android.log.model.LogEvent +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import org.assertj.core.api.AbstractObjectAssert import org.assertj.core.api.Assertions.assertThat import org.assertj.core.data.Offset @@ -175,52 +175,6 @@ internal class LogEventAssert(actual: LogEvent) : return this } - fun hasNetworkInfo(networkInfo: com.datadog.android.v2.api.context.NetworkInfo): LogEventAssert { - assertThat(actual.network?.client?.connectivity) - .overridingErrorMessage( - "Expected LogEvent to have connectivity: " + - "${networkInfo.connectivity} but " + - "instead was: ${actual.network?.client?.connectivity}" - ) - .isEqualTo(networkInfo.connectivity.toString()) - assertThat(actual.network?.client?.downlinkKbps) - .overridingErrorMessage( - "Expected LogEvent to have downlinkKbps: " + - "${networkInfo.downKbps?.toString()} but " + - "instead was: ${actual.network?.client?.downlinkKbps}" - ) - .isEqualTo(networkInfo.downKbps?.toString()) - assertThat(actual.network?.client?.uplinkKbps) - .overridingErrorMessage( - "Expected LogEvent to have uplinkKbps: " + - "${networkInfo.upKbps?.toString()} but " + - "instead was: ${actual.network?.client?.uplinkKbps}" - ) - .isEqualTo(networkInfo.upKbps?.toString()) - assertThat(actual.network?.client?.signalStrength) - .overridingErrorMessage( - "Expected LogEvent to have signal strength: " + - "${networkInfo.strength?.toString()} but " + - "instead was: ${actual.network?.client?.signalStrength}" - ) - .isEqualTo(networkInfo.strength?.toString()) - assertThat(actual.network?.client?.simCarrier?.id) - .overridingErrorMessage( - "Expected LogEvent to have carrier id: " + - "${networkInfo.carrierId?.toString()} but " + - "instead was: ${actual.network?.client?.simCarrier?.id}" - ) - .isEqualTo(networkInfo.carrierId?.toString()) - assertThat(actual.network?.client?.simCarrier?.name) - .overridingErrorMessage( - "Expected LogEvent to have carrier name: " + - "${networkInfo.carrierName} but " + - "instead was: ${actual.network?.client?.simCarrier?.name}" - ) - .isEqualTo(networkInfo.carrierName) - return this - } - fun doesNotHaveError(): LogEventAssert { assertThat(actual.error) .overridingErrorMessage( @@ -269,34 +223,6 @@ internal class LogEventAssert(actual: LogEvent) : return this } - fun hasUserInfo(userInfo: com.datadog.android.v2.api.context.UserInfo): LogEventAssert { - assertThat(actual.usr?.name) - .overridingErrorMessage( - "Expected LogEvent to have user name: " + - "${userInfo.name} but " + - "instead was: ${actual.usr?.name}" - ) - .isEqualTo(userInfo.name) - assertThat(actual.usr?.email) - .overridingErrorMessage( - "Expected LogEvent to have user email: " + - "${userInfo.email} but " + - "instead was: ${actual.usr?.email}" - ) - .isEqualTo(userInfo.email) - assertThat(actual.usr?.id) - .overridingErrorMessage( - "Expected LogEvent to have user id: " + - "${userInfo.id} but " + - "instead was: ${actual.usr?.id}" - ) - .isEqualTo(userInfo.id) - assertThat(actual.usr?.additionalProperties) - .hasSameSizeAs(userInfo.additionalProperties) - .containsAllEntriesOf(userInfo.additionalProperties) - return this - } - fun doesNotHaveUserInfo(): LogEventAssert { assertThat(actual.usr) .overridingErrorMessage( diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/assertj/NetworkInfoAssert.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/log/assertj/NetworkInfoAssert.kt index 9e4cd38ad8..d3de819769 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/assertj/NetworkInfoAssert.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/log/assertj/NetworkInfoAssert.kt @@ -6,7 +6,7 @@ package com.datadog.android.log.assertj -import com.datadog.android.core.model.NetworkInfo +import com.datadog.android.v2.api.context.NetworkInfo import org.assertj.core.api.AbstractObjectAssert import org.assertj.core.api.Assertions.assertThat diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/LogsFeatureTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/LogsFeatureTest.kt index 9a6cd649a8..c081095a19 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/LogsFeatureTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/LogsFeatureTest.kt @@ -8,8 +8,6 @@ package com.datadog.android.log.internal import android.util.Log import com.datadog.android.core.configuration.Configuration -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.event.MapperSerializer import com.datadog.android.log.LogAttributes import com.datadog.android.log.internal.domain.event.LogEventMapperWrapper @@ -24,6 +22,8 @@ import com.datadog.android.v2.api.EventBatchWriter import com.datadog.android.v2.api.FeatureScope import com.datadog.android.v2.api.SdkCore import com.datadog.android.v2.api.context.DatadogContext +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.android.v2.core.internal.storage.DataWriter import com.datadog.android.v2.log.internal.storage.LogsDataWriter import com.datadog.opentracing.DDSpanContext diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/domain/DatadogLogGeneratorTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/domain/DatadogLogGeneratorTest.kt index 759a9a18b7..c34203c0e6 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/domain/DatadogLogGeneratorTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/log/internal/domain/DatadogLogGeneratorTest.kt @@ -6,8 +6,6 @@ package com.datadog.android.log.internal.domain -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.LogAttributes import com.datadog.android.log.assertj.LogEventAssert.Companion.assertThat import com.datadog.android.log.model.LogEvent @@ -17,6 +15,8 @@ import com.datadog.android.utils.extension.asLogStatus import com.datadog.android.utils.extension.toIsoFormattedTimestamp import com.datadog.android.utils.forge.Configurator import com.datadog.android.v2.api.context.DatadogContext +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.opentracing.DDSpanContext import com.datadog.tools.unit.extensions.TestConfigurationExtension import com.datadog.tools.unit.forge.aThrowable diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/domain/event/RumEventSerializerTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/domain/event/RumEventSerializerTest.kt index e611a7f0f3..67a88602e8 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/domain/event/RumEventSerializerTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/domain/event/RumEventSerializerTest.kt @@ -7,7 +7,6 @@ package com.datadog.android.rum.internal.domain.event import com.datadog.android.core.internal.constraints.DataConstraints -import com.datadog.android.core.model.UserInfo import com.datadog.android.rum.RumAttributes import com.datadog.android.rum.model.ActionEvent import com.datadog.android.rum.model.ErrorEvent @@ -19,6 +18,7 @@ import com.datadog.android.telemetry.model.TelemetryDebugEvent import com.datadog.android.telemetry.model.TelemetryErrorEvent import com.datadog.android.utils.config.LoggerTestConfiguration import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.UserInfo import com.datadog.tools.unit.annotations.TestConfigurationsProvider import com.datadog.tools.unit.assertj.JsonObjectAssert.Companion.assertThat import com.datadog.tools.unit.extensions.TestConfigurationExtension diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/ndk/DatadogNdkCrashHandlerTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/ndk/DatadogNdkCrashHandlerTest.kt index d6d95ede49..ed5dd67ab0 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/ndk/DatadogNdkCrashHandlerTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/rum/internal/ndk/DatadogNdkCrashHandlerTest.kt @@ -12,8 +12,6 @@ import com.datadog.android.core.internal.persistence.file.FileReader import com.datadog.android.core.internal.persistence.file.batch.BatchFileReader import com.datadog.android.core.internal.system.AndroidInfoProvider import com.datadog.android.core.internal.time.TimeProvider -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.LogAttributes import com.datadog.android.log.Logger import com.datadog.android.log.internal.LogsFeature @@ -31,6 +29,8 @@ import com.datadog.android.v2.api.EventBatchWriter import com.datadog.android.v2.api.FeatureScope import com.datadog.android.v2.api.SdkCore import com.datadog.android.v2.api.context.DatadogContext +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.android.v2.core.internal.storage.DataWriter import com.datadog.tools.unit.annotations.TestConfigurationsProvider import com.datadog.tools.unit.extensions.TestConfigurationExtension @@ -65,7 +65,6 @@ import org.mockito.quality.Strictness import java.io.File import java.util.Locale import java.util.concurrent.ExecutorService -import com.datadog.android.v2.api.context.UserInfo as UserInfoV2 @Extensions( ExtendWith(MockitoExtension::class), @@ -438,7 +437,7 @@ internal class DatadogNdkCrashHandlerTest { id = fakeUserInfo.id, name = fakeUserInfo.name, email = fakeUserInfo.email, - additionalProperties = fakeUserInfo.additionalProperties + additionalProperties = fakeUserInfo.additionalProperties.toMutableMap() ) ) @@ -476,11 +475,11 @@ internal class DatadogNdkCrashHandlerTest { .hasErrorSourceType(ErrorEvent.SourceType.ANDROID) .hasTimestamp(ndkCrashLog.timestamp + fakeServerOffset) .hasUserInfo( - UserInfoV2( + UserInfo( fakeViewEvent.usr?.id, fakeViewEvent.usr?.name, fakeViewEvent.usr?.email, - fakeViewEvent.usr?.additionalProperties ?: mutableMapOf() + fakeViewEvent.usr?.additionalProperties.orEmpty() ) ) .hasErrorType(ndkCrashLog.signalName) @@ -610,7 +609,7 @@ internal class DatadogNdkCrashHandlerTest { id = fakeUserInfo.id, name = fakeUserInfo.name, email = fakeUserInfo.email, - additionalProperties = fakeUserInfo.additionalProperties + additionalProperties = fakeUserInfo.additionalProperties.toMutableMap() ) ) whenever(mockRumEventDeserializer.deserialize(viewEventStr)) @@ -654,11 +653,11 @@ internal class DatadogNdkCrashHandlerTest { .hasErrorSourceType(ErrorEvent.SourceType.ANDROID) .hasTimestamp(ndkCrashLog.timestamp + fakeServerOffset) .hasUserInfo( - UserInfoV2( + UserInfo( fakeViewEvent.usr?.id, fakeViewEvent.usr?.name, fakeViewEvent.usr?.email, - fakeViewEvent.usr?.additionalProperties ?: mutableMapOf() + fakeViewEvent.usr?.additionalProperties.orEmpty() ) ) .hasErrorType(ndkCrashLog.signalName) diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/config/CoreFeatureTestConfiguration.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/config/CoreFeatureTestConfiguration.kt index aedcf81120..4da41bf57d 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/config/CoreFeatureTestConfiguration.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/config/CoreFeatureTestConfiguration.kt @@ -20,7 +20,7 @@ import com.datadog.android.core.internal.system.AndroidInfoProvider import com.datadog.android.core.internal.system.AppVersionProvider import com.datadog.android.core.internal.system.SystemInfoProvider import com.datadog.android.core.internal.time.TimeProvider -import com.datadog.android.log.internal.user.MutableUserInfoProvider +import com.datadog.android.core.internal.user.MutableUserInfoProvider import com.datadog.android.privacy.TrackingConsent import com.datadog.android.utils.forge.exhaustiveAttributes import com.datadog.android.v2.core.internal.ContextProvider diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/Configurator.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/Configurator.kt index e7a101a2d2..b7c630cdd0 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/Configurator.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/Configurator.kt @@ -77,9 +77,7 @@ internal class Configurator : // Datadog SDK v2 forge.addFactory(TimeInfoForgeryFactory()) forge.addFactory(ProcessInfoForgeryFactory()) - forge.addFactory(NetworkInfoV2ForgeryFactory()) forge.addFactory(DeviceInfoForgeryFactory()) - forge.addFactory(UserInfoV2ForgeryFactory()) forge.addFactory(DatadogContextForgeryFactory()) forge.useJvmFactories() diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/CredentialsForgeryFactory.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/CredentialsForgeryFactory.kt index c6f6645af5..561f22582d 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/CredentialsForgeryFactory.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/CredentialsForgeryFactory.kt @@ -16,7 +16,7 @@ internal class CredentialsForgeryFactory : override fun getForgery(forge: Forge): Credentials { return Credentials( clientToken = forge.anHexadecimalString(), - envName = forge.anAlphabeticalString(), + envName = forge.aStringMatching("[a-zA-Z0-9_:./-]{0,195}[a-zA-Z0-9_./-]"), variant = forge.anElementFrom(forge.anAlphabeticalString(), ""), serviceName = forge.aStringMatching("[a-z]+(\\.[a-z]+)+"), rumApplicationId = forge.getForgery().toString() diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/LogEventForgeryFactory.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/LogEventForgeryFactory.kt index f4e71a7c9a..8f132f8c63 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/LogEventForgeryFactory.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/LogEventForgeryFactory.kt @@ -7,9 +7,9 @@ package com.datadog.android.utils.forge import com.datadog.android.core.internal.utils.orEmpty -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.log.model.LogEvent +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.tools.unit.forge.aThrowable import fr.xgouchet.elmyr.Forge import fr.xgouchet.elmyr.ForgeryFactory @@ -47,7 +47,7 @@ internal class LogEventForgeryFactory : ForgeryFactory { id = userInfo?.id, name = userInfo?.name, email = userInfo?.email, - additionalProperties = userInfo?.additionalProperties.orEmpty() + additionalProperties = userInfo?.additionalProperties?.toMutableMap().orEmpty() ) }, diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/NetworkInfoForgeryFactory.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/NetworkInfoForgeryFactory.kt index 84f59763c4..645b09d5fd 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/NetworkInfoForgeryFactory.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/NetworkInfoForgeryFactory.kt @@ -6,7 +6,7 @@ package com.datadog.android.utils.forge -import com.datadog.android.core.model.NetworkInfo +import com.datadog.android.v2.api.context.NetworkInfo import fr.xgouchet.elmyr.Forge import fr.xgouchet.elmyr.ForgeryFactory diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/NetworkInfoV2ForgeryFactory.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/NetworkInfoV2ForgeryFactory.kt deleted file mode 100644 index 2264432909..0000000000 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/NetworkInfoV2ForgeryFactory.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. - * This product includes software developed at Datadog (https://www.datadoghq.com/). - * Copyright 2016-Present Datadog, Inc. - */ - -package com.datadog.android.utils.forge - -import com.datadog.android.v2.api.context.NetworkInfo -import fr.xgouchet.elmyr.Forge -import fr.xgouchet.elmyr.ForgeryFactory - -class NetworkInfoV2ForgeryFactory : ForgeryFactory { - override fun getForgery(forge: Forge): NetworkInfo { - return NetworkInfo( - connectivity = forge.aValueFrom(NetworkInfo.Connectivity::class.java), - carrierName = forge.aNullable { - anElementFrom( - anAlphabeticalString(), - aWhitespaceString() - ) - }, - carrierId = forge.aNullable { forge.aLong(0, 10000) }, - upKbps = forge.aNullable { aLong(1, Long.MAX_VALUE) }, - downKbps = forge.aNullable { aLong(1, Long.MAX_VALUE) }, - strength = forge.aNullable { aLong(-100, -30) }, // dBm for wifi signal - cellularTechnology = forge.aNullable { anAlphabeticalString() } - ) - } -} diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/SpanEventForgeryFactory.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/SpanEventForgeryFactory.kt index 8d9c230b97..b98dc247f9 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/SpanEventForgeryFactory.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/SpanEventForgeryFactory.kt @@ -8,9 +8,9 @@ package com.datadog.android.utils.forge import com.datadog.android.core.internal.utils.orEmpty import com.datadog.android.core.internal.utils.toMutableMap -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.tracing.model.SpanEvent +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import fr.xgouchet.elmyr.Forge import fr.xgouchet.elmyr.ForgeryFactory import java.util.concurrent.TimeUnit @@ -54,7 +54,7 @@ internal class SpanEventForgeryFactory : ForgeryFactory { id = userInfo?.id, name = userInfo?.name, email = userInfo?.email, - additionalProperties = userInfo?.additionalProperties.orEmpty() + additionalProperties = userInfo?.additionalProperties?.toMutableMap().orEmpty() ), network = SpanEvent.Network( SpanEvent.Client( diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/UserInfoForgeryFactory.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/UserInfoForgeryFactory.kt index 533ba5f422..add8bdd830 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/UserInfoForgeryFactory.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/UserInfoForgeryFactory.kt @@ -6,7 +6,7 @@ package com.datadog.android.utils.forge -import com.datadog.android.core.model.UserInfo +import com.datadog.android.v2.api.context.UserInfo import fr.xgouchet.elmyr.Forge import fr.xgouchet.elmyr.ForgeryFactory diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/UserInfoV2ForgeryFactory.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/UserInfoV2ForgeryFactory.kt deleted file mode 100644 index 6b4c56402b..0000000000 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/utils/forge/UserInfoV2ForgeryFactory.kt +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0. - * This product includes software developed at Datadog (https://www.datadoghq.com/). - * Copyright 2016-Present Datadog, Inc. - */ - -package com.datadog.android.utils.forge - -import com.datadog.android.v2.api.context.UserInfo -import fr.xgouchet.elmyr.Forge -import fr.xgouchet.elmyr.ForgeryFactory - -class UserInfoV2ForgeryFactory : ForgeryFactory { - override fun getForgery(forge: Forge): UserInfo { - return UserInfo( - id = forge.aNullable { anHexadecimalString() }, - name = forge.aNullable { forge.aStringMatching("[A-Z][a-z]+ [A-Z]\\. [A-Z][a-z]+") }, - email = forge.aNullable { forge.aStringMatching("[a-z]+\\.[a-z]+@[a-z]+\\.[a-z]{3}") }, - additionalProperties = forge.exhaustiveAttributes() - ) - } -} diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/model/NetworkInfoTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/api/context/NetworkInfoTest.kt similarity index 96% rename from dd-sdk-android/src/test/kotlin/com/datadog/android/core/model/NetworkInfoTest.kt rename to dd-sdk-android/src/test/kotlin/com/datadog/android/v2/api/context/NetworkInfoTest.kt index ad67186f87..0b87e9f7a6 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/model/NetworkInfoTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/api/context/NetworkInfoTest.kt @@ -4,7 +4,7 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.core.model +package com.datadog.android.v2.api.context import com.datadog.android.utils.forge.Configurator import fr.xgouchet.elmyr.annotation.Forgery diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/model/UserInfoTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/api/context/UserInfoTest.kt similarity index 96% rename from dd-sdk-android/src/test/kotlin/com/datadog/android/core/model/UserInfoTest.kt rename to dd-sdk-android/src/test/kotlin/com/datadog/android/v2/api/context/UserInfoTest.kt index 5fee8c6857..e4f2cf59c2 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/core/model/UserInfoTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/api/context/UserInfoTest.kt @@ -4,7 +4,7 @@ * Copyright 2016-Present Datadog, Inc. */ -package com.datadog.android.core.model +package com.datadog.android.v2.api.context import com.datadog.android.utils.forge.Configurator import fr.xgouchet.elmyr.annotation.Forgery diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/DatadogCoreTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/DatadogCoreTest.kt index 9e84c463cb..ae6472d940 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/DatadogCoreTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/DatadogCoreTest.kt @@ -15,10 +15,9 @@ import com.datadog.android.core.internal.SdkFeature import com.datadog.android.core.internal.privacy.ConsentProvider import com.datadog.android.core.internal.time.NoOpTimeProvider import com.datadog.android.core.internal.time.TimeProvider -import com.datadog.android.core.model.UserInfo +import com.datadog.android.core.internal.user.MutableUserInfoProvider import com.datadog.android.error.internal.CrashReportsFeature import com.datadog.android.log.internal.LogsFeature -import com.datadog.android.log.internal.user.MutableUserInfoProvider import com.datadog.android.plugin.DatadogContext import com.datadog.android.plugin.DatadogRumContext import com.datadog.android.privacy.TrackingConsent @@ -33,6 +32,7 @@ import com.datadog.android.utils.extension.mockChoreographerInstance import com.datadog.android.utils.forge.Configurator import com.datadog.android.v2.api.FeatureEventReceiver import com.datadog.android.v2.api.context.TimeInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.android.v2.core.internal.ContextProvider import com.datadog.android.webview.internal.log.WebViewLogsFeature import com.datadog.android.webview.internal.rum.WebViewRumFeature diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/internal/DatadogContextProviderTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/internal/DatadogContextProviderTest.kt index 9714e35ace..2665bde993 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/internal/DatadogContextProviderTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/internal/DatadogContextProviderTest.kt @@ -9,12 +9,12 @@ package com.datadog.android.v2.core.internal import android.app.Application import com.datadog.android.core.internal.CoreFeature import com.datadog.android.core.internal.system.AndroidInfoProvider -import com.datadog.android.core.model.NetworkInfo -import com.datadog.android.core.model.UserInfo import com.datadog.android.privacy.TrackingConsent import com.datadog.android.utils.config.ApplicationContextTestConfiguration import com.datadog.android.utils.config.CoreFeatureTestConfiguration import com.datadog.android.utils.forge.Configurator +import com.datadog.android.v2.api.context.NetworkInfo +import com.datadog.android.v2.api.context.UserInfo import com.datadog.tools.unit.annotations.TestConfigurationsProvider import com.datadog.tools.unit.extensions.TestConfigurationExtension import com.datadog.tools.unit.extensions.config.TestConfiguration diff --git a/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/internal/data/upload/DataUploadRunnableTest.kt b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/internal/data/upload/DataUploadRunnableTest.kt index 8eeee2acb1..14d80e7140 100644 --- a/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/internal/data/upload/DataUploadRunnableTest.kt +++ b/dd-sdk-android/src/test/kotlin/com/datadog/android/v2/core/internal/data/upload/DataUploadRunnableTest.kt @@ -11,9 +11,9 @@ import com.datadog.android.core.internal.net.UploadStatus import com.datadog.android.core.internal.net.info.NetworkInfoProvider import com.datadog.android.core.internal.system.SystemInfo import com.datadog.android.core.internal.system.SystemInfoProvider -import com.datadog.android.core.model.NetworkInfo import com.datadog.android.utils.forge.Configurator import com.datadog.android.v2.api.context.DatadogContext +import com.datadog.android.v2.api.context.NetworkInfo import com.datadog.android.v2.core.internal.ContextProvider import com.datadog.android.v2.core.internal.net.DataUploader import com.datadog.android.v2.core.internal.storage.BatchConfirmation diff --git a/detekt.yml b/detekt.yml index 99e6ad2cf6..e21e9f5846 100644 --- a/detekt.yml +++ b/detekt.yml @@ -687,6 +687,7 @@ datadog: - "java.util.zip.Deflater.deflate(kotlin.ByteArray, kotlin.Int, kotlin.Int, kotlin.Int):java.lang.IllegalArgumentException" # endregion # region Kotlin primitives + - "kotlin.Array.first(kotlin.Function1):java.util.NoSuchElementException" - "kotlin.String.get(kotlin.Int):java.lang.IndexOutOfBoundsException" - "kotlin.String.substring(kotlin.Int, kotlin.Int):java.lang.IndexOutOfBoundsException" - "kotlin.String.substring(kotlin.Int):java.lang.IndexOutOfBoundsException" @@ -1273,6 +1274,7 @@ datadog: - "com.google.gson.JsonArray.addAll(com.google.gson.JsonArray)" - "com.google.gson.JsonArray.add(kotlin.String)" - "com.google.gson.JsonArray.map(kotlin.Function1)" + - "com.google.gson.JsonParseException.constructor(kotlin.String, kotlin.Throwable)" - "com.google.gson.JsonParseException.constructor(kotlin.Throwable)" # endregion # region Kronos