summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorErik Kline <ek@google.com>2018-08-28 20:31:13 -0700
committerandroid-build-merger <android-build-merger@google.com>2018-08-28 20:31:13 -0700
commitd89fa25882a65be67cd9ea4bb89e730711d1c643 (patch)
treec54be6c9a04aa0759b64e9f3d94aabe21e20767b /core/java
parent2de8afd0a11c408a98221c9118b876f187a4f2e5 (diff)
parent37e01c985ded50ddca88f4c383ac76adfa938b47 (diff)
Merge "Remove ResolveUtil from frameworks/base callers" am: 0e1621296f am: 0bd9ac4b69
am: 37e01c985d Change-Id: Iddadeb5dc0b97180deac407f3196185edd3e0340
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/net/ConnectivityManager.java2
-rw-r--r--core/java/android/net/Network.java21
-rw-r--r--core/java/android/net/SntpClient.java9
3 files changed, 18 insertions, 14 deletions
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index fb916d38f3ba..ce1879620ce3 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -3840,7 +3840,7 @@ public class ConnectivityManager {
@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 142023d40c0e..bf2344d4a9f6 100644
--- a/core/java/android/net/Network.java
+++ b/core/java/android/net/Network.java
@@ -100,21 +100,29 @@ public class Network implements Parcelable {
// 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 @@ public class Network implements Parcelable {
* 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 @@ public class Network implements Parcelable {
}
/**
- * 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 10c0ce25e97b..b8d7cf167ca8 100644
--- a/core/java/android/net/SntpClient.java
+++ b/core/java/android/net/SntpClient.java
@@ -85,19 +85,16 @@ public class SntpClient {
* @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) {