@datadog/mobile-react-native 2.2.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/DatadogSDKReactNative.podspec +2 -1
  2. package/android/build.gradle +1 -0
  3. package/android/src/main/kotlin/com/datadog/reactnative/DatadogSDKWrapper.kt +2 -0
  4. package/android/src/main/kotlin/com/datadog/reactnative/DatadogWrapper.kt +11 -1
  5. package/android/src/main/kotlin/com/datadog/reactnative/DdLogsImplementation.kt +5 -0
  6. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfiguration.kt +64 -1
  7. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkConfigurationExt.kt +164 -4
  8. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkImplementation.kt +6 -354
  9. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkNativeInitialization.kt +351 -0
  10. package/android/src/main/kotlin/com/datadog/reactnative/DdSdkReactNativePackage.kt +5 -3
  11. package/android/src/main/kotlin/com/datadog/reactnative/DdTraceImplementation.kt +10 -0
  12. package/android/src/main/kotlin/com/datadog/reactnative/JSONFileReader.kt +20 -0
  13. package/android/src/main/kotlin/com/datadog/reactnative/ProxyAuthenticator.kt +4 -1
  14. package/android/src/main/kotlin/com/datadog/reactnative/SdkVersion.kt +10 -0
  15. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdLogs.kt +3 -2
  16. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdRum.kt +5 -2
  17. package/android/src/oldarch/kotlin/com/datadog/reactnative/DdSdk.kt +3 -2
  18. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkConfigurationTest.kt +196 -0
  19. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkNativeInitializationTest.kt +181 -0
  20. package/android/src/test/kotlin/com/datadog/reactnative/DdSdkTest.kt +12 -271
  21. package/android/src/test/kotlin/com/datadog/reactnative/DdTraceTest.kt +10 -0
  22. package/android/src/test/kotlin/com/datadog/tools/unit/DdSdkConfigurationExt.kt +28 -1
  23. package/android/src/test/kotlin/com/datadog/tools/unit/MapExt.kt +24 -0
  24. package/android/src/test/kotlin/com/datadog/tools/unit/forge/DdSdkConfigurationForgeryFactory.kt +9 -1
  25. package/android/src/test/resources/input/complete-configuration.json +48 -0
  26. package/android/src/test/resources/input/malformed-configuration.json +5 -0
  27. package/android/src/test/resources/input/minimal-configuration.json +8 -0
  28. package/datadog-configuration.gradle +57 -0
  29. package/datadog-configuration.schema.json +200 -0
  30. package/ios/Sources/DatadogSDKWrapper.swift +16 -13
  31. package/ios/Sources/DdLogsImplementation.swift +14 -0
  32. package/ios/Sources/DdSdk.h +2 -0
  33. package/ios/Sources/DdSdk.mm +6 -1
  34. package/ios/Sources/DdSdkConfiguration.swift +47 -56
  35. package/ios/Sources/DdSdkImplementation.swift +10 -279
  36. package/ios/Sources/DdSdkNativeInitialization.swift +218 -0
  37. package/ios/Sources/DdTraceImplementation.swift +3 -1
  38. package/ios/Sources/GlobalState.swift +1 -1
  39. package/ios/Sources/JSONFileReader.swift +28 -0
  40. package/ios/Sources/RNDdSdkConfiguration.swift +227 -9
  41. package/ios/Sources/SdkVersion.swift +10 -0
  42. package/lib/commonjs/DdSdkReactNative.js +24 -66
  43. package/lib/commonjs/DdSdkReactNative.js.map +1 -1
  44. package/lib/commonjs/DdSdkReactNativeConfiguration.js +24 -4
  45. package/lib/commonjs/DdSdkReactNativeConfiguration.js.map +1 -1
  46. package/lib/commonjs/ProxyConfiguration.js +15 -2
  47. package/lib/commonjs/ProxyConfiguration.js.map +1 -1
  48. package/lib/commonjs/index.js +8 -0
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/commonjs/nativeModulesTypes.js +2 -2
  51. package/lib/commonjs/nativeModulesTypes.js.map +1 -1
  52. package/lib/commonjs/sdk/DatadogProvider/DatadogProvider.js.map +1 -1
  53. package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js +214 -0
  54. package/lib/commonjs/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -0
  55. package/lib/commonjs/types.js +10 -2
  56. package/lib/commonjs/types.js.map +1 -1
  57. package/lib/commonjs/version.js +1 -1
  58. package/lib/commonjs/version.js.map +1 -1
  59. package/lib/module/DdSdkReactNative.js +23 -65
  60. package/lib/module/DdSdkReactNative.js.map +1 -1
  61. package/lib/module/DdSdkReactNativeConfiguration.js +22 -4
  62. package/lib/module/DdSdkReactNativeConfiguration.js.map +1 -1
  63. package/lib/module/ProxyConfiguration.js +15 -2
  64. package/lib/module/ProxyConfiguration.js.map +1 -1
  65. package/lib/module/index.js +2 -1
  66. package/lib/module/index.js.map +1 -1
  67. package/lib/module/nativeModulesTypes.js +2 -2
  68. package/lib/module/nativeModulesTypes.js.map +1 -1
  69. package/lib/module/sdk/DatadogProvider/DatadogProvider.js.map +1 -1
  70. package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js +197 -0
  71. package/lib/module/sdk/FileBasedConfiguration/FileBasedConfiguration.js.map +1 -0
  72. package/lib/module/types.js +10 -2
  73. package/lib/module/types.js.map +1 -1
  74. package/lib/module/version.js +1 -1
  75. package/lib/module/version.js.map +1 -1
  76. package/lib/typescript/DdSdkReactNative.d.ts +0 -9
  77. package/lib/typescript/DdSdkReactNativeConfiguration.d.ts +43 -3
  78. package/lib/typescript/ProxyConfiguration.d.ts +4 -12
  79. package/lib/typescript/index.d.ts +2 -1
  80. package/lib/typescript/nativeModulesTypes.d.ts +2 -2
  81. package/lib/typescript/sdk/DatadogProvider/DatadogProvider.d.ts +2 -1
  82. package/lib/typescript/sdk/FileBasedConfiguration/FileBasedConfiguration.d.ts +31 -0
  83. package/lib/typescript/types.d.ts +29 -3
  84. package/lib/typescript/version.d.ts +1 -1
  85. package/package.json +7 -4
  86. package/src/DdSdkReactNative.tsx +58 -101
  87. package/src/DdSdkReactNativeConfiguration.tsx +26 -7
  88. package/src/ProxyConfiguration.tsx +17 -3
  89. package/src/__tests__/DdSdkReactNative.test.tsx +134 -112
  90. package/src/__tests__/DdSdkReactNativeConfiguration.test.ts +19 -10
  91. package/src/__tests__/mock.test.ts +0 -9
  92. package/src/index.tsx +2 -0
  93. package/src/nativeModulesTypes.ts +1 -1
  94. package/src/sdk/DatadogProvider/DatadogProvider.tsx +3 -1
  95. package/src/sdk/DatadogProvider/__tests__/initialization.test.tsx +12 -5
  96. package/src/sdk/DatadogProvider/__tests__/initializationModes.test.tsx +1 -2
  97. package/src/sdk/FileBasedConfiguration/FileBasedConfiguration.ts +235 -0
  98. package/src/sdk/FileBasedConfiguration/__tests__/FileBasedConfiguration.test.ts +245 -0
  99. package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/configuration-all-fields.json +22 -0
  100. package/src/sdk/FileBasedConfiguration/__tests__/__fixtures__/malformed-configuration.json +5 -0
  101. package/src/types.tsx +21 -2
  102. package/src/version.ts +1 -1
