Initialize serviceCache before first use

The comment that "The very first posted task is to initialize the
service cache, so it will be always set in other tasks running on
the handler" did not consider that if the looper was provided by the
caller, it is possible for other tasks to run on it before the
serviceCache is initialized. In particular, if the caller calls
registerListener on the looper thread right after calling the
constructor, this would be executed before the posted initialization
task.

In practice this does not happen as MdnsDiscoveryManager is created in
the NsdService constructor, and any usage of it is on messages posted to
the NsdService handler thread after the constructor has been called; so
the service cache initialization does happen before any other
MdnsDiscoveryManager task.

As this is error-prone, just initialize the service cache before first
use on the handler thread, as it is only used for
createServiceTypeClient, which runs on the handler thread.

Test: atest
Change-Id: Ie341bb71ef327dceb4f0aa6fc2d241d6e9cbb900
1 file changed