fix NPE in NetworkChangeReceiver

This commit is contained in:
Milos Kozak 2020-04-21 22:02:38 +02:00
parent ee13848928
commit 733370a126

View file

@ -29,7 +29,7 @@ class NetworkChangeReceiver : DaggerBroadcastReceiver() {
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networks: Array<Network> = cm.allNetworks val networks: Array<Network> = cm.allNetworks
networks.forEach { networks.forEach {
val capabilities = cm.getNetworkCapabilities(it) val capabilities = cm.getNetworkCapabilities(it) ?: return@forEach
event.wifiConnected = event.wifiConnected || (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI) event.wifiConnected = event.wifiConnected || (capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)
|| capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET)) || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_ETHERNET))
event.mobileConnected = event.mobileConnected || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) event.mobileConnected = event.mobileConnected || capabilities.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)