Merge "Remove ResolveUtil from frameworks/base callers" am: 0e1621296f

am: 0bd9ac4b69

Change-Id: I3199337fd168f58f13a547d4eaff2be069a22f3d
This commit is contained in:
Erik Kline
2018-08-28 20:21:50 -07:00
committed by android-build-merger
7 changed files with 27 additions and 38 deletions

View File

@@ -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());
}
/**

View File

@@ -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);
}
/**

View File

@@ -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) {

View File

@@ -33,7 +33,6 @@ import android.net.NetworkRequest;
import android.net.Proxy;
import android.net.Uri;
import android.net.captiveportal.CaptivePortalProbeSpec;
import android.net.dns.ResolvUtil;
import android.net.http.SslError;
import android.net.wifi.WifiInfo;
import android.os.Build;
@@ -132,9 +131,9 @@ public class CaptivePortalLoginActivity extends Activity {
}
// Also initializes proxy system properties.
mNetwork = mNetwork.getPrivateDnsBypassingCopy();
mCm.bindProcessToNetwork(mNetwork);
mCm.setProcessDefaultNetworkForHostResolution(
ResolvUtil.getNetworkWithUseLocalNameserversFlag(mNetwork));
mCm.setProcessDefaultNetworkForHostResolution(mNetwork);
// Proxy system properties must be initialized before setContentView is called because
// setContentView initializes the WebView logic which in turn reads the system properties.
@@ -334,7 +333,6 @@ public class CaptivePortalLoginActivity extends Activity {
// TODO: reuse NetworkMonitor facilities for consistent captive portal detection.
new Thread(new Runnable() {
public void run() {
final Network network = ResolvUtil.makeNetworkWithPrivateDnsBypass(mNetwork);
// Give time for captive portal to open.
try {
Thread.sleep(1000);
@@ -344,7 +342,7 @@ public class CaptivePortalLoginActivity extends Activity {
int httpResponseCode = 500;
String locationHeader = null;
try {
urlConnection = (HttpURLConnection) network.openConnection(mUrl);
urlConnection = (HttpURLConnection) mNetwork.openConnection(mUrl);
urlConnection.setInstanceFollowRedirects(false);
urlConnection.setConnectTimeout(SOCKET_TIMEOUT_MS);
urlConnection.setReadTimeout(SOCKET_TIMEOUT_MS);

View File

@@ -35,7 +35,6 @@ import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkUtils;
import android.net.Uri;
import android.net.dns.ResolvUtil;
import android.os.Binder;
import android.os.INetworkManagementService;
import android.os.UserHandle;
@@ -174,15 +173,6 @@ public class DnsManager {
return new PrivateDnsConfig(useTls);
}
public static PrivateDnsConfig tryBlockingResolveOf(Network network, String name) {
try {
final InetAddress[] ips = ResolvUtil.blockingResolveAllLocally(network, name);
return new PrivateDnsConfig(name, ips);
} catch (UnknownHostException uhe) {
return new PrivateDnsConfig(name, null);
}
}
public static Uri[] getPrivateDnsSettingsUris() {
return new Uri[]{
Settings.Global.getUriFor(PRIVATE_DNS_DEFAULT_MODE),

View File

@@ -43,7 +43,6 @@ import android.net.TrafficStats;
import android.net.Uri;
import android.net.captiveportal.CaptivePortalProbeResult;
import android.net.captiveportal.CaptivePortalProbeSpec;
import android.net.dns.ResolvUtil;
import android.net.metrics.IpConnectivityLog;
import android.net.metrics.NetworkEvent;
import android.net.metrics.ValidationProbeEvent;
@@ -326,7 +325,7 @@ public class NetworkMonitor extends StateMachine {
mConnectivityServiceHandler = handler;
mDependencies = deps;
mNetworkAgentInfo = networkAgentInfo;
mNetwork = deps.getNetwork(networkAgentInfo);
mNetwork = deps.getNetwork(networkAgentInfo).getPrivateDnsBypassingCopy();
mNetId = mNetwork.netId;
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
@@ -800,9 +799,7 @@ public class NetworkMonitor extends StateMachine {
private void resolveStrictModeHostname() {
try {
// Do a blocking DNS resolution using the network-assigned nameservers.
// Do not set AI_ADDRCONFIG in ai_flags so we get all address families in advance.
final InetAddress[] ips = ResolvUtil.blockingResolveAllLocally(
mNetwork, mPrivateDnsProviderHostname, 0 /* aiFlags */);
final InetAddress[] ips = mNetwork.getAllByName(mPrivateDnsProviderHostname);
mPrivateDnsConfig = new PrivateDnsConfig(mPrivateDnsProviderHostname, ips);
validationLog("Strict mode hostname resolved: " + mPrivateDnsConfig);
} catch (UnknownHostException uhe) {
@@ -860,14 +857,13 @@ public class NetworkMonitor extends StateMachine {
// to complete, regardless of how many IP addresses a host has.
private static class OneAddressPerFamilyNetwork extends Network {
public OneAddressPerFamilyNetwork(Network network) {
super(network);
// Always bypass Private DNS.
super(network.getPrivateDnsBypassingCopy());
}
@Override
public InetAddress[] getAllByName(String host) throws UnknownHostException {
// Always bypass Private DNS.
final List<InetAddress> addrs = Arrays.asList(
ResolvUtil.blockingResolveAllLocally(this, host));
final List<InetAddress> addrs = Arrays.asList(super.getAllByName(host));
// Ensure the address family of the first address is tried first.
LinkedHashMap<Class, InetAddress> addressByFamily = new LinkedHashMap<>();

View File

@@ -106,6 +106,7 @@ public class NetworkMonitorTest {
anyString())).thenReturn(TEST_HTTP_URL);
when(mDependencies.getSetting(any(), eq(Settings.Global.CAPTIVE_PORTAL_HTTPS_URL),
anyString())).thenReturn(TEST_HTTPS_URL);
when(mNetwork.getPrivateDnsBypassingCopy()).thenReturn(mNetwork);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephony);
when(mContext.getSystemService(Context.WIFI_SERVICE)).thenReturn(mWifi);