Make NsdService only start the native daemon when needed and automatically clean it up.

Currently, NsdService starts the native mdnsresponder daemon if any
NsdManager connect to it, which results in that when any constant
service holds the NsdManager connection, the device would always be
in the mdns multicast group whatever the connection is not used or not.
This is because mdnsresponder will join the multicast group when it
starts.

To solve this problem, start the native daemon only when needed, and
clean it up after the given idle timeout.

1. Start the native daemon when a new request come.
2. If there is no pending request, clean up the daemon after 3 seconds
of idle time.

Bug: 181810560
Test: atest NsdManagerTest NsdServiceTest
Original-Change: https://android-review.googlesource.com/1717479
Merged-In: I3eb04552f6cf6c0c68c07abffe751bb4d0669215
Change-Id: I3eb04552f6cf6c0c68c07abffe751bb4d0669215
2 files changed