@@ -350,6 +350,43 @@ internal fun NetworkInfo.toActionConnectivity(): ActionEvent.Connectivity {
350350 )
351351}
352352
353+ internal fun NetworkInfo.toVitalConnectivity (): VitalEvent .Connectivity {
354+ val status = if (isConnected()) {
355+ VitalEvent .Status .CONNECTED
356+ } else {
357+ VitalEvent .Status .NOT_CONNECTED
358+ }
359+ val interfaces = when (connectivity) {
360+ NetworkInfo .Connectivity .NETWORK_ETHERNET -> listOf (VitalEvent .Interface .ETHERNET )
361+ NetworkInfo .Connectivity .NETWORK_WIFI -> listOf (VitalEvent .Interface .WIFI )
362+ NetworkInfo .Connectivity .NETWORK_WIMAX -> listOf (VitalEvent .Interface .WIMAX )
363+ NetworkInfo .Connectivity .NETWORK_BLUETOOTH -> listOf (VitalEvent .Interface .BLUETOOTH )
364+ NetworkInfo .Connectivity .NETWORK_2G ,
365+ NetworkInfo .Connectivity .NETWORK_3G ,
366+ NetworkInfo .Connectivity .NETWORK_4G ,
367+ NetworkInfo .Connectivity .NETWORK_5G ,
368+ NetworkInfo .Connectivity .NETWORK_MOBILE_OTHER ,
369+ NetworkInfo .Connectivity .NETWORK_CELLULAR -> listOf (VitalEvent .Interface .CELLULAR )
370+
371+ NetworkInfo .Connectivity .NETWORK_OTHER -> listOf (VitalEvent .Interface .OTHER )
372+ NetworkInfo .Connectivity .NETWORK_NOT_CONNECTED -> emptyList()
373+ }
374+
375+ val cellular = if (cellularTechnology != null || carrierName != null ) {
376+ VitalEvent .Cellular (
377+ technology = cellularTechnology,
378+ carrierName = carrierName
379+ )
380+ } else {
381+ null
382+ }
383+ return VitalEvent .Connectivity (
384+ status,
385+ interfaces,
386+ cellular = cellular
387+ )
388+ }
389+
353390internal fun NetworkInfo.isConnected (): Boolean {
354391 return connectivity != NetworkInfo .Connectivity .NETWORK_NOT_CONNECTED
355392}
@@ -418,6 +455,18 @@ internal fun DeviceType.toErrorSchemaType(): ErrorEvent.DeviceType {
418455 }
419456}
420457
458+ internal fun DeviceType.toVitalSchemaType (): VitalEvent .DeviceType {
459+ return when (this ) {
460+ DeviceType .MOBILE -> VitalEvent .DeviceType .MOBILE
461+ DeviceType .TABLET -> VitalEvent .DeviceType .TABLET
462+ DeviceType .TV -> VitalEvent .DeviceType .TV
463+ DeviceType .DESKTOP -> VitalEvent .DeviceType .DESKTOP
464+ DeviceType .GAMING_CONSOLE -> VitalEvent .DeviceType .GAMING_CONSOLE
465+ DeviceType .BOT -> VitalEvent .DeviceType .BOT
466+ DeviceType .OTHER -> VitalEvent .DeviceType .OTHER
467+ }
468+ }
469+
421470// endregion
422471
423472// region Source
@@ -507,6 +556,23 @@ internal fun ResourceEvent.ResourceEventSource.Companion.tryFromSource(
507556 }
508557}
509558
559+ internal fun VitalEvent.VitalEventSource.Companion.tryFromSource (
560+ source : String ,
561+ internalLogger : InternalLogger
562+ ): VitalEvent .VitalEventSource ? {
563+ return try {
564+ fromJson(source)
565+ } catch (e: NoSuchElementException ) {
566+ internalLogger.log(
567+ InternalLogger .Level .ERROR ,
568+ InternalLogger .Target .USER ,
569+ { UNKNOWN_SOURCE_WARNING_MESSAGE_FORMAT .format(Locale .US , source) },
570+ e
571+ )
572+ null
573+ }
574+ }
575+
510576internal const val UNKNOWN_SOURCE_WARNING_MESSAGE_FORMAT = " You are using an unknown " +
511577 " source %s for your events"
512578
0 commit comments