DoH: Enable session resumption

When a connection is closed gracefully, the connection's session
will be stored in the `Connection`. The `Network` that owns the
`Connection` will attempt to reuse the session on next connection.

This change should improve the performance in terms of reducing
traffic resources.

The example log of a reconnection to dns.google (w/o session resumption):
15:42:47.431  1017  1095 D doh::connection::driver: Sent 1200 bytes on network 100
15:42:47.454  1017  1095 D doh::connection::driver: Received 1200 bytes on network 100
15:42:47.455  1017  1095 D doh::connection::driver: Sent 1200 bytes on network 100
15:42:47.455  1017  1095 D doh::connection::driver: Received 1200 bytes on network 100
15:42:47.456  1017  1095 D doh::connection::driver: Sent 59 bytes on network 100
15:42:47.456  1017  1095 D doh::connection::driver: Received 1200 bytes on network 100
15:42:47.457  1017  1095 D doh::connection::driver: Sent 59 bytes on network 100
15:42:47.458  1017  1095 D doh::connection::driver: Received 1200 bytes on network 100
15:42:47.458  1017  1095 D doh::connection::driver: Sent 59 bytes on network 100
15:42:47.460  1017  1095 D doh::connection::driver: Received 1200 bytes on network 100
15:42:47.461  1017  1095 D doh::connection::driver: Sent 60 bytes on network 100
15:42:47.469  1017  1095 D doh::connection::driver: Received 397 bytes on network 100
15:42:47.469  1017  1095 D doh::connection::driver: Sent 132 bytes on network 100
15:42:47.470  1017  1095 D doh::connection::driver: Handling DNS request on network 100, ...

The example log of a reconnection to dns.google (w/ session resumption)
15:33:18.702  1021  1066 D doh::connection::driver: Sent 1200 bytes on network 101
15:33:18.756  1021  1066 D doh::connection::driver: Received 1200 bytes on network 101
15:33:18.757  1021  1066 D doh::connection::driver: Sent 1200 bytes on network 101
15:33:18.758  1021  1066 D doh::connection::driver: Handling DNS request on network 101, ...

Bug: 205922811
Test: cd packages/modules/DnsResolver && atest
Test: manually tested every non-testing DoH provider listed
      in mAvailableDoHProviders
Change-Id: I5ec02970d03a40a7fea05688e9a42fa50ceb4859
11 files changed
tree: 3c60f731f1c8ba764a3608e5a71fd9c5c36b0c46
  1. aidl_api/
  2. apex/
  3. binder/
  4. doh/
  5. include/
  6. tests/
  7. .editorconfig
  8. Android.bp
  9. cbindgen.toml
  10. Dns64Configuration.cpp
  11. Dns64Configuration.h
  12. DnsProxyListener.cpp
  13. DnsProxyListener.h
  14. DnsQueryLog.cpp
  15. DnsQueryLog.h
  16. DnsQueryLogTest.cpp
  17. DnsResolver.cpp
  18. DnsResolver.h
  19. DnsResolverService.cpp
  20. DnsResolverService.h
  21. DnsStats.cpp
  22. DnsStats.h
  23. DnsStatsTest.cpp
  24. DnsTlsDispatcher.cpp
  25. DnsTlsDispatcher.h
  26. DnsTlsQueryMap.cpp
  27. DnsTlsQueryMap.h
  28. DnsTlsServer.cpp
  29. DnsTlsServer.h
  30. DnsTlsSessionCache.cpp
  31. DnsTlsSessionCache.h
  32. DnsTlsSocket.cpp
  33. DnsTlsSocket.h
  34. DnsTlsSocketFactory.h
  35. DnsTlsTransport.cpp
  36. DnsTlsTransport.h
  37. doh.h
  38. Experiments.cpp
  39. Experiments.h
  40. ExperimentsTest.cpp
  41. getaddrinfo.cpp
  42. getaddrinfo.h
  43. gethnamaddr.cpp
  44. gethnamaddr.h
  45. hostent.h
  46. IDnsTlsSocket.h
  47. IDnsTlsSocketFactory.h
  48. IDnsTlsSocketObserver.h
  49. IPrivateDnsServer.h
  50. libnetd_resolv.map.txt
  51. LockedQueue.h
  52. NOTICE
  53. OperationLimiter.h
  54. OperationLimiterTest.cpp
  55. OWNERS
  56. params.h
  57. PREUPLOAD.cfg
  58. PrivateDnsCommon.h
  59. PrivateDnsConfiguration.cpp
  60. PrivateDnsConfiguration.h
  61. PrivateDnsConfigurationTest.cpp
  62. PrivateDnsValidationObserver.h
  63. README-DoT.md
  64. README.md
  65. res_cache.cpp
  66. res_comp.cpp
  67. res_comp.h
  68. res_debug.cpp
  69. res_debug.h
  70. res_mkquery.cpp
  71. res_query.cpp
  72. res_send.cpp
  73. res_send.h
  74. res_stats.cpp
  75. resolv_cache.h
  76. resolv_private.h
  77. resolv_rust_test_config_template.xml
  78. resolv_test_config_template.xml
  79. ResolverController.cpp
  80. ResolverController.h
  81. ResolverEventReporter.cpp
  82. ResolverEventReporter.h
  83. ResolverStats.h
  84. sethostent.cpp
  85. stats.h
  86. stats.proto
  87. TEST_MAPPING
  88. util.cpp
  89. util.h
README.md

Logging

This code uses LOG(X) for logging. Log levels are VERBOSE,DEBUG,INFO,WARNING and ERROR. The default setting is WARNING and logs relate to WARNING and ERROR will be shown. If you want to enable the DEBUG level logs, using following command. adb shell service call dnsresolver 10 i32 1 VERBOSE 0 DEBUG 1 INFO 2 WARNING 3 ERROR 4 Verbose resolver logs could contain PII -- do NOT enable in production builds.