@@ -4,6 +4,7 @@ import android.net.ConnectivityManager
4
4
import android.net.LinkProperties
5
5
import android.net.Network
6
6
import android.net.NetworkCapabilities
7
+ import co.touchlab.kermit.Logger
7
8
import java.net.DatagramSocket
8
9
import java.net.Inet4Address
9
10
import java.net.Inet6Address
@@ -88,12 +89,19 @@ class ConnectivityListener(
88
89
}
89
90
90
91
private fun ConnectivityManager.activeRawNetworkState (): RawNetworkState ? =
91
- activeNetwork?.let { initialNetwork: Network ->
92
- RawNetworkState (
93
- network = initialNetwork,
94
- linkProperties = getLinkProperties(initialNetwork),
95
- networkCapabilities = getNetworkCapabilities(initialNetwork),
92
+ try {
93
+ activeNetwork?.let { initialNetwork: Network ->
94
+ RawNetworkState (
95
+ network = initialNetwork,
96
+ linkProperties = getLinkProperties(initialNetwork),
97
+ networkCapabilities = getNetworkCapabilities(initialNetwork),
98
+ )
99
+ }
100
+ } catch (_: RuntimeException ) {
101
+ Logger .e(
102
+ " Unable to get active network or properties and capabilities of the active network"
96
103
)
104
+ null
97
105
}
98
106
99
107
private fun RawNetworkState?.toConnectivity (): Connectivity .Status =
@@ -115,8 +123,6 @@ class ConnectivityListener(
115
123
this ?.linkProperties?.routes?.any { it.destination.address is Inet6Address } ==
116
124
true ,
117
125
)
118
- // If we have internet, but both IPv4 and IPv6 are not available, we
119
- // assume something is wrong and instead will return presume online.
120
126
}
121
127
122
128
/* *
0 commit comments