Implement the stop resolution with MdnsDiscoveryManager
The resolveService() uses new mdns backend if the MdnsDiscoveryManager feature is enabled. So the new API stopServiceResolution() should have new mdns backend implementation as well. Test: atest FrameworksNetTests Change-Id: I591e78180f530daa701e0970860f7471f5f5fb9a
This commit is contained in:
@@ -1150,6 +1150,37 @@ public class NsdServiceTest {
|
||||
argThat(info -> matches(info, new NsdServiceInfo(regInfo.getServiceName(), null))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopServiceResolutionWithMdnsDiscoveryManager() {
|
||||
setMdnsDiscoveryManagerEnabled();
|
||||
|
||||
final NsdManager client = connectClient(mService);
|
||||
final ResolveListener resolveListener = mock(ResolveListener.class);
|
||||
final Network network = new Network(999);
|
||||
final String serviceType = "_nsd._service._tcp";
|
||||
final String constructedServiceType = "_nsd._sub._service._tcp.local";
|
||||
final ArgumentCaptor<MdnsServiceBrowserListener> listenerCaptor =
|
||||
ArgumentCaptor.forClass(MdnsServiceBrowserListener.class);
|
||||
final NsdServiceInfo request = new NsdServiceInfo(SERVICE_NAME, serviceType);
|
||||
request.setNetwork(network);
|
||||
client.resolveService(request, resolveListener);
|
||||
waitForIdle();
|
||||
verify(mSocketProvider).startMonitoringSockets();
|
||||
verify(mDiscoveryManager).registerListener(eq(constructedServiceType),
|
||||
listenerCaptor.capture(), argThat(options -> network.equals(options.getNetwork())));
|
||||
|
||||
client.stopServiceResolution(resolveListener);
|
||||
waitForIdle();
|
||||
|
||||
// Verify the listener has been unregistered.
|
||||
verify(mDiscoveryManager, timeout(TIMEOUT_MS))
|
||||
.unregisterListener(eq(constructedServiceType), eq(listenerCaptor.getValue()));
|
||||
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
|
||||
request.getServiceName().equals(ns.getServiceName())
|
||||
&& request.getServiceType().equals(ns.getServiceType())));
|
||||
verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).stopMonitoringSockets();
|
||||
}
|
||||
|
||||
private void waitForIdle() {
|
||||
HandlerUtils.waitForIdle(mHandler, TIMEOUT_MS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user