Merge "Do not return found services on dummy0"

This commit is contained in:
Remi NGUYEN VAN
2023-01-24 04:10:58 +00:00
committed by Gerrit Code Review
2 changed files with 35 additions and 0 deletions

View File

@@ -919,6 +919,12 @@ public class NsdService extends INsdManager.Stub {
// interfaces that do not have an associated Network.
break;
}
if (foundNetId == INetd.DUMMY_NET_ID) {
// Ignore services on the dummy0 interface: they are only seen when
// discovering locally advertised services, and are not reachable
// through that interface.
break;
}
setServiceNetworkForCallback(servInfo, info.netId, info.interfaceIdx);
clientInfo.onServiceFound(clientId, servInfo);
break;

View File

@@ -412,6 +412,35 @@ public class NsdServiceTest {
assertEquals(interfaceIdx, resolvedService.getInterfaceIndex());
}
@Test
public void testDiscoverOnBlackholeNetwork() throws Exception {
final NsdManager client = connectClient(mService);
final DiscoveryListener discListener = mock(DiscoveryListener.class);
client.discoverServices(SERVICE_TYPE, PROTOCOL, discListener);
waitForIdle();
final IMDnsEventListener eventListener = getEventListener();
final ArgumentCaptor<Integer> discIdCaptor = ArgumentCaptor.forClass(Integer.class);
verify(mMockMDnsM).discover(discIdCaptor.capture(), eq(SERVICE_TYPE),
eq(0) /* interfaceIdx */);
// NsdManager uses a separate HandlerThread to dispatch callbacks (on ServiceHandler), so
// this needs to use a timeout
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE);
final DiscoveryInfo discoveryInfo = new DiscoveryInfo(
discIdCaptor.getValue(),
IMDnsEventListener.SERVICE_FOUND,
SERVICE_NAME,
SERVICE_TYPE,
DOMAIN_NAME,
123 /* interfaceIdx */,
INetd.DUMMY_NET_ID); // netId of the blackhole network
eventListener.onServiceDiscoveryStatus(discoveryInfo);
waitForIdle();
verify(discListener, never()).onServiceFound(any());
}
@Test
public void testServiceRegistrationSuccessfulAndFailed() throws Exception {
final NsdManager client = connectClient(mService);