From 7b32f5e078bb56e612168b776c7f02c3057df8e2 Mon Sep 17 00:00:00 2001 From: Redge Barkley Date: Wed, 9 Sep 2026 14:46:38 +0200 Subject: [PATCH] fix(network_info_plus): report ethernet IP, mask and gateway below Android 12 The ConnectivityManager path in getWifiIPAddress() was gated at API 31, falling back to WifiManager below that. WifiInfo.ipAddress is 0 on a wired link, so getWifiIP() returned null and getWifiSubmask() returned an empty string on every Android below 12. That gate was never deliberate. It arrived in f750ae96, whose actual goal was reading the SSID on Android 12, where NetworkCapabilities.getTransportInfo() genuinely requires API 31. The same commit rewrote getWifiIPAddress() and reused the constant. 40d7e13b removed the gate from the SSID path nine days later, but it survived on the address and gateway paths. The gate now sits at API 24, which is the minSdkVersion the current Flutter tooling enforces, so no supported consumer can run below it. The APIs the path uses are older still: getActiveNetwork() is API 23 and getLinkProperties() is API 21. The same gate in NetworkInfoPlusPlugin.setupChannels() has to move too, otherwise connectivityManager stays null and nothing changes. getGatewayIPAddress() could not take the same change: it called LinkProperties.getDhcpServerAddress(), which is API 30 and would throw NoSuchMethodError below that. It now reads the default route's gateway via RouteInfo.isDefaultRoute() and getGateway(), both API 21. On API 31+ that also reports the gateway rather than the DHCP server address. --- .../fluttercommunity/plus/network_info/NetworkInfo.kt | 10 +++++----- .../plus/network_info/NetworkInfoPlusPlugin.kt | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/network_info_plus/network_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/network_info/NetworkInfo.kt b/packages/network_info_plus/network_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/network_info/NetworkInfo.kt index 61318091ba..722663f141 100644 --- a/packages/network_info_plus/network_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/network_info/NetworkInfo.kt +++ b/packages/network_info_plus/network_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/network_info/NetworkInfo.kt @@ -25,7 +25,7 @@ internal class NetworkInfo( fun getWifiIPAddress(): String? { var ipAddress: String? = null - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { val linkAddresses = connectivityManager?.getLinkProperties(connectivityManager.activeNetwork)?.linkAddresses @@ -80,12 +80,12 @@ internal class NetworkInfo( } fun getGatewayIPAddress(): String? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { - val linkAddresses = + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + val linkProperties = connectivityManager?.getLinkProperties(connectivityManager.activeNetwork) - val dhcpServer = linkAddresses?.dhcpServerAddress?.hostAddress + val defaultRoute = linkProperties?.routes?.firstOrNull { route -> route.isDefaultRoute } - dhcpServer + defaultRoute?.gateway?.hostAddress } else { @Suppress("DEPRECATION") val dhcpInfo = wifiManager.dhcpInfo diff --git a/packages/network_info_plus/network_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/network_info/NetworkInfoPlusPlugin.kt b/packages/network_info_plus/network_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/network_info/NetworkInfoPlusPlugin.kt index a1f7b06bc2..fc6e6baf53 100644 --- a/packages/network_info_plus/network_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/network_info/NetworkInfoPlusPlugin.kt +++ b/packages/network_info_plus/network_info_plus/android/src/main/kotlin/dev/fluttercommunity/plus/network_info/NetworkInfoPlusPlugin.kt @@ -28,7 +28,7 @@ class NetworkInfoPlusPlugin : FlutterPlugin { context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager var connectivityManager: ConnectivityManager? = null - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { connectivityManager = context.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager }