Skip to content

Commit b516483

Browse files
committed
Some more fixes
1 parent 5c6b574 commit b516483

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

android/lib/talpid/src/main/kotlin/net/mullvad/talpid/ConnectivityListener.kt

+13-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.net.ConnectivityManager
44
import android.net.LinkProperties
55
import android.net.Network
66
import android.net.NetworkCapabilities
7+
import co.touchlab.kermit.Logger
78
import java.net.DatagramSocket
89
import java.net.Inet4Address
910
import java.net.Inet6Address
@@ -88,12 +89,19 @@ class ConnectivityListener(
8889
}
8990

9091
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"
96103
)
104+
null
97105
}
98106

99107
private fun RawNetworkState?.toConnectivity(): Connectivity.Status =
@@ -115,8 +123,6 @@ class ConnectivityListener(
115123
this?.linkProperties?.routes?.any { it.destination.address is Inet6Address } ==
116124
true,
117125
)
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.
120126
}
121127

122128
/**

0 commit comments

Comments
 (0)