Remove ResolveUtil from frameworks/base callers
Use the Private DNS bypass logic that was moved into Network.
Once all callers of ResolvUtil are updated to use this interface
ResolvUtil can be deleted.
Test: as follows
- built, flashed, booted
- runtest frameworks-net passes
- connection to captive portal network detects portal correctly
and the login activity functions as expected
Bug: 64133961
Bug: 72345192
Bug: 73872000
Bug: 78548486
Change-Id: If11ef2b5ffdc729f8449cf18dccd5f1eccbc51e6
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index fb916d3..ce18796 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -3840,7 +3840,7 @@
@UnsupportedAppUsage
public static boolean setProcessDefaultNetworkForHostResolution(Network network) {
return NetworkUtils.bindProcessToNetworkForHostResolution(
- network == null ? NETID_UNSET : network.netId);
+ (network == null) ? NETID_UNSET : network.getNetIdForResolv());
}
/**
diff --git a/core/java/android/net/Network.java b/core/java/android/net/Network.java
index 142023d..bf2344d 100644
--- a/core/java/android/net/Network.java
+++ b/core/java/android/net/Network.java
@@ -100,21 +100,29 @@
// anytime and (b) receivers should be explicit about attempts to bypass
// Private DNS so that the intent of the code is easily determined and
// code search audits are possible.
- private boolean mPrivateDnsBypass = false;
+ private final transient boolean mPrivateDnsBypass;
/**
* @hide
*/
@UnsupportedAppUsage
public Network(int netId) {
+ this(netId, false);
+ }
+
+ /**
+ * @hide
+ */
+ public Network(int netId, boolean privateDnsBypass) {
this.netId = netId;
+ this.mPrivateDnsBypass = privateDnsBypass;
}
/**
* @hide
*/
public Network(Network that) {
- this.netId = that.netId;
+ this(that.netId, that.mPrivateDnsBypass);
}
/**
@@ -133,8 +141,7 @@
* Operates the same as {@code InetAddress.getByName} except that host
* resolution is done on this network.
*
- * @param host
- * the hostName to be resolved to an address or {@code null}.
+ * @param host the hostname to be resolved to an address or {@code null}.
* @return the {@code InetAddress} instance representing the host.
* @throws UnknownHostException
* if the address lookup fails.
@@ -144,14 +151,14 @@
}
/**
- * Specify whether or not Private DNS should be bypassed when attempting
+ * Obtain a Network object for which Private DNS is to be bypassed when attempting
* to use {@link #getAllByName(String)}/{@link #getByName(String)} methods on the given
* instance for hostname resolution.
*
* @hide
*/
- public void setPrivateDnsBypass(boolean bypass) {
- mPrivateDnsBypass = bypass;
+ public Network getPrivateDnsBypassingCopy() {
+ return new Network(netId, true);
}
/**
diff --git a/core/java/android/net/SntpClient.java b/core/java/android/net/SntpClient.java
index 10c0ce2..b8d7cf1 100644
--- a/core/java/android/net/SntpClient.java
+++ b/core/java/android/net/SntpClient.java
@@ -85,19 +85,16 @@
* @return true if the transaction was successful.
*/
public boolean requestTime(String host, int timeout, Network network) {
- // This flag only affects DNS resolution and not other socket semantics,
- // therefore it's safe to set unilaterally rather than take more
- // defensive measures like making a copy.
- network.setPrivateDnsBypass(true);
+ final Network networkForResolv = network.getPrivateDnsBypassingCopy();
InetAddress address = null;
try {
- address = network.getByName(host);
+ address = networkForResolv.getByName(host);
} catch (Exception e) {
EventLogTags.writeNtpFailure(host, e.toString());
if (DBG) Log.d(TAG, "request time failed: " + e);
return false;
}
- return requestTime(address, NTP_PORT, timeout, network);
+ return requestTime(address, NTP_PORT, timeout, networkForResolv);
}
public boolean requestTime(InetAddress address, int port, int timeout, Network network) {