Loading api/current.txt +2 −2 Original line number Diff line number Diff line Loading @@ -27228,8 +27228,8 @@ package android.net { public final class DnsResolver { method @NonNull public static android.net.DnsResolver getInstance(); method public <T> void query(@Nullable android.net.Network, @NonNull byte[], int, @NonNull java.util.concurrent.Executor, @NonNull android.net.DnsResolver.AnswerCallback<T>); method public <T> void query(@Nullable android.net.Network, @NonNull String, int, int, int, @NonNull java.util.concurrent.Executor, @NonNull android.net.DnsResolver.AnswerCallback<T>); method public <T> void query(@Nullable android.net.Network, @NonNull byte[], int, @NonNull java.util.concurrent.Executor, @Nullable android.os.CancellationSignal, @NonNull android.net.DnsResolver.AnswerCallback<T>); method public <T> void query(@Nullable android.net.Network, @NonNull String, int, int, int, @NonNull java.util.concurrent.Executor, @Nullable android.os.CancellationSignal, @NonNull android.net.DnsResolver.AnswerCallback<T>); field public static final int CLASS_IN = 1; // 0x1 field public static final int FLAG_EMPTY = 0; // 0x0 field public static final int FLAG_NO_CACHE_LOOKUP = 4; // 0x4 core/java/android/net/DnsResolver.java +34 −4 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.net; import static android.net.NetworkUtils.resNetworkCancel; import static android.net.NetworkUtils.resNetworkQuery; import static android.net.NetworkUtils.resNetworkResult; import static android.net.NetworkUtils.resNetworkSend; Loading @@ -26,6 +27,7 @@ import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.CancellationSignal; import android.os.Looper; import android.system.ErrnoException; import android.util.Log; Loading Loading @@ -191,11 +193,18 @@ public final class DnsResolver { * @param query blob message * @param flags flags as a combination of the FLAGS_* constants * @param executor The {@link Executor} that the callback should be executed on. * @param cancellationSignal used by the caller to signal if the query should be * cancelled. May be {@code null}. * @param callback an {@link AnswerCallback} which will be called to notify the caller * of the result of dns query. */ public <T> void query(@Nullable Network network, @NonNull byte[] query, @QueryFlag int flags, @NonNull @CallbackExecutor Executor executor, @NonNull AnswerCallback<T> callback) { @NonNull @CallbackExecutor Executor executor, @Nullable CancellationSignal cancellationSignal, @NonNull AnswerCallback<T> callback) { if (cancellationSignal != null && cancellationSignal.isCanceled()) { return; } final FileDescriptor queryfd; try { queryfd = resNetworkSend((network != null Loading @@ -205,6 +214,7 @@ public final class DnsResolver { return; } maybeAddCancellationSignal(cancellationSignal, queryfd); registerFDListener(executor, queryfd, callback); } Loading @@ -219,12 +229,19 @@ public final class DnsResolver { * @param nsType dns resource record (RR) type as one of the TYPE_* constants * @param flags flags as a combination of the FLAGS_* constants * @param executor The {@link Executor} that the callback should be executed on. * @param cancellationSignal used by the caller to signal if the query should be * cancelled. May be {@code null}. * @param callback an {@link AnswerCallback} which will be called to notify the caller * of the result of dns query. */ public <T> void query(@Nullable Network network, @NonNull String domain, @QueryClass int nsClass, @QueryType int nsType, @QueryFlag int flags, @NonNull @CallbackExecutor Executor executor, @NonNull AnswerCallback<T> callback) { @NonNull @CallbackExecutor Executor executor, @Nullable CancellationSignal cancellationSignal, @NonNull AnswerCallback<T> callback) { if (cancellationSignal != null && cancellationSignal.isCanceled()) { return; } final FileDescriptor queryfd; try { queryfd = resNetworkQuery((network != null Loading @@ -233,6 +250,8 @@ public final class DnsResolver { callback.onQueryException(e); return; } maybeAddCancellationSignal(cancellationSignal, queryfd); registerFDListener(executor, queryfd, callback); } Loading Loading @@ -264,6 +283,17 @@ public final class DnsResolver { }); } private void maybeAddCancellationSignal(@Nullable CancellationSignal cancellationSignal, @NonNull FileDescriptor queryfd) { if (cancellationSignal == null) return; cancellationSignal.setOnCancelListener( () -> { Looper.getMainLooper().getQueue() .removeOnFileDescriptorEventListener(queryfd); resNetworkCancel(queryfd); }); } private static class DnsAddressAnswer extends DnsPacket { private static final String TAG = "DnsResolver.DnsAddressAnswer"; private static final boolean DBG = false; Loading core/java/android/net/NetworkUtils.java +6 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,12 @@ public class NetworkUtils { */ public static native byte[] resNetworkResult(FileDescriptor fd) throws ErrnoException; /** * DNS resolver series jni method. * Attempts to cancel the in-progress query associated with the {@code fd}. */ public static native void resNetworkCancel(FileDescriptor fd); /** * Add an entry into the ARP cache. */ Loading core/jni/android_net_NetUtils.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -487,6 +487,11 @@ static jbyteArray android_net_utils_resNetworkResult(JNIEnv *env, jobject thiz, return answer; } static void android_net_utils_resNetworkCancel(JNIEnv *env, jobject thiz, jobject javaFd) { int fd = jniGetFDFromFileDescriptor(env, javaFd); resNetworkCancel(fd); } static jobject android_net_utils_getTcpRepairWindow(JNIEnv *env, jobject thiz, jobject javaFd) { if (javaFd == NULL) { jniThrowNullPointerException(env, NULL); Loading Loading @@ -546,6 +551,7 @@ static const JNINativeMethod gNetworkUtilMethods[] = { { "resNetworkSend", "(I[BII)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkSend }, { "resNetworkQuery", "(ILjava/lang/String;III)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkQuery }, { "resNetworkResult", "(Ljava/io/FileDescriptor;)[B", (void*) android_net_utils_resNetworkResult }, { "resNetworkCancel", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_resNetworkCancel }, }; int register_android_net_NetworkUtils(JNIEnv* env) Loading Loading
api/current.txt +2 −2 Original line number Diff line number Diff line Loading @@ -27228,8 +27228,8 @@ package android.net { public final class DnsResolver { method @NonNull public static android.net.DnsResolver getInstance(); method public <T> void query(@Nullable android.net.Network, @NonNull byte[], int, @NonNull java.util.concurrent.Executor, @NonNull android.net.DnsResolver.AnswerCallback<T>); method public <T> void query(@Nullable android.net.Network, @NonNull String, int, int, int, @NonNull java.util.concurrent.Executor, @NonNull android.net.DnsResolver.AnswerCallback<T>); method public <T> void query(@Nullable android.net.Network, @NonNull byte[], int, @NonNull java.util.concurrent.Executor, @Nullable android.os.CancellationSignal, @NonNull android.net.DnsResolver.AnswerCallback<T>); method public <T> void query(@Nullable android.net.Network, @NonNull String, int, int, int, @NonNull java.util.concurrent.Executor, @Nullable android.os.CancellationSignal, @NonNull android.net.DnsResolver.AnswerCallback<T>); field public static final int CLASS_IN = 1; // 0x1 field public static final int FLAG_EMPTY = 0; // 0x0 field public static final int FLAG_NO_CACHE_LOOKUP = 4; // 0x4
core/java/android/net/DnsResolver.java +34 −4 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package android.net; import static android.net.NetworkUtils.resNetworkCancel; import static android.net.NetworkUtils.resNetworkQuery; import static android.net.NetworkUtils.resNetworkResult; import static android.net.NetworkUtils.resNetworkSend; Loading @@ -26,6 +27,7 @@ import android.annotation.CallbackExecutor; import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.os.CancellationSignal; import android.os.Looper; import android.system.ErrnoException; import android.util.Log; Loading Loading @@ -191,11 +193,18 @@ public final class DnsResolver { * @param query blob message * @param flags flags as a combination of the FLAGS_* constants * @param executor The {@link Executor} that the callback should be executed on. * @param cancellationSignal used by the caller to signal if the query should be * cancelled. May be {@code null}. * @param callback an {@link AnswerCallback} which will be called to notify the caller * of the result of dns query. */ public <T> void query(@Nullable Network network, @NonNull byte[] query, @QueryFlag int flags, @NonNull @CallbackExecutor Executor executor, @NonNull AnswerCallback<T> callback) { @NonNull @CallbackExecutor Executor executor, @Nullable CancellationSignal cancellationSignal, @NonNull AnswerCallback<T> callback) { if (cancellationSignal != null && cancellationSignal.isCanceled()) { return; } final FileDescriptor queryfd; try { queryfd = resNetworkSend((network != null Loading @@ -205,6 +214,7 @@ public final class DnsResolver { return; } maybeAddCancellationSignal(cancellationSignal, queryfd); registerFDListener(executor, queryfd, callback); } Loading @@ -219,12 +229,19 @@ public final class DnsResolver { * @param nsType dns resource record (RR) type as one of the TYPE_* constants * @param flags flags as a combination of the FLAGS_* constants * @param executor The {@link Executor} that the callback should be executed on. * @param cancellationSignal used by the caller to signal if the query should be * cancelled. May be {@code null}. * @param callback an {@link AnswerCallback} which will be called to notify the caller * of the result of dns query. */ public <T> void query(@Nullable Network network, @NonNull String domain, @QueryClass int nsClass, @QueryType int nsType, @QueryFlag int flags, @NonNull @CallbackExecutor Executor executor, @NonNull AnswerCallback<T> callback) { @NonNull @CallbackExecutor Executor executor, @Nullable CancellationSignal cancellationSignal, @NonNull AnswerCallback<T> callback) { if (cancellationSignal != null && cancellationSignal.isCanceled()) { return; } final FileDescriptor queryfd; try { queryfd = resNetworkQuery((network != null Loading @@ -233,6 +250,8 @@ public final class DnsResolver { callback.onQueryException(e); return; } maybeAddCancellationSignal(cancellationSignal, queryfd); registerFDListener(executor, queryfd, callback); } Loading Loading @@ -264,6 +283,17 @@ public final class DnsResolver { }); } private void maybeAddCancellationSignal(@Nullable CancellationSignal cancellationSignal, @NonNull FileDescriptor queryfd) { if (cancellationSignal == null) return; cancellationSignal.setOnCancelListener( () -> { Looper.getMainLooper().getQueue() .removeOnFileDescriptorEventListener(queryfd); resNetworkCancel(queryfd); }); } private static class DnsAddressAnswer extends DnsPacket { private static final String TAG = "DnsResolver.DnsAddressAnswer"; private static final boolean DBG = false; Loading
core/java/android/net/NetworkUtils.java +6 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,12 @@ public class NetworkUtils { */ public static native byte[] resNetworkResult(FileDescriptor fd) throws ErrnoException; /** * DNS resolver series jni method. * Attempts to cancel the in-progress query associated with the {@code fd}. */ public static native void resNetworkCancel(FileDescriptor fd); /** * Add an entry into the ARP cache. */ Loading
core/jni/android_net_NetUtils.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -487,6 +487,11 @@ static jbyteArray android_net_utils_resNetworkResult(JNIEnv *env, jobject thiz, return answer; } static void android_net_utils_resNetworkCancel(JNIEnv *env, jobject thiz, jobject javaFd) { int fd = jniGetFDFromFileDescriptor(env, javaFd); resNetworkCancel(fd); } static jobject android_net_utils_getTcpRepairWindow(JNIEnv *env, jobject thiz, jobject javaFd) { if (javaFd == NULL) { jniThrowNullPointerException(env, NULL); Loading Loading @@ -546,6 +551,7 @@ static const JNINativeMethod gNetworkUtilMethods[] = { { "resNetworkSend", "(I[BII)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkSend }, { "resNetworkQuery", "(ILjava/lang/String;III)Ljava/io/FileDescriptor;", (void*) android_net_utils_resNetworkQuery }, { "resNetworkResult", "(Ljava/io/FileDescriptor;)[B", (void*) android_net_utils_resNetworkResult }, { "resNetworkCancel", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_resNetworkCancel }, }; int register_android_net_NetworkUtils(JNIEnv* env) Loading