Share NetworkInterfaceProvider between MdnsSockets

Instead of creating one NetworkInterfaceProvider for each MdnsSocket,
create one in MdnsSocketClient and use it for each MdnsSocket.

MdnsSocket only calls getMulticastNetworkInterfaces and
getAvailableNetwork on MulticastNetworkInterfaceProvider, which are
thread-safe (the first one is synchronized). There is no need to have
multiple MulticastNetworkInterfaceProvider tracking the same state.

This allows reducing the number of callbacks filed to
ConnectivityManager, which is a resource usage improvement and can be
beneficial for huge apps that have many components which may
collectively reach the MAX_NETWORK_REQUESTS_PER_UID limit in
ConnectivityService (100).

MdnsSocketClient is unused in AOSP so this is a no-op in the platform.
It is only used by users of the unbundled mdns library.

Bug: 322049918
Test: atest
Change-Id: I515459beaee6aacc99c7c0c2a05c3c9c41473b62
3 files changed