Fix flaky test for DnsResolverTest

It's possible that private DNS setting is not in the state we expected
when we tried to enable strict mode during tests. The problem here is
that there are 2 setting Uris(mode and specifier) relating to strict
mode, each of them might trigger private DNS setting changing evnet in
ConnectivityService.
Previously, we tried to enable strict mode with first set private DNS
mode and then private DNS specifier. This may result in 2 consecutive
private DNS changes events with very short intervals, which caused
conflicts between DnsResolver / NetworkMonitor and lead to flaky tests.

So
1. Change the order (mode and specifier) for enabling strict mode.
2. Change private DNS mode only when needed.
     (If original mode is "hostname", then we only need to set
     specifier)

Bug: 153624005
Bug: 153624702
Test: atest DnsResolverTest --rerun-until-failure 100
Merged-In: Iaed6285677f74a5ee6cc6684534ddc0758b25974
Change-Id: I566bdfa98dc070247b52fe29ca1f31cbd1bb8cc2
(cherry picked from commit 877af1ee3ed2c3a9e9256e216709908d2beb3bfb)
3 files changed
tree: 3b1be76fa7f6458077962c53f0070740c1f55e9e
  1. tests/