[Request]: network_info_plus: use ConnectivityManager for getWifiIP and getWifiGatewayIP from Android 7 (N), so ethernet works below Android 12
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 半天
- 新手友好度
- 22/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 领域
- mobile, mobile-dev
调研方向
Work is already in open PR #3999; do not start a duplicate. The Android path lives in the network_info_plus plugin: NetworkInfoPlusPlugin.setupChannels() currently constructs ConnectivityManager only from VERSION_CODES.S, and NetworkInfo.getWifiIPAddress() / getGatewayIPAddress() use the same S gate (WifiInfo/dhcpInfo below that). Confirm minSdk 19 still needs the Wi-Fi fallback below N. Done means ethernet IP/gateway work on API 24–30 without crashing getDhcpServerAddress on API 24–29.
由索引模型根据 Issue 内容生成。
描述
Plugin
network_info_plus
Use case
If an Android device below version 12 is on ethernet, the plugin can't find the network:
getWifiIP()gives backnullgetWifiSubmask()gives back an empty stringgetWifiBroadcast()andgetWifiIPv6()don't work eithergetWifiGatewayIP()doesn't give the ethernet gateway
On Android 12 and up it works fine. The Android code uses ConnectivityManager there, and 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 instead. Those only know about Wi-Fi, so on ethernet they just give back 0.
The thing is, the ConnectivityManager calls are much older than Android 12. getActiveNetwork() is API 23, and the rest are API 21. The only newer one is getDhcpServerAddress(), which the gateway code uses. That one is API 30.
The S check came in with #1151. #420 asks for something similar, but this is just for Android.
Proposal
Turn on the ConnectivityManager code from Android 7 (Build.VERSION_CODES.N, API 24) instead of Android 12. That takes 3 small changes.
1. Get ConnectivityManager from N in NetworkInfoPlusPlugin.setupChannels()
Right now it's only set up on S and above, so it's null on older devices. If you only change the check in NetworkInfo.kt, nothing happens.
var connectivityManager: ConnectivityManager? = null
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
connectivityManager = context.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
}
2. Change the check in NetworkInfo.getWifiIPAddress()
Only the version number changes. The rest stays the same.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val linkAddresses =
connectivityManager?.getLinkProperties(connectivityManager.activeNetwork)?.linkAddresses
// ...unchanged
}
3. Get the gateway from the default route in NetworkInfo.getGatewayIPAddress()
You can't just change the version number here. getDhcpServerAddress() needs API 30, so it would crash on API 24 to 29. The default route works from API 21. It's also a bit better on Android 12+, because it gives you the real gateway and not the DHCP server. Those aren't always the same thing.
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val linkProperties =
connectivityManager?.getLinkProperties(connectivityManager.activeNetwork)
val defaultRoute = linkProperties?.routes?.firstOrNull { route -> route.isDefaultRoute }
defaultRoute?.gateway?.hostAddress
} else {
// ...existing dhcpInfo fallback, unchanged
}
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, so the old Wi-Fi code still runs on anything below N.
I tried this on ethernet on API 25, 28 and 30, and it works on all of them. Before the change, none of them showed anything. It might work on API 23 (M) too, but I haven't tried that.
- 主要语言
- Dart
- 星标
- 1.9k
- 派生
- 1.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 15
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fluttercommunity/plus_plugins 的其他 Issue
-
[Bug]: (share_plus) iOS drops the subject when sharing a uri可能已有人在做 @kaluli123123 于 5 天前认领。 未关闭bug triage
难度 2/5 1-3 小时 新手友好度 82/100
fluttercommunity/plus_plugins#3994 · 1 条评论 ·
维护者通常 1 天内回复
-
[package_info_plus]: Use Flutter's compile-time build name/number on web instead of version.json可能已有人在做 @Ortes 于 10 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 25/100
fluttercommunity/plus_plugins#3989 ·
维护者通常 1 天内回复
-
enhancement triage
难度 4/5 3-5 天 新手友好度 55/100
fluttercommunity/plus_plugins#3976 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
fluttercommunity/plus_plugins#3974 · 1 个 reaction ·
维护者通常 1 天内回复
-
enhancement triage
难度 5/5 一周以上 新手友好度 48/100
fluttercommunity/plus_plugins#3973 ·
维护者通常 1 天内回复
查看 fluttercommunity/plus_plugins 的全部 Issue
相似的 Issue
-
[BUG][All] VLESS URIs with flow=xtls-rprx-vision-udp443 are silently dropped on subscription import未关闭
难度 2/5 1-3 小时 新手友好度 68/100
-
area::timeline needs::triage regression
难度 2/5 1-3 小时 新手友好度 80/100
linagora/twake-on-matrix#3450 ·
维护者通常 3 天内回复
-
难度 2/5 1 小时以内 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 82/100
genkit-ai/genkit-dart#637 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 70/100
bggRGjQaUbCoE/PiliPlus#3235 ·
维护者通常 1 天内回复