Skip to content

fix(network_info_plus): report ethernet IP, mask and gateway below Android 12 - #3999

Open
redge-munch wants to merge 1 commit into
fluttercommunity:mainfrom
redge-munch:fix/network_info_plus_android_ethernet
Open

redge-munch wants to merge 1 commit into
fluttercommunity:mainfrom
redge-munch:fix/network_info_plus_android_ethernet

Conversation

@redge-munch

@redge-munch redge-munch commented Oct 6, 2026 •

Copy link
Copy Markdown

Description

If an Android device below version 12 is on ethernet, the plugin can't find the network:

  • getWifiIP() gives back null
  • getWifiSubmask() gives back an empty string
  • getWifiBroadcast() and getWifiIPv6() don't work either
  • getWifiGatewayIP() doesn't give the ethernet gateway

On Android 12 and up, the plugin uses ConnectivityManager. That works for any kind of connection. But it only turns on at Build.VERSION_CODES.S. Below that, the plugin uses WifiInfo and dhcpInfo. Those only know about Wi-Fi, so on ethernet they give back 0.

The S check came in with #1151. It was needed there for the SSID, because NetworkCapabilities.getTransportInfo() is API 31. But the calls for the IP and gateway are much older.

This PR turns on the ConnectivityManager code from Android 7 (Build.VERSION_CODES.N, API 24). It makes 3 small changes:

  1. NetworkInfoPlusPlugin.setupChannels(): Get ConnectivityManager from N. Before, it was null on older devices. Without this, the other changes do nothing.
  2. NetworkInfo.getWifiIPAddress(): Only the version number changes. getActiveNetwork() is API 23, and getLinkProperties() is API 21.
  3. NetworkInfo.getGatewayIPAddress(): Get the gateway from the default route. The old code used getDhcpServerAddress(), but that needs API 30. It would crash on API 24 to 29. The default route calls (isDefaultRoute() and getGateway()) work from API 21.

Subnet mask, broadcast and IPv6 don't need any changes. They all use the IP from getWifiIPAddress(), so they start working once that does.

The plugin's minSdk is 19. Below N, the old Wi-Fi code still runs.

One change on Android 12 and up: getWifiGatewayIP() now gives the real gateway, not the DHCP server. Most of the time these are the same, but not always.

Testing

  • I tried this on ethernet on API 25, 28 and 30. It works on all of them. Before the change, none of them showed anything.
  • flutter analyze finds no problems in network_info_plus, and flutter test passes.
  • The example app builds with flutter build apk --debug.

Related Issues

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I titled the PR using Conventional Commits.
  • I did not modify the CHANGELOG.md nor the plugin version in pubspec.yaml files.
  • All existing and new tests are passing.
  • The analyzer (flutter analyze) does not report any problems on my PR.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (please indicate that with a ! in the title as explained in Conventional Commits).
  • No, this is not a breaking change.

…droid 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 f750ae9, 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. 40d7e13 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Request]: network_info_plus: use ConnectivityManager for getWifiIP and getWifiGatewayIP from Android 7 (N), so ethernet works below Android 12

1 participant