@@ -27,7 +27,8 @@ Pod::Spec.new do |s|
27
27
  s.dependency 'DatadogWebViewTracking', '~> 2.7.1'
28
28
 
29
29
  s.test_spec 'Tests' do |test_spec|
30
- test_spec.source_files = 'ios/Tests/*.swift'
30
+ test_spec.source_files = 'ios/Tests/**/*.{swift,json}'
31
+ test_spec.resources = 'ios/Tests/Fixtures'
31
32
  end
32
33
 
33
34
 
@@ -190,6 +190,7 @@ dependencies {
190
190
  implementation "com.datadoghq:dd-sdk-android-logs:2.6.2"
191
191
  implementation "com.datadoghq:dd-sdk-android-trace:2.6.2"
192
192
  implementation "com.datadoghq:dd-sdk-android-webview:2.6.2"
193
+ implementation "com.google.code.gson:gson:2.10.0"
193
194
  testImplementation "org.junit.platform:junit-platform-launcher:1.6.2"
194
195
  testImplementation "org.junit.jupiter:junit-jupiter-api:5.6.2"
195
196
  testImplementation "org.junit.jupiter:junit-jupiter-engine:5.6.2"
@@ -70,6 +70,8 @@ object DatadogSDKWrapperStorage {
70
70
  }
71
71
 
72
72
  internal class DatadogSDKWrapper : DatadogWrapper {
73
+ override var bundleLogsWithRum = DefaultConfiguration.bundleLogsWithRum
74
+ override var bundleLogsWithTraces = DefaultConfiguration.bundleLogsWithTraces
73
75
 
74
76
  // We use Kotlin backing field here to initialize once the telemetry proxy
75
77
  // and make sure it is only after SDK is initialized.
@@ -10,7 +10,6 @@ import android.content.Context
10
10
  import com.datadog.android.core.configuration.Configuration
11
11
  import com.datadog.android.log.LogsConfiguration
12
12
  import com.datadog.android.privacy.TrackingConsent
13
- import com.datadog.android.rum.GlobalRumMonitor
14
13
  import com.datadog.android.rum.RumConfiguration
15
14
  import com.datadog.android.rum.RumMonitor
16
15
  import com.datadog.android.trace.TraceConfiguration
@@ -21,6 +20,17 @@ import java.lang.IllegalArgumentException
21
20
  */
22
21
  @Suppress("ComplexInterface", "TooManyFunctions")
23
22
  interface DatadogWrapper {
23
+ /**
24
+ * Enables RUM for logs.
25
+ * By default, RUM is enabled for logs.
26
+ */
27
+ var bundleLogsWithRum : Boolean
28
+
29
+ /**
30
+ * Enables Traces for logs.
31
+ * By default, Traces is enabled for logs.
32
+ */
33
+ var bundleLogsWithTraces : Boolean
24
34
 
25
35
  /**
26
36
  * Sets the verbosity of the Datadog library.
@@ -19,8 +19,13 @@ class DdLogsImplementation(
19
19
  private val datadog: DatadogWrapper = DatadogSDKWrapper()
20
20
  ) {
21
21
  private val reactNativeLogger: Logger by lazy {
22
+ val bundleLogsWithRum = datadog.bundleLogsWithRum
23
+ val bundleLogsWithTraces = datadog.bundleLogsWithTraces
24
+
22
25
  logger ?: Logger.Builder(DatadogSDKWrapperStorage.getSdkCore())
23
26
  .setLogcatLogsEnabled(true)
27
+ .setBundleWithRumEnabled(bundleLogsWithRum)
28
+ .setBundleWithTraceEnabled(bundleLogsWithTraces)
24
29
  .setName("DdLogs")
25
30
  .build()
26
31
  }
@@ -6,6 +6,9 @@
6
6
 
7
7
  package com.datadog.reactnative
8
8
 
9
+ import com.datadog.android.trace.TracingHeaderType
10
+ import java.net.Proxy
11
+
9
12
  /**
10
13
  * A configuration object to initialize Datadog's features.
11
14
  * @param clientToken A valid Datadog client token.
@@ -26,6 +29,14 @@ package com.datadog.reactnative
26
29
  * @param customEndpoints Custom endpoints for RUM/Logs/Trace features.
27
30
  * @param additionalConfig Additional configuration parameters.
28
31
  * @param configurationForTelemetry Additional configuration data for Datadog telemetry.
32
+ * @param nativeViewTracking Enables/Disables tracking RUM Views on the native level.
33
+ * @param nativeInteractionTracking Enables/Disables tracking RUM Actions on the native level.
34
+ * @param verbosity Verbosity level of the SDK.
35
+ * @param proxyConfig Configuration for proxying SDK data.
36
+ * @param serviceName Custom service name.
37
+ * @param firstPartyHosts List of backend hosts to enable tracing with.
38
+ * @param bundleLogsWithRum Enables RUM correlation with logs.
39
+ * @param bundleLogsWithTraces Enables Traces correlation with logs.
29
40
  */
30
41
  data class DdSdkConfiguration(
31
42
  val clientToken: String,
@@ -45,7 +56,59 @@ data class DdSdkConfiguration(
45
56
  val trackBackgroundEvents: Boolean? = null,
46
57
  val customEndpoints: CustomEndpoints? = null,
47
58
  val additionalConfig: Map<String, Any?>? = null,
48
- val configurationForTelemetry: ConfigurationForTelemetry? = null
59
+ val configurationForTelemetry: ConfigurationForTelemetry? = null,
60
+ val nativeViewTracking: Boolean? = null,
61
+ val nativeInteractionTracking: Boolean? = null,
62
+ val verbosity: String? = null,
63
+ val proxyConfig: Pair<Proxy, ProxyAuthenticator?>? = null,
64
+ val serviceName: String? = null,
65
+ val firstPartyHosts: Map<String, Set<TracingHeaderType>>? = null,
66
+ val bundleLogsWithRum: Boolean? = null,
67
+ val bundleLogsWithTraces: Boolean? = null
68
+ )
69
+
70
+ internal data class JSONConfigurationFile(
71
+ val configuration: JSONDdSdkConfiguration
72
+ )
73
+
74
+ internal data class JSONDdSdkConfiguration(
75
+ val clientToken: String,
76
+ val env: String,
77
+ val applicationId: String,
78
+ val nativeCrashReportEnabled: Boolean? = null,
79
+ val nativeLongTaskThresholdMs: Double? = null,
80
+ val longTaskThresholdMs: Double? = null,
81
+ val sessionSamplingRate: Double? = null,
82
+ val site: String? = null,
83
+ val trackingConsent: String? = null,
84
+ val telemetrySampleRate: Double? = null,
85
+ val vitalsUpdateFrequency: String? = null,
86
+ val trackFrustrations: Boolean? = null,
87
+ val uploadFrequency: String? = null,
88
+ val batchSize: String? = null,
89
+ val trackBackgroundEvents: Boolean? = null,
90
+ val customEndpoints: CustomEndpoints? = null,
91
+ val nativeViewTracking: Boolean? = null,
92
+ val nativeInteractionTracking: Boolean? = null,
93
+ val verbosity: String? = null,
94
+ val proxy: JSONProxyConfiguration? = null,
95
+ val serviceName: String? = null,
96
+ val firstPartyHosts: List<JSONFirstPartyHost>? = null,
97
+ val bundleLogsWithRum: Boolean? = null,
98
+ val bundleLogsWithTraces: Boolean? = null
99
+ )
100
+
101
+ internal data class JSONProxyConfiguration(
102
+ val type: String,
103
+ val address: String,
104
+ val port: Int,
105
+ val username: String? = null,
106
+ val password: String? = null
107
+ )
108
+
109
+ internal data class JSONFirstPartyHost(
110
+ val match: String,
111
+ val propagatorTypes: List<String>
49
112
  )
50
113
 
51
114
  /**
@@ -4,12 +4,17 @@
4
4
  * Copyright 2016-Present Datadog, Inc.
5
5
  */
6
6
 
7
+ @file:Suppress("TooManyFunctions")
7
8
  package com.datadog.reactnative
8
9
 
10
+ import android.util.Log
9
11
  import com.datadog.android.trace.TracingHeaderType
10
12
  import com.facebook.react.bridge.ReadableArray
11
13
  import com.facebook.react.bridge.ReadableMap
12
14
  import com.facebook.react.bridge.WritableNativeMap
15
+ import java.net.InetSocketAddress
16
+ import java.net.Proxy
17
+ import java.util.Locale
13
18
 
14
19
  internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
15
20
  return DdSdkConfiguration(
@@ -32,7 +37,15 @@ internal fun ReadableMap.asDdSdkConfiguration(): DdSdkConfiguration {
32
37
  additionalConfig = getMap("additionalConfig")?.toHashMap(),
33
38
  configurationForTelemetry = getMap(
34
39
  "configurationForTelemetry"
35
- )?.asConfigurationForTelemetry()
40
+ )?.asConfigurationForTelemetry(),
41
+ nativeViewTracking = getBoolean("nativeViewTracking"),
42
+ nativeInteractionTracking = getBoolean("nativeInteractionTracking"),
43
+ verbosity = getString("verbosity"),
44
+ proxyConfig = getMap("proxyConfig")?.asProxyConfig(),
45
+ serviceName = getString("serviceName"),
46
+ firstPartyHosts = getArray("firstPartyHosts")?.asFirstPartyHosts(),
47
+ bundleLogsWithRum = getBoolean("bundleLogsWithRum"),
48
+ bundleLogsWithTraces = getBoolean("bundleLogsWithTraces")
36
49
  )
37
50
  }
38
51
 
@@ -55,9 +68,127 @@ internal fun ReadableMap.asCustomEndpoints(): CustomEndpoints {
55
68
  )
56
69
  }
57
70
 
58
- internal fun ReadableArray.asTracingHeaderTypes(): Set<TracingHeaderType> {
59
- return this.toArrayList().mapNotNull {
60
- when (it) {
71
+ @Suppress("ComplexMethod")
72
+ internal fun ReadableMap.asProxyConfig(): Pair<Proxy, ProxyAuthenticator?>? {
73
+ val address: String? = getString("address")
74
+
75
+ // getInt expects the value to be non-null
76
+ var port: Int? = null
77
+ if (hasKey("port")) {
78
+ port = getInt("port")
79
+ }
80
+
81
+ val type = getString("type")
82
+
83
+ return if (address != null && port != null && type != null) {
84
+ buildProxyConfig(
85
+ type,
86
+ address,
87
+ port,
88
+ getString("username"),
89
+ getString("password")
90
+ )
91
+ } else {
92
+ null
93
+ }
94
+ }
95
+
96
+ internal fun ReadableArray.asFirstPartyHosts(): Map<String, Set<TracingHeaderType>> {
97
+ val firstPartyHosts = this.toArrayList() as List<ReadableMap>
98
+ return firstPartyHosts.mapNotNull<ReadableMap, JSONFirstPartyHost> {
99
+ val match = it.getString("match")
100
+ val propagatorTypes = it.getArray("propagatorTypes")
101
+ if (match != null && propagatorTypes != null) {
102
+ JSONFirstPartyHost(match, propagatorTypes.toArrayList() as List<String>)
103
+ } else null
104
+ }.asFirstPartyHosts()
105
+ }
106
+
107
+ internal object DefaultConfiguration {
108
+ const val nativeCrashReportEnabled = false
109
+ const val sessionSamplingRate = 100.0
110
+ const val site = "US1"
111
+ const val longTaskThresholdMs = 0.0
112
+ const val nativeLongTaskThresholdMs = 200.0
113
+ const val nativeViewTracking = false
114
+ const val nativeInteractionTracking = false
115
+ const val trackingConsent = "GRANTED"
116
+ const val telemetrySampleRate = 20.0
117
+ const val vitalsUpdateFrequency = "AVERAGE"
118
+ const val trackFrustrations = true
119
+ const val uploadFrequency = "AVERAGE"
120
+ const val batchSize = "MEDIUM"
121
+ const val trackBackgroundEvents = false
122
+ const val bundleLogsWithRum = true
123
+ const val bundleLogsWithTraces = true
124
+ }
125
+
126
+ @Suppress("ComplexMethod")
127
+ internal fun JSONDdSdkConfiguration.asDdSdkConfiguration(): DdSdkConfiguration {
128
+ return DdSdkConfiguration(
129
+ this.clientToken,
130
+ this.env,
131
+ this.applicationId,
132
+ this.nativeCrashReportEnabled ?: DefaultConfiguration.nativeCrashReportEnabled,
133
+ this.nativeLongTaskThresholdMs ?: DefaultConfiguration.nativeLongTaskThresholdMs,
134
+ this.longTaskThresholdMs ?: DefaultConfiguration.longTaskThresholdMs,
135
+ this.sessionSamplingRate ?: DefaultConfiguration.sessionSamplingRate,
136
+ this.site ?: DefaultConfiguration.site,
137
+ this.trackingConsent ?: DefaultConfiguration.trackingConsent,
138
+ this.telemetrySampleRate ?: DefaultConfiguration.telemetrySampleRate,
139
+ this.vitalsUpdateFrequency ?: DefaultConfiguration.vitalsUpdateFrequency,
140
+ this.trackFrustrations ?: DefaultConfiguration.trackFrustrations,
141
+ this.uploadFrequency ?: DefaultConfiguration.uploadFrequency,
142
+ this.batchSize ?: DefaultConfiguration.batchSize,
143
+ this.trackBackgroundEvents ?: DefaultConfiguration.trackBackgroundEvents,
144
+ this.customEndpoints,
145
+ mapOf(
146
+ "_dd.source" to "react-native",
147
+ "_dd.sdk_version" to SDK_VERSION
148
+ ),
149
+ null,
150
+ this.nativeViewTracking ?: DefaultConfiguration.nativeViewTracking,
151
+ this.nativeInteractionTracking ?: DefaultConfiguration.nativeInteractionTracking,
152
+ this.verbosity,
153
+ this.proxy?.asProxyConfig(),
154
+ this.serviceName,
155
+ this.firstPartyHosts?.asFirstPartyHosts(),
156
+ this.bundleLogsWithRum ?: DefaultConfiguration.bundleLogsWithRum,
157
+ this.bundleLogsWithTraces ?: DefaultConfiguration.bundleLogsWithTraces
158
+ )
159
+ }
160
+
161
+ internal fun JSONProxyConfiguration.asProxyConfig(): Pair<Proxy, ProxyAuthenticator?>? {
162
+ return buildProxyConfig(type, address, port, username, password)
163
+ }
164
+
165
+ internal fun List<JSONFirstPartyHost>.asFirstPartyHosts(): Map<String, Set<TracingHeaderType>> {
166
+ /**
167
+ * Adapts the data format from the React Native SDK configuration to match with the Android
168
+ * SDK configuration. For example:
169
+ *
170
+ * RN config: [{ match: "example.com", propagatorTypes: [DATADOG, B3] }] Android config: {
171
+ * "example.com": [DATADOG, B3] }
172
+ */
173
+ val firstPartyHostsWithHeaderTypes = mutableMapOf<String, MutableSet<TracingHeaderType>>()
174
+
175
+ for (host in this) {
176
+ if (host.propagatorTypes.isNotEmpty()) {
177
+ val hostMatch = firstPartyHostsWithHeaderTypes[host.match]
178
+ if (hostMatch != null) {
179
+ hostMatch.addAll(host.propagatorTypes.asTracingHeaderTypes())
180
+ } else {
181
+ firstPartyHostsWithHeaderTypes[host.match] = host.propagatorTypes.asTracingHeaderTypes().toMutableSet()
182
+ }
183
+ }
184
+ }
185
+
186
+ return firstPartyHostsWithHeaderTypes
187
+ }
188
+
189
+ internal fun List<String>.asTracingHeaderTypes(): Set<TracingHeaderType> {
190
+ return this.mapNotNull {
191
+ when (it.lowercase()) {
61
192
  "datadog" -> TracingHeaderType.DATADOG
62
193
  "b3" -> TracingHeaderType.B3
63
194
  "b3multi" -> TracingHeaderType.B3MULTI
@@ -107,3 +238,32 @@ internal fun CustomEndpoints.toReadableMap(): ReadableMap {
107
238
  trace?.let { map.putString("trace", it) }
108
239
  return map
109
240
  }
241
+
242
+ private fun buildProxyConfig(type: String, address: String, port: Int, username: String?, password: String?): Pair<Proxy, ProxyAuthenticator?>? {
243
+ val proxyType = when (type.lowercase(Locale.US)) {
244
+ "http", "https" -> Proxy.Type.HTTP
245
+ "socks" -> Proxy.Type.SOCKS
246
+ else -> {
247
+ Log.w(
248
+ DdSdk::class.java.canonicalName,
249
+ "Unknown proxy type given: $type, skipping proxy configuration."
250
+ )
251
+ null
252
+ }
253
+ }
254
+
255
+ if (proxyType == null) {
256
+ return null
257
+ }
258
+
259
+ val proxy = Proxy(proxyType, InetSocketAddress(address, port))
260
+
261
+ val authenticator =
262
+ if (username != null && password != null) {
263
+ ProxyAuthenticator(username, password)
264
+ } else {
265
+ null
266
+ }
267
+
268
+ return Pair(proxy, authenticator)
269
+ }