Make DoT retries configurable

DnsTlsTransport re-issues pending queries when onClosed is called.
The call to onClosed is triggered when 1) asynchronous handshake
fails and 2) SSL socket idles for 20 seconds. In either case, retry
on the same DoT server is not always a good solution. Instead, there
are some considerable options, like trying next DoT server, fallbacking
to Do53, or simply returning query failure.

Tuning DoT retries is especially significant to asynchronous
handshake feature because the timeout of the feature is calculated as:

  timeout = dot_connect_timeout_ms * dot_maxtries

Bug: 149445907
Test: cd packages/modules/DnsResolver
      atest with combination of (dot_async_handshake, dot_maxtries)
      which are (0, 3), (0, 1), (1, 3), and (1, 1)
Change-Id: Iceb7bc7f0f6736d900384d1a11eea470761ee32c
diff --git a/DnsTlsQueryMap.cpp b/DnsTlsQueryMap.cpp
index c4ae450..96191e3 100644
--- a/DnsTlsQueryMap.cpp
+++ b/DnsTlsQueryMap.cpp
@@ -20,9 +20,16 @@
 
 #include <android-base/logging.h>
 
+#include "Experiments.h"
+
 namespace android {
 namespace net {
 
+DnsTlsQueryMap::DnsTlsQueryMap() {
+    mMaxTries = Experiments::getInstance()->getFlag("dot_maxtries", kMaxTries);
+    if (mMaxTries < 1) mMaxTries = 1;
+}
+
 std::unique_ptr<DnsTlsQueryMap::QueryFuture> DnsTlsQueryMap::recordQuery(
         const netdutils::Slice query) {
     std::lock_guard guard(mLock);
@@ -67,7 +74,7 @@
     std::lock_guard guard(mLock);
     for (auto it = mQueries.begin(); it != mQueries.end();) {
         auto& p = it->second;
-        if (p.tries >= kMaxTries) {
+        if (p.tries >= mMaxTries) {
             expire(&p);
             it = mQueries.erase(it);
         } else {