Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 993f1c96 authored by Chiachang Wang's avatar Chiachang Wang
Browse files

Fix a bug where private DNS to v4-only servers don't validate.

Bug: 132670008
Test: Manual
Test: atest NetworkStackTests
Change-Id: I8ae6fa6f3800f5f6c9ee88ffe3b8ada34b96dee6
Merged-In: I362d43ee6af318694a4038a257e1ebb3f577863c
parent 544ad304
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -55,12 +55,23 @@ public class DnsUtils {
            throws UnknownHostException {
        final List<InetAddress> result = new ArrayList<InetAddress>();

        try {
            result.addAll(Arrays.asList(
                    getAllByName(dnsResolver, network, host, TYPE_AAAA, FLAG_NO_CACHE_LOOKUP,
                    timeout)));
        } catch (UnknownHostException e) {
            // Might happen if the host is v4-only, still need to query TYPE_A
        }
        try {
            result.addAll(Arrays.asList(
                    getAllByName(dnsResolver, network, host, TYPE_A, FLAG_NO_CACHE_LOOKUP,
                    timeout)));
        } catch (UnknownHostException e) {
            // Might happen if the host is v6-only, still need to return AAAA answers
        }
        if (result.size() == 0) {
            throw new UnknownHostException(host);
        }
        return result.toArray(new InetAddress[0]);
    }

+3 −2
Original line number Diff line number Diff line
@@ -297,9 +297,10 @@ public class NetworkMonitorTest {
        setOtherFallbackUrls(TEST_OTHER_FALLBACK_URL);
        setFallbackSpecs(null); // Test with no fallback spec by default
        when(mRandom.nextInt()).thenReturn(0);

        // DNS probe timeout should not be defined more than half of HANDLER_TIMEOUT_MS. Otherwise,
        // it will fail the test because of timeout expired for querying AAAA and A sequentially.
        when(mResources.getInteger(eq(R.integer.config_captive_portal_dns_probe_timeout)))
                .thenReturn(500);
                .thenReturn(200);

        doAnswer((invocation) -> {
            URL url = invocation.getArgument(0);