coil-kt / coil

Image loading for Android and Compose Multiplatform.
https://coil-kt.github.io/coil/
Apache License 2.0
10.61k stars 646 forks source link

Update NetworkObserver to call connectivityManager.registerDefaultNetworkCallback instead of connectivityManager.registerNetworkCallback #2374

Closed daniellevass closed 1 month ago

daniellevass commented 1 month ago

Hi,

We'd like to update the NetworkObserver to call connectivityManager.registerDefaultNetworkCallback instead of connectivityManager.registerNetworkCallback to ensure images load across our Android Automotive app regardless of the network assigned.

Android Automotive OEMs use a feature called Per-application network selection (PANS) to separate network traffic amongst various cellular network interfaces. OEMs generally prioritize critical car functionality to an "OEM-paid" network and keep entertainment functionality to a "Customer-paid" network.

Calling registerNetworkCallback is not recommended to track the default network assigned - Google recommend using registerDefaultNetworkCallback to track the default network assigned to the app.

I'm happy to open a pull request for this change, if there are no concerns with this?

Thank you,

Danielle.

colinrtwhite commented 1 month ago

Thanks for the context. I think it's possible changing NetworkObserver to use registerDefaultNetworkCallback could have side effects for existing users so I think we should probably add ImageLoader.Builder.observeDefaultNetwork(true/false) to allow opting into the change. By default we only load over the default network, but it's possible a user could be supplying a custom SocketFactory to use a different network. PR welcome!

I think this is also a good reason to make NetworkObserver public in Coil 3.x so the behaviour can be custom.

daniellevass commented 1 month ago

Thank you so much for your quick feedback! I've opened a PR over here : https://github.com/coil-kt/coil/pull/2379 - any feedback on the PR welcome 🙇‍♀️ I ran the ./test.sh locally, but it looks like CI won't let me know if I did everything okay until someone approves the build 🙈

colinrtwhite commented 1 month ago

This will be available in 2.8.0 - unfortunately I don't have a timeline for when the next release will be.