summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-09-30 09:14:08 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-09-30 09:14:08 +0200
commitfb1271119cc886afbcdc7c4c0657ed1fd3445185 (patch)
tree74d6314434973d1569ff94ba65a4d2532401c5a6
parent238db87df06e65d8ce1aa1b9b6f587e60994f876 (diff)
parent3c6f861ed711df7412240ad699ba3fb072504411 (diff)
downloadmullvadvpn-fb1271119cc886afbcdc7c4c0657ed1fd3445185.tar.xz
mullvadvpn-fb1271119cc886afbcdc7c4c0657ed1fd3445185.zip
Merge branch 'default-network-is-not-updating-correctly-when-vpn-is-droid-2055'
-rw-r--r--android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/ConnectivityManagerUtil.kt10
-rw-r--r--android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/UnderlyingConnectivityStatusResolver.kt13
2 files changed, 19 insertions, 4 deletions
diff --git a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/ConnectivityManagerUtil.kt b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/ConnectivityManagerUtil.kt
index 923aca44fb..bc6a488f7b 100644
--- a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/ConnectivityManagerUtil.kt
+++ b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/ConnectivityManagerUtil.kt
@@ -74,7 +74,7 @@ fun ConnectivityManager.defaultNetworkEvents(): Flow<NetworkEvent> =
awaitClose { unregisterNetworkCallback(callback) }
}
- .onEach { Logger.d("Got a default network event type: ${it::class.simpleName}") }
+ .onEach { Logger.i("Got a default network event type: ${it::class.simpleName}") }
fun ConnectivityManager.nonVpnInternetNetworksEvents(): Flow<NetworkEvent> =
callbackFlow {
@@ -203,6 +203,13 @@ internal fun ConnectivityManager.activeRawNetworkState(): RawNetworkState? =
* with the default network not being updated correctly on Android 9 and below when the VPN is
* turned on. The non-VPN network event is not used it is just there to trigger a new connectivity
* check.
+ *
+ * Note: While the use of a combine of non-VPN networks and default network flows is primarily to
+ * fix issues on Android 8 and 9, we have seen similar user reports on newer versions of Android as
+ * well. When we stop supporting Android 8 and 9 and decide to remove this fix we should make sure
+ * that it won't cause issues for users on Android 10+.
+ *
+ * See DROID-2025 for more details.
*/
@OptIn(FlowPreview::class)
fun ConnectivityManager.hasInternetConnectivity(
@@ -212,6 +219,7 @@ fun ConnectivityManager.hasInternetConnectivity(
defaultEvent
}
.debounce(CONNECTIVITY_DEBOUNCE)
+ .onEach { Logger.i("Resolving connectivity status") }
.map { resolveConnectivityStatus(it, resolver) }
.distinctUntilChanged()
diff --git a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/UnderlyingConnectivityStatusResolver.kt b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/UnderlyingConnectivityStatusResolver.kt
index 1a5cb33be4..f957c1a645 100644
--- a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/UnderlyingConnectivityStatusResolver.kt
+++ b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/util/UnderlyingConnectivityStatusResolver.kt
@@ -43,8 +43,8 @@ class UnderlyingConnectivityStatusResolver(
// Protect so we can get underlying network
if (!protected) {
- // We shouldn't be doing this if we don't have a VPN, then we should of checked
- // the network directly.
+ // We shouldn't be doing this if we don't have a VPN, then we should have
+ // checked the network directly.
Logger.w("Failed to protect socket")
}
@@ -59,9 +59,16 @@ class UnderlyingConnectivityStatusResolver(
private fun DatagramSocket.connectSafe(address: InetSocketAddress): Either<Throwable, Unit> =
Either.catch { connect(address) }
- .onLeft { Logger.e("Socket could not be set up") }
+ .onLeft { Logger.i("${address.toIpVersionString()} is not available") }
.also { close() }
+ private fun InetSocketAddress.toIpVersionString(): String =
+ when (this.address) {
+ is Inet4Address -> "IPv4"
+ is Inet6Address -> "IPv6"
+ else -> "Unknown"
+ }
+
companion object {
private const val PUBLIC_IPV4_ADDRESS = "1.1.1.1"
private const val PUBLIC_IPV6_ADDRESS = "2606:4700:4700::1001"