Thanks a lot for the context and suggestions — really appreciate it.
We’d really appreciate any guidance from folks who have worked on this area recently.
Regards,
Ke
I haven't worked on NetworkChangeNotifierAutoDetect in maybe 5 years, so it's probably best to reach out to
net...@chromium.org or other folks who have worked on it more recently.
WRT using NetworkCapabilities passed to onCapabilitiesChanged(), I believe those are only the capabilities for one network, so you'd have to cache and track the capabilities for all networks.
WRT why the current implementation makes synchronous getNetworkInfo() calls, I think this is done to ensure we always get the most up to date information. Looks like getNetworkInfo() is now deprecated in favor of using things like
NetworkCallbacks.
Hi Team,
I'm from the Edge Mobile team, we're investigating ANR issues in Edge Android where getNetworkInfo() is called on the main thread within NetworkChangeNotifierAutoDetect, performing synchronous Binder IPC to ConnectivityManager.
Current code:
This call goes through getNetworkInfo() which performs a Binder IPC on the main thread, leading to potential ANR.
We're considering two possible approaches and would like your input:
1. Use NetworkCapabilities directly (where available): In callbacks like onCapabilitiesChanged(), the NetworkCapabilities parameter already contains transport information. Could we derive the connection type from it instead of calling getNetworkInfo()?
2. Use cached network state:
Commit 4fab437979e8 introduced caching for network state. Could more code paths use getCurrentNetworkState() (which returns cached data) instead of making fresh system calls?
Are there specific reasons why the current implementation makes synchronous getNetworkInfo() calls instead of using these alternatives? Are there edge cases we should be aware of?
Any guidance would be greatly appreciated!
Thanks,
Ke