Avoid creating a Network with INetd.LOCAL_NET_ID

INetd.LOCAL_NET_ID cannot be referred to by system SDK. To make the
MdnsSocketProvider built with system SDK, the reference to
INetd.LOCAL_NET_ID must be removed.

This network is created in MdnsSocketProvider.java and propagated
through MdnsSocketProvider.java -> MdnsMultinetworkSocketClient.java ->
MdnsDiscoveryManager.java -> MdnsServiceTypeClient.java ->
NsdService.java. In NsdService.java, it was used in
handleMdnsDiscoveryManagerEvent() -> buildNsdServiceInfoFromMdnsEvent()
-> setServiceNetworkForCallback(). The setServiceNetworkForCallback() is
updated to handle the NETID_UNSET the same as LOCAL_NET_ID.

Test: atest CtsNetTestCases FrameworksNetTests
Bug: 272392042
Change-Id: I07c573948e9dc6249325f0733807bb7a7ffc281c
This commit is contained in:
Yuyang Huang
2023-04-04 13:00:54 +09:00
parent 2d51f333d7
commit 3bee9d4099
4 changed files with 80 additions and 34 deletions

View File

@@ -1106,9 +1106,12 @@ public class NsdService extends INsdManager.Stub {
final String serviceName = serviceInfo.getServiceInstanceName();
final NsdServiceInfo servInfo = new NsdServiceInfo(serviceName, serviceType);
final Network network = serviceInfo.getNetwork();
// In MdnsDiscoveryManagerEvent, the Network can be null which means it is a
// network for Tethering interface. In other words, the network == null means the
// network has netId = INetd.LOCAL_NET_ID.
setServiceNetworkForCallback(
servInfo,
network == null ? NETID_UNSET : network.netId,
network == null ? INetd.LOCAL_NET_ID : network.netId,
serviceInfo.getInterfaceIndex());
return servInfo;
}