Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bd9ac4b authored by Erik Kline's avatar Erik Kline Committed by android-build-merger
Browse files

Merge "Remove ResolveUtil from frameworks/base callers"

am: 0e162129

Change-Id: Ibc885ccd9531706df029154f7ec4fde71bf600d1
parents 1ed3e96e 0e162129
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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());
    }

    /**
+14 −7
Original line number Diff line number Diff line
@@ -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);
    }

    /**
+3 −6
Original line number Diff line number Diff line
@@ -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) {
+3 −5
Original line number Diff line number Diff line
@@ -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);
+0 −10
Original line number Diff line number Diff line
@@ -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),
Loading