Skip to content

Commit 1f8c298

Browse files
authored
Releases/v1.7.1
## Improvements * Report disconnected network as `no_connection` instead of a null value (#92)
1 parent 931a741 commit 1f8c298

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

library/src/main/java/com/mux/stats/sdk/muxstats/MuxDataSdk.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,8 @@ abstract class MuxDataSdk<Player, PlayerView : View> @JvmOverloads protected con
576576
val connectivityManager = context.getSystemService(ConnectivityManager::class.java)
577577
val nc: NetworkCapabilities? =
578578
connectivityManager.getNetworkCapabilities(connectivityManager.activeNetwork)
579-
nc?.toMuxConnectionType()
579+
580+
/*return*/ nc?.toMuxConnectionType() ?: NetworkChangeMonitor.CONNECTION_TYPE_NONE
580581
}
581582
}
582583

library/src/main/java/com/mux/stats/sdk/muxstats/NetworkMonitor.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface NetworkChangeMonitor {
2424
const val CONNECTION_TYPE_WIFI = "wifi"
2525
const val CONNECTION_TYPE_WIRED = "wired"
2626
const val CONNECTION_TYPE_OTHER = "other"
27+
const val CONNECTION_TYPE_NONE = "no_connection"
2728
}
2829

2930
fun setListener(listener: NetworkChangedListener?)
@@ -103,10 +104,10 @@ private class NetworkChangeMonitorApi16(
103104
return context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
104105
}
105106

106-
private fun currentConnectionType(): String? {
107+
private fun currentConnectionType(): String {
107108
val networkInfo = getConnectivityManager(appContext).activeNetworkInfo
108109
val connType = networkInfo?.toMuxConnectionType()
109-
return connType
110+
return connType ?: NetworkChangeMonitor.CONNECTION_TYPE_NONE
110111
}
111112

112113
override fun setListener(listener: NetworkChangeMonitor.NetworkChangedListener?) {
@@ -195,7 +196,12 @@ private class NetworkChangeMonitorApi26(
195196
}
196197

197198
override fun onLost(network: Network) {
198-
callbackHandler.post { outsideListener?.onNetworkChanged(null, null) }
199+
callbackHandler.post {
200+
outsideListener?.onNetworkChanged(
201+
networkType = NetworkChangeMonitor.CONNECTION_TYPE_NONE,
202+
restrictedData = null
203+
)
204+
}
199205
}
200206
}
201207

0 commit comments

Comments
 (0)