DnsResolver
class DnsResolver
| kotlin.Any | |
| ↳ | android.net.DnsResolver |
Dns resolver class for asynchronous dns querying Note that if a client sends a query with more than 1 record in the question section but the remote dns server does not support this, it may not respond at all, leading to a timeout.
Summary
| Nested classes | |
|---|---|
| abstract |
Base interface for answer callbacks |
|
Class to represent DNS error |
|
| Constants | |
|---|---|
| static Int | |
| static Int |
Indicates that there was an error parsing the response the query. |
| static Int |
Indicates that there was an error sending the query. |
| static Int | |
| static Int | |
| static Int | |
| static Int | |
| static Int |
Indicates that the default wait time should be used for the HTTPS query. |
| static Int |
Indicates that no additional wait should be used for the HTTPS query. |
| static Int |
Indicates that the HTTPS query will be retransmitted until it gets a response, or until it times out. |
| static Int | |
| static Int | |
| static Int | |
| Public methods | |
|---|---|
| static DnsResolver |
Get instance for DnsResolver |
| static DnsResolver |
getInstance(context: Context, looper: Looper?)Returns a |
| Unit |
query(network: Network?, domain: String, nsType: Int, flags: Int, executor: Executor, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<in MutableList<InetAddress!>!>)Send a DNS query with the specified name and query type, get back a set of InetAddresses with rfc6724 sorting asynchronously. |
| Unit |
query(network: Network?, domain: String, flags: Int, executor: Executor, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<in MutableList<InetAddress!>!>)Send a DNS query with the specified name on a network with both IPv4 and IPv6, get back a set of InetAddresses with rfc6724 sorting asynchronously. |
| Unit |
query(network: Network?, domain: String, flags: Int, executor: Executor, httpsTimeoutMillis: Int, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<HttpsEndpoint!>)Send concurrent A/AAAA/HTTPS DNS queries with the specified name on a network. |
| Unit |
rawQuery(network: Network?, query: ByteArray, flags: Int, executor: Executor, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<in ByteArray!>)Send a raw DNS query. |
| Unit |
rawQuery(network: Network?, domain: String, nsClass: Int, nsType: Int, flags: Int, executor: Executor, cancellationSignal: CancellationSignal?, callback: DnsResolver.Callback<in ByteArray!>)Send a DNS query with the specified name, class and query type. |
Constants
ERROR_PARSE
static val ERROR_PARSE: Int
Indicates that there was an error parsing the response the query. The cause of this error is available via getCause() and is a ParseException.
Value: 0ERROR_SYSTEM
static val ERROR_SYSTEM: Int
Indicates that there was an error sending the query. The cause of this error is available via getCause() and is an ErrnoException.
Value: 1HTTPS_QUERY_WAIT_AUTO
static val HTTPS_QUERY_WAIT_AUTO: Int
Indicates that the default wait time should be used for the HTTPS query.
This option balances the extra latency of waiting for the HTTPS record with the latency and security benefits of receiving it.
Value: -1HTTPS_QUERY_WAIT_NONE
static val HTTPS_QUERY_WAIT_NONE: Int
Indicates that no additional wait should be used for the HTTPS query.
This option means the callback will be called immediately as soon as the IP address queries have received a response, regardless of whether the HTTPS query has received a response or not.
This option is not recommended for security or latency because it may result in HTTPS records not being returned even if they exist.
Value: 0HTTPS_QUERY_WAIT_UNTIL_TIMEOUT
static val HTTPS_QUERY_WAIT_UNTIL_TIMEOUT: Int
Indicates that the HTTPS query will be retransmitted until it gets a response, or until it times out.
This option may increase latency if the HTTPS query is dropped by the network.
Value: -2Public methods
getInstance
static fungetInstance(): DnsResolver
Deprecated: Use getInstance(Context,Looper) instead.
Get instance for DnsResolver
| Return | |
|---|---|
DnsResolver |
This value cannot be null. |
getInstance
static fun getInstance(
context: Context,
looper: Looper?
): DnsResolver
Returns a DnsResolver instance.
| Parameters | |
|---|---|
context |
Context: used for internal interactions with other system services. This value cannot be null. |
looper |
Looper?: Looper for monitoring incoming replies to DNS queries. If null, then uses the value returned by Looper.getMainLooper(). |
| Return | |
|---|---|
DnsResolver |
This value cannot be null. |
query
fun query(
network: Network?,
domain: String,
nsType: Int,
flags: Int,
executor: Executor,
cancellationSignal: CancellationSignal?,
callback: DnsResolver.Callback<in MutableList<InetAddress!>!>
): Unit
Send a DNS query with the specified name and query type, get back a set of InetAddresses with rfc6724 sorting asynchronously. The answer will be provided asynchronously through the provided Callback.
| Parameters | |
|---|---|
network |
Network?: Network specifying which network to query on. null for query on default network. |
domain |
String: domain name to query. This value cannot be null. |
nsType |
Int: dns resource record (RR) type as one of the TYPE_* constants. Value is one of the following: |
flags |
Int: flags as a combination of the FLAGS_* constants. Value is one of the following: |
executor |
Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
cancellationSignal |
CancellationSignal?: used by the caller to signal if the query should be cancelled. May be null. |
callback |
DnsResolver.Callback<in MutableList<InetAddress!>!>: a Callback which will be called to notify the caller of the result of dns query. This value cannot be null. |
query
fun query(
network: Network?,
domain: String,
flags: Int,
executor: Executor,
cancellationSignal: CancellationSignal?,
callback: DnsResolver.Callback<in MutableList<InetAddress!>!>
): Unit
Send a DNS query with the specified name on a network with both IPv4 and IPv6, get back a set of InetAddresses with rfc6724 sorting asynchronously. This method will examine the connection ability on given network, and query IPv4 and IPv6 if connection is available. This method will send A queries if the specified Network provides IPv4 connectivity, and AAAA queries if it provides IPv6 connectivity. If at least one query succeeded with valid answer, rcode will be 0 The answer will be provided asynchronously through the provided Callback.
| Parameters | |
|---|---|
network |
Network?: Network specifying which network to query on. null for query on default network. |
domain |
String: domain name to query. This value cannot be null. |
flags |
Int: flags as a combination of the FLAGS_* constants. Value is one of the following: |
executor |
Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
cancellationSignal |
CancellationSignal?: used by the caller to signal if the query should be cancelled. May be null. |
callback |
DnsResolver.Callback<in MutableList<InetAddress!>!>: a Callback which will be called to notify the caller of the result of dns query. This value cannot be null. |
query
fun query(
network: Network?,
domain: String,
flags: Int,
executor: Executor,
httpsTimeoutMillis: Int,
cancellationSignal: CancellationSignal?,
callback: DnsResolver.Callback<HttpsEndpoint!>
): Unit
Send concurrent A/AAAA/HTTPS DNS queries with the specified name on a network. The answer to all queries will be provided asynchronously through the provided callback Callback, which provides a HttpsEndpoint.
| Parameters | |
|---|---|
network |
Network?: Network specifying which network to query on. null for query on default network. |
domain |
String: domain name to query. This value cannot be null. |
flags |
Int: flags as a combination of the FLAGS_* constants. Value is one of the following: |
executor |
Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
httpsTimeoutMillis |
Int: the timeout in milliseconds to wait for the HTTPS query to complete after the A/AAAA queries have already completed. May be set to HTTPS_QUERY_WAIT_NONE to disable any additional wait, HTTPS_QUERY_WAIT_AUTO to use the default wait time, HTTPS_QUERY_WAIT_UNTIL_TIMEOUT to wait for the HTTPS query to complete, or a specific value in milliseconds. |
cancellationSignal |
CancellationSignal?: used by the caller to signal if all the queries should be cancelled. May be null. |
callback |
DnsResolver.Callback<HttpsEndpoint!>: a Callback which will be called to notify the caller of the results of the A/AAAA/HTTPS DNS queries. Will return a ERROR_PARSE if any of the DNS records cannot be parsed, and should be treated as a resolution failure. This value cannot be null. |
rawQuery
fun rawQuery(
network: Network?,
query: ByteArray,
flags: Int,
executor: Executor,
cancellationSignal: CancellationSignal?,
callback: DnsResolver.Callback<in ByteArray!>
): Unit
Send a raw DNS query. The answer will be provided asynchronously through the provided Callback.
| Parameters | |
|---|---|
network |
Network?: Network specifying which network to query on. null for query on default network. |
query |
ByteArray: blob message to query. This value cannot be null. |
flags |
Int: flags as a combination of the FLAGS_* constants. Value is one of the following: |
executor |
Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
cancellationSignal |
CancellationSignal?: used by the caller to signal if the query should be cancelled. May be null. |
callback |
DnsResolver.Callback<in ByteArray!>: a Callback which will be called to notify the caller of the result of dns query. This value cannot be null. |
rawQuery
fun rawQuery(
network: Network?,
domain: String,
nsClass: Int,
nsType: Int,
flags: Int,
executor: Executor,
cancellationSignal: CancellationSignal?,
callback: DnsResolver.Callback<in ByteArray!>
): Unit
Send a DNS query with the specified name, class and query type. The answer will be provided asynchronously through the provided Callback.
| Parameters | |
|---|---|
network |
Network?: Network specifying which network to query on. null for query on default network. |
domain |
String: domain name to query. This value cannot be null. |
nsClass |
Int: dns class as one of the CLASS_* constants. Value is one of the following: |
nsType |
Int: dns resource record (RR) type as one of the TYPE_* constants. Value is one of the following: |
flags |
Int: flags as a combination of the FLAGS_* constants. Value is one of the following: |
executor |
Executor: The Executor that the callback should be executed on. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread. |
cancellationSignal |
CancellationSignal?: used by the caller to signal if the query should be cancelled. May be null. |
callback |
DnsResolver.Callback<in ByteArray!>: a Callback which will be called to notify the caller of the result of dns query. This value cannot be null. |