Stop monitoring sockets until all sockets are unrequested

Now MdnsSocketProvider is stopped when there is no client request
left in NsdService, but this does not trigger
SocketCallback.onInterfaceDestroyed callbacks. If the network of
the socket is then lost while MdnsSocketProvider is not
monitoring, no callback will be fired. Users of the socket
(MdnsDiscoveryManager and MdnsAdvertiser) may keep using it
without ever getting notified. So ignore the stop and wait until
all sockets are unrequested. Then the socket destroy should be
notified to all users.

Bug: 267978487
Test: atest FrameworksNetTests
Change-Id: I7a8bb0550262fe397b91f1236a8dbca1cf2c7518
This commit is contained in:
Paul Hu
2023-02-18 11:41:07 +08:00
parent 22f17371b3
commit 58f2060614
4 changed files with 90 additions and 16 deletions

View File

@@ -317,7 +317,7 @@ public class NsdService extends INsdManager.Stub {
if (!mIsMonitoringSocketsStarted) return;
if (isAnyRequestActive()) return;
mMdnsSocketProvider.stopMonitoringSockets();
mMdnsSocketProvider.requestStopWhenInactive();
mIsMonitoringSocketsStarted = false;
}