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

Commit d118c2b4 authored by Chalard Jean's avatar Chalard Jean Committed by android-build-merger
Browse files

Merge changes I6abd2221,I2c149d29,I45d22857,I1f879b2c,If4986a25, ... am: 6c0106b5

am: 85bae863

Change-Id: Ica8e290909a34976e00bebbb622dd49d8f0d6b8d
parents 267ef30c 85bae863
Loading
Loading
Loading
Loading
+98 −87
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import java.util.Collections;
import java.util.Hashtable;
import java.util.Hashtable;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Objects;
import java.util.StringJoiner;


/**
/**
 * Describes the properties of a network link.
 * Describes the properties of a network link.
@@ -48,13 +49,13 @@ import java.util.Objects;
public final class LinkProperties implements Parcelable {
public final class LinkProperties implements Parcelable {
    // The interface described by the network link.
    // The interface described by the network link.
    private String mIfaceName;
    private String mIfaceName;
    private ArrayList<LinkAddress> mLinkAddresses = new ArrayList<LinkAddress>();
    private ArrayList<LinkAddress> mLinkAddresses = new ArrayList<>();
    private ArrayList<InetAddress> mDnses = new ArrayList<InetAddress>();
    private ArrayList<InetAddress> mDnses = new ArrayList<>();
    private ArrayList<InetAddress> mValidatedPrivateDnses = new ArrayList<InetAddress>();
    private ArrayList<InetAddress> mValidatedPrivateDnses = new ArrayList<>();
    private boolean mUsePrivateDns;
    private boolean mUsePrivateDns;
    private String mPrivateDnsServerName;
    private String mPrivateDnsServerName;
    private String mDomains;
    private String mDomains;
    private ArrayList<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
    private ArrayList<RouteInfo> mRoutes = new ArrayList<>();
    private ProxyInfo mHttpProxy;
    private ProxyInfo mHttpProxy;
    private int mMtu;
    private int mMtu;
    // in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max"
    // in the format "rmem_min,rmem_def,rmem_max,wmem_min,wmem_def,wmem_max"
@@ -66,15 +67,14 @@ public final class LinkProperties implements Parcelable {


    // Stores the properties of links that are "stacked" above this link.
    // Stores the properties of links that are "stacked" above this link.
    // Indexed by interface name to allow modification and to prevent duplicates being added.
    // Indexed by interface name to allow modification and to prevent duplicates being added.
    private Hashtable<String, LinkProperties> mStackedLinks =
    private Hashtable<String, LinkProperties> mStackedLinks = new Hashtable<>();
        new Hashtable<String, LinkProperties>();


    /**
    /**
     * @hide
     * @hide
     */
     */
    public static class CompareResult<T> {
    public static class CompareResult<T> {
        public final List<T> removed = new ArrayList<T>();
        public final List<T> removed = new ArrayList<>();
        public final List<T> added = new ArrayList<T>();
        public final List<T> added = new ArrayList<>();


        public CompareResult() {}
        public CompareResult() {}


@@ -93,12 +93,9 @@ public final class LinkProperties implements Parcelable {


        @Override
        @Override
        public String toString() {
        public String toString() {
            String retVal = "removed=[";
            return "removed=[" + TextUtils.join(",", removed)
            for (T addr : removed) retVal += addr.toString() + ",";
                    + "] added=[" + TextUtils.join(",", added)
            retVal += "] added=[";
                    + "]";
            for (T addr : added) retVal += addr.toString() + ",";
            retVal += "]";
            return retVal;
        }
        }
    }
    }


@@ -120,7 +117,7 @@ public final class LinkProperties implements Parcelable {
    public static ProvisioningChange compareProvisioning(
    public static ProvisioningChange compareProvisioning(
            LinkProperties before, LinkProperties after) {
            LinkProperties before, LinkProperties after) {
        if (before.isProvisioned() && after.isProvisioned()) {
        if (before.isProvisioned() && after.isProvisioned()) {
            // On dualstack networks, DHCPv4 renewals can occasionally fail.
            // On dual-stack networks, DHCPv4 renewals can occasionally fail.
            // When this happens, IPv6-reachable services continue to function
            // When this happens, IPv6-reachable services continue to function
            // normally but IPv4-only services (naturally) fail.
            // normally but IPv4-only services (naturally) fail.
            //
            //
@@ -131,7 +128,7 @@ public final class LinkProperties implements Parcelable {
            //
            //
            // For users, this is confusing and unexpected behaviour, and is
            // For users, this is confusing and unexpected behaviour, and is
            // not necessarily easy to diagnose.  Therefore, we treat changing
            // not necessarily easy to diagnose.  Therefore, we treat changing
            // from a dualstack network to an IPv6-only network equivalent to
            // from a dual-stack network to an IPv6-only network equivalent to
            // a total loss of provisioning.
            // a total loss of provisioning.
            //
            //
            // For one such example of this, see b/18867306.
            // For one such example of this, see b/18867306.
@@ -139,7 +136,7 @@ public final class LinkProperties implements Parcelable {
            // Additionally, losing IPv6 provisioning can result in TCP
            // Additionally, losing IPv6 provisioning can result in TCP
            // connections getting stuck until timeouts fire and other
            // connections getting stuck until timeouts fire and other
            // baffling failures. Therefore, loss of either IPv4 or IPv6 on a
            // baffling failures. Therefore, loss of either IPv4 or IPv6 on a
            // previously dualstack network is deemed a lost of provisioning.
            // previously dual-stack network is deemed a lost of provisioning.
            if ((before.isIPv4Provisioned() && !after.isIPv4Provisioned()) ||
            if ((before.isIPv4Provisioned() && !after.isIPv4Provisioned()) ||
                (before.isIPv6Provisioned() && !after.isIPv6Provisioned())) {
                (before.isIPv6Provisioned() && !after.isIPv6Provisioned())) {
                return ProvisioningChange.LOST_PROVISIONING;
                return ProvisioningChange.LOST_PROVISIONING;
@@ -165,22 +162,19 @@ public final class LinkProperties implements Parcelable {
     */
     */
    public LinkProperties(LinkProperties source) {
    public LinkProperties(LinkProperties source) {
        if (source != null) {
        if (source != null) {
            mIfaceName = source.getInterfaceName();
            mIfaceName = source.mIfaceName;
            for (LinkAddress l : source.getLinkAddresses()) mLinkAddresses.add(l);
            mLinkAddresses.addAll(source.mLinkAddresses);
            for (InetAddress i : source.getDnsServers()) mDnses.add(i);
            mDnses.addAll(source.mDnses);
            for (InetAddress i : source.getValidatedPrivateDnsServers()) {
            mValidatedPrivateDnses.addAll(source.mValidatedPrivateDnses);
                mValidatedPrivateDnses.add(i);
            }
            mUsePrivateDns = source.mUsePrivateDns;
            mUsePrivateDns = source.mUsePrivateDns;
            mPrivateDnsServerName = source.mPrivateDnsServerName;
            mPrivateDnsServerName = source.mPrivateDnsServerName;
            mDomains = source.getDomains();
            mDomains = source.mDomains;
            for (RouteInfo r : source.getRoutes()) mRoutes.add(r);
            mRoutes.addAll(source.mRoutes);
            mHttpProxy = (source.getHttpProxy() == null)  ?
            mHttpProxy = (source.mHttpProxy == null) ? null : new ProxyInfo(source.mHttpProxy);
                    null : new ProxyInfo(source.getHttpProxy());
            for (LinkProperties l: source.mStackedLinks.values()) {
            for (LinkProperties l: source.mStackedLinks.values()) {
                addStackedLink(l);
                addStackedLink(l);
            }
            }
            setMtu(source.getMtu());
            setMtu(source.mMtu);
            mTcpBufferSizes = source.mTcpBufferSizes;
            mTcpBufferSizes = source.mTcpBufferSizes;
        }
        }
    }
    }
@@ -194,7 +188,7 @@ public final class LinkProperties implements Parcelable {
     */
     */
    public void setInterfaceName(String iface) {
    public void setInterfaceName(String iface) {
        mIfaceName = iface;
        mIfaceName = iface;
        ArrayList<RouteInfo> newRoutes = new ArrayList<RouteInfo>(mRoutes.size());
        ArrayList<RouteInfo> newRoutes = new ArrayList<>(mRoutes.size());
        for (RouteInfo route : mRoutes) {
        for (RouteInfo route : mRoutes) {
            newRoutes.add(routeWithInterface(route));
            newRoutes.add(routeWithInterface(route));
        }
        }
@@ -214,8 +208,8 @@ public final class LinkProperties implements Parcelable {
     * @hide
     * @hide
     */
     */
    public List<String> getAllInterfaceNames() {
    public List<String> getAllInterfaceNames() {
        List<String> interfaceNames = new ArrayList<String>(mStackedLinks.size() + 1);
        List<String> interfaceNames = new ArrayList<>(mStackedLinks.size() + 1);
        if (mIfaceName != null) interfaceNames.add(new String(mIfaceName));
        if (mIfaceName != null) interfaceNames.add(mIfaceName);
        for (LinkProperties stacked: mStackedLinks.values()) {
        for (LinkProperties stacked: mStackedLinks.values()) {
            interfaceNames.addAll(stacked.getAllInterfaceNames());
            interfaceNames.addAll(stacked.getAllInterfaceNames());
        }
        }
@@ -229,11 +223,11 @@ public final class LinkProperties implements Parcelable {
     * prefix lengths for each address.  This is a simplified utility alternative to
     * prefix lengths for each address.  This is a simplified utility alternative to
     * {@link LinkProperties#getLinkAddresses}.
     * {@link LinkProperties#getLinkAddresses}.
     *
     *
     * @return An umodifiable {@link List} of {@link InetAddress} for this link.
     * @return An unmodifiable {@link List} of {@link InetAddress} for this link.
     * @hide
     * @hide
     */
     */
    public List<InetAddress> getAddresses() {
    public List<InetAddress> getAddresses() {
        List<InetAddress> addresses = new ArrayList<InetAddress>();
        List<InetAddress> addresses = new ArrayList<>();
        for (LinkAddress linkAddress : mLinkAddresses) {
        for (LinkAddress linkAddress : mLinkAddresses) {
            addresses.add(linkAddress.getAddress());
            addresses.add(linkAddress.getAddress());
        }
        }
@@ -245,7 +239,7 @@ public final class LinkProperties implements Parcelable {
     * @hide
     * @hide
     */
     */
    public List<InetAddress> getAllAddresses() {
    public List<InetAddress> getAllAddresses() {
        List<InetAddress> addresses = new ArrayList<InetAddress>();
        List<InetAddress> addresses = new ArrayList<>();
        for (LinkAddress linkAddress : mLinkAddresses) {
        for (LinkAddress linkAddress : mLinkAddresses) {
            addresses.add(linkAddress.getAddress());
            addresses.add(linkAddress.getAddress());
        }
        }
@@ -322,8 +316,7 @@ public final class LinkProperties implements Parcelable {
     * @hide
     * @hide
     */
     */
    public List<LinkAddress> getAllLinkAddresses() {
    public List<LinkAddress> getAllLinkAddresses() {
        List<LinkAddress> addresses = new ArrayList<LinkAddress>();
        List<LinkAddress> addresses = new ArrayList<>(mLinkAddresses);
        addresses.addAll(mLinkAddresses);
        for (LinkProperties stacked: mStackedLinks.values()) {
        for (LinkProperties stacked: mStackedLinks.values()) {
            addresses.addAll(stacked.getAllLinkAddresses());
            addresses.addAll(stacked.getAllLinkAddresses());
        }
        }
@@ -391,7 +384,7 @@ public final class LinkProperties implements Parcelable {
    /**
    /**
     * Returns all the {@link InetAddress} for DNS servers on this link.
     * Returns all the {@link InetAddress} for DNS servers on this link.
     *
     *
     * @return An umodifiable {@link List} of {@link InetAddress} for DNS servers on
     * @return An unmodifiable {@link List} of {@link InetAddress} for DNS servers on
     *         this link.
     *         this link.
     */
     */
    public List<InetAddress> getDnsServers() {
    public List<InetAddress> getDnsServers() {
@@ -653,8 +646,7 @@ public final class LinkProperties implements Parcelable {
     * @hide
     * @hide
     */
     */
    public List<RouteInfo> getAllRoutes() {
    public List<RouteInfo> getAllRoutes() {
        List<RouteInfo> routes = new ArrayList<>();
        List<RouteInfo> routes = new ArrayList<>(mRoutes);
        routes.addAll(mRoutes);
        for (LinkProperties stacked: mStackedLinks.values()) {
        for (LinkProperties stacked: mStackedLinks.values()) {
            routes.addAll(stacked.getAllRoutes());
            routes.addAll(stacked.getAllRoutes());
        }
        }
@@ -725,9 +717,9 @@ public final class LinkProperties implements Parcelable {
     */
     */
    public @NonNull List<LinkProperties> getStackedLinks() {
    public @NonNull List<LinkProperties> getStackedLinks() {
        if (mStackedLinks.isEmpty()) {
        if (mStackedLinks.isEmpty()) {
            return Collections.EMPTY_LIST;
            return Collections.emptyList();
        }
        }
        List<LinkProperties> stacked = new ArrayList<LinkProperties>();
        List<LinkProperties> stacked = new ArrayList<>();
        for (LinkProperties link : mStackedLinks.values()) {
        for (LinkProperties link : mStackedLinks.values()) {
            stacked.add(new LinkProperties(link));
            stacked.add(new LinkProperties(link));
        }
        }
@@ -761,57 +753,76 @@ public final class LinkProperties implements Parcelable {


    @Override
    @Override
    public String toString() {
    public String toString() {
        String ifaceName = (mIfaceName == null ? "" : "InterfaceName: " + mIfaceName + " ");
        // Space as a separator, so no need for spaces at start/end of the individual fragments.
        final StringJoiner resultJoiner = new StringJoiner(" ", "{", "}");


        String linkAddresses = "LinkAddresses: [";
        if (mIfaceName != null) {
        for (LinkAddress addr : mLinkAddresses) linkAddresses += addr.toString() + ",";
            resultJoiner.add("InterfaceName:");
        linkAddresses += "] ";
            resultJoiner.add(mIfaceName);
        }


        String dns = "DnsAddresses: [";
        resultJoiner.add("LinkAddresses: [");
        for (InetAddress addr : mDnses) dns += addr.getHostAddress() + ",";
        if (!mLinkAddresses.isEmpty()) {
        dns += "] ";
            resultJoiner.add(TextUtils.join(",", mLinkAddresses));
        }
        resultJoiner.add("]");

        resultJoiner.add("DnsAddresses: [");
        if (!mDnses.isEmpty()) {
            resultJoiner.add(TextUtils.join(",", mDnses));
        }
        resultJoiner.add("]");


        String usePrivateDns = "UsePrivateDns: " + mUsePrivateDns + " ";
        if (mUsePrivateDns) {
            resultJoiner.add("UsePrivateDns: true");
        }


        String privateDnsServerName = "";
        if (mPrivateDnsServerName != null) {
        if (mPrivateDnsServerName != null) {
            privateDnsServerName = "PrivateDnsServerName: " + mPrivateDnsServerName + " ";
            resultJoiner.add("PrivateDnsServerName:");
            resultJoiner.add(mPrivateDnsServerName);
        }
        }


        String validatedPrivateDns = "";
        if (!mValidatedPrivateDnses.isEmpty()) {
        if (!mValidatedPrivateDnses.isEmpty()) {
            validatedPrivateDns = "ValidatedPrivateDnsAddresses: [";
            final StringJoiner validatedPrivateDnsesJoiner =
            for (InetAddress addr : mValidatedPrivateDnses) {
                    new StringJoiner(",", "ValidatedPrivateDnsAddresses: [", "]");
                validatedPrivateDns += addr.getHostAddress() + ",";
            for (final InetAddress addr : mValidatedPrivateDnses) {
                validatedPrivateDnsesJoiner.add(addr.getHostAddress());
            }
            }
            validatedPrivateDns += "] ";
            resultJoiner.add(validatedPrivateDnsesJoiner.toString());
        }
        }


        String domainName = "Domains: " + mDomains;
        resultJoiner.add("Domains:");
        resultJoiner.add(mDomains);


        String mtu = " MTU: " + mMtu;
        resultJoiner.add("MTU:");
        resultJoiner.add(Integer.toString(mMtu));


        String tcpBuffSizes = "";
        if (mTcpBufferSizes != null) {
        if (mTcpBufferSizes != null) {
            tcpBuffSizes = " TcpBufferSizes: " + mTcpBufferSizes;
            resultJoiner.add("TcpBufferSizes:");
            resultJoiner.add(mTcpBufferSizes);
        }
        }


        String routes = " Routes: [";
        resultJoiner.add("Routes: [");
        for (RouteInfo route : mRoutes) routes += route.toString() + ",";
        if (!mRoutes.isEmpty()) {
        routes += "] ";
            resultJoiner.add(TextUtils.join(",", mRoutes));
        String proxy = (mHttpProxy == null ? "" : " HttpProxy: " + mHttpProxy.toString() + " ");
        }
        resultJoiner.add("]");


        String stacked = "";
        if (mHttpProxy != null) {
        if (mStackedLinks.values().size() > 0) {
            resultJoiner.add("HttpProxy:");
            stacked += " Stacked: [";
            resultJoiner.add(mHttpProxy.toString());
            for (LinkProperties link: mStackedLinks.values()) {
        }
                stacked += " [" + link.toString() + " ],";

        final Collection<LinkProperties> stackedLinksValues = mStackedLinks.values();
        if (!stackedLinksValues.isEmpty()) {
            final StringJoiner stackedLinksJoiner = new StringJoiner(",", "Stacked: [", "]");
            for (final LinkProperties lp : stackedLinksValues) {
                stackedLinksJoiner.add("[ " + lp + " ]");
            }
            }
            stacked += "] ";
            resultJoiner.add(stackedLinksJoiner.toString());
        }
        }
        return "{" + ifaceName + linkAddresses + routes + dns + usePrivateDns

            + privateDnsServerName + validatedPrivateDns + domainName + mtu + tcpBuffSizes + proxy
        return resultJoiner.toString();
            + stacked + "}";
    }
    }


    /**
    /**
@@ -1028,7 +1039,7 @@ public final class LinkProperties implements Parcelable {
        if (mDomains == null) {
        if (mDomains == null) {
            if (targetDomains != null) return false;
            if (targetDomains != null) return false;
        } else {
        } else {
            if (mDomains.equals(targetDomains) == false) return false;
            if (!mDomains.equals(targetDomains)) return false;
        }
        }
        return (mDnses.size() == targetDnses.size()) ?
        return (mDnses.size() == targetDnses.size()) ?
                mDnses.containsAll(targetDnses) : false;
                mDnses.containsAll(targetDnses) : false;
@@ -1130,7 +1141,6 @@ public final class LinkProperties implements Parcelable {
        return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes);
        return Objects.equals(mTcpBufferSizes, target.mTcpBufferSizes);
    }
    }


    @Override
    /**
    /**
     * Compares this {@code LinkProperties} instance against the target
     * Compares this {@code LinkProperties} instance against the target
     * LinkProperties in {@code obj}. Two LinkPropertieses are equal if
     * LinkProperties in {@code obj}. Two LinkPropertieses are equal if
@@ -1145,13 +1155,14 @@ public final class LinkProperties implements Parcelable {
     * @param obj the object to be tested for equality.
     * @param obj the object to be tested for equality.
     * @return {@code true} if both objects are equal, {@code false} otherwise.
     * @return {@code true} if both objects are equal, {@code false} otherwise.
     */
     */
    @Override
    public boolean equals(Object obj) {
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (this == obj) return true;


        if (!(obj instanceof LinkProperties)) return false;
        if (!(obj instanceof LinkProperties)) return false;


        LinkProperties target = (LinkProperties) obj;
        LinkProperties target = (LinkProperties) obj;
        /**
        /*
         * This method does not check that stacked interfaces are equal, because
         * This method does not check that stacked interfaces are equal, because
         * stacked interfaces are not so much a property of the link as a
         * stacked interfaces are not so much a property of the link as a
         * description of connections between links.
         * description of connections between links.
@@ -1258,12 +1269,13 @@ public final class LinkProperties implements Parcelable {
    }
    }




    @Override
    /**
    /**
     * generate hashcode based on significant fields
     * Generate hashcode based on significant fields
     *
     * Equal objects must produce the same hash code, while unequal objects
     * Equal objects must produce the same hash code, while unequal objects
     * may have the same hash codes.
     * may have the same hash codes.
     */
     */
    @Override
    public int hashCode() {
    public int hashCode() {
        return ((null == mIfaceName) ? 0 : mIfaceName.hashCode()
        return ((null == mIfaceName) ? 0 : mIfaceName.hashCode()
                + mLinkAddresses.size() * 31
                + mLinkAddresses.size() * 31
@@ -1313,7 +1325,7 @@ public final class LinkProperties implements Parcelable {
        } else {
        } else {
            dest.writeByte((byte)0);
            dest.writeByte((byte)0);
        }
        }
        ArrayList<LinkProperties> stackedLinks = new ArrayList(mStackedLinks.values());
        ArrayList<LinkProperties> stackedLinks = new ArrayList<>(mStackedLinks.values());
        dest.writeList(stackedLinks);
        dest.writeList(stackedLinks);
    }
    }


@@ -1331,7 +1343,7 @@ public final class LinkProperties implements Parcelable {
                }
                }
                int addressCount = in.readInt();
                int addressCount = in.readInt();
                for (int i = 0; i < addressCount; i++) {
                for (int i = 0; i < addressCount; i++) {
                    netProp.addLinkAddress((LinkAddress) in.readParcelable(null));
                    netProp.addLinkAddress(in.readParcelable(null));
                }
                }
                addressCount = in.readInt();
                addressCount = in.readInt();
                for (int i = 0; i < addressCount; i++) {
                for (int i = 0; i < addressCount; i++) {
@@ -1353,10 +1365,10 @@ public final class LinkProperties implements Parcelable {
                netProp.setTcpBufferSizes(in.readString());
                netProp.setTcpBufferSizes(in.readString());
                addressCount = in.readInt();
                addressCount = in.readInt();
                for (int i = 0; i < addressCount; i++) {
                for (int i = 0; i < addressCount; i++) {
                    netProp.addRoute((RouteInfo) in.readParcelable(null));
                    netProp.addRoute(in.readParcelable(null));
                }
                }
                if (in.readByte() == 1) {
                if (in.readByte() == 1) {
                    netProp.setHttpProxy((ProxyInfo) in.readParcelable(null));
                    netProp.setHttpProxy(in.readParcelable(null));
                }
                }
                ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>();
                ArrayList<LinkProperties> stackedLinks = new ArrayList<LinkProperties>();
                in.readList(stackedLinks, LinkProperties.class.getClassLoader());
                in.readList(stackedLinks, LinkProperties.class.getClassLoader());
@@ -1377,10 +1389,9 @@ public final class LinkProperties implements Parcelable {
     */
     */
    public static boolean isValidMtu(int mtu, boolean ipv6) {
    public static boolean isValidMtu(int mtu, boolean ipv6) {
        if (ipv6) {
        if (ipv6) {
            if (mtu >= MIN_MTU_V6 && mtu <= MAX_MTU) return true;
            return mtu >= MIN_MTU_V6 && mtu <= MAX_MTU;
        } else {
        } else {
            if (mtu >= MIN_MTU && mtu <= MAX_MTU) return true;
            return mtu >= MIN_MTU && mtu <= MAX_MTU;
        }
        }
        return false;
    }
    }
}
}
+5 −11
Original line number Original line Diff line number Diff line
@@ -142,7 +142,7 @@ public class Network implements Parcelable {


    /**
    /**
     * Specify whether or not Private DNS should be bypassed when attempting
     * Specify whether or not Private DNS should be bypassed when attempting
     * to use {@link getAllByName()}/{@link getByName()} methods on the given
     * to use {@link #getAllByName(String)}/{@link #getByName(String)} methods on the given
     * instance for hostname resolution.
     * instance for hostname resolution.
     *
     *
     * @hide
     * @hide
@@ -169,13 +169,6 @@ public class Network implements Parcelable {
     * A {@code SocketFactory} that produces {@code Socket}'s bound to this network.
     * A {@code SocketFactory} that produces {@code Socket}'s bound to this network.
     */
     */
    private class NetworkBoundSocketFactory extends SocketFactory {
    private class NetworkBoundSocketFactory extends SocketFactory {
        private final int mNetId;

        public NetworkBoundSocketFactory(int netId) {
            super();
            mNetId = netId;
        }

        private Socket connectToHost(String host, int port, SocketAddress localAddress)
        private Socket connectToHost(String host, int port, SocketAddress localAddress)
                throws IOException {
                throws IOException {
            // Lookup addresses only on this Network.
            // Lookup addresses only on this Network.
@@ -201,7 +194,8 @@ public class Network implements Parcelable {
        }
        }


        @Override
        @Override
        public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
        public Socket createSocket(String host, int port, InetAddress localHost, int localPort)
                throws IOException {
            return connectToHost(host, port, new InetSocketAddress(localHost, localPort));
            return connectToHost(host, port, new InetSocketAddress(localHost, localPort));
        }
        }


@@ -265,7 +259,7 @@ public class Network implements Parcelable {
        if (mNetworkBoundSocketFactory == null) {
        if (mNetworkBoundSocketFactory == null) {
            synchronized (mLock) {
            synchronized (mLock) {
                if (mNetworkBoundSocketFactory == null) {
                if (mNetworkBoundSocketFactory == null) {
                    mNetworkBoundSocketFactory = new NetworkBoundSocketFactory(netId);
                    mNetworkBoundSocketFactory = new NetworkBoundSocketFactory();
                }
                }
            }
            }
        }
        }
@@ -475,7 +469,7 @@ public class Network implements Parcelable {


    @Override
    @Override
    public boolean equals(Object obj) {
    public boolean equals(Object obj) {
        if (obj instanceof Network == false) return false;
        if (!(obj instanceof Network)) return false;
        Network other = (Network)obj;
        Network other = (Network)obj;
        return this.netId == other.netId;
        return this.netId == other.netId;
    }
    }
+46 −150

File changed.

Preview size limit exceeded, changes collapsed.

+10 −12
Original line number Original line Diff line number Diff line
@@ -90,7 +90,7 @@ public class PacManager {
    private volatile boolean mHasDownloaded;
    private volatile boolean mHasDownloaded;


    private Handler mConnectivityHandler;
    private Handler mConnectivityHandler;
    private int mProxyMessage;
    private final int mProxyMessage;


    /**
    /**
     * Used for locking when setting mProxyService and all references to mCurrentPac.
     * Used for locking when setting mProxyService and all references to mCurrentPac.
@@ -99,7 +99,7 @@ public class PacManager {


    /**
    /**
     * Runnable to download PAC script.
     * Runnable to download PAC script.
     * The behavior relies on the assamption it always run on mNetThread to guarantee that the
     * The behavior relies on the assumption it always runs on mNetThread to guarantee that the
     * latest data fetched from mPacUrl is stored in mProxyService.
     * latest data fetched from mPacUrl is stored in mProxyService.
     */
     */
    private Runnable mPacDownloader = new Runnable() {
    private Runnable mPacDownloader = new Runnable() {
@@ -133,8 +133,6 @@ public class PacManager {
        }
        }
    };
    };


    private final HandlerThread mNetThread = new HandlerThread("android.pacmanager",
            android.os.Process.THREAD_PRIORITY_DEFAULT);
    private final Handler mNetThreadHandler;
    private final Handler mNetThreadHandler;


    class PacRefreshIntentReceiver extends BroadcastReceiver {
    class PacRefreshIntentReceiver extends BroadcastReceiver {
@@ -146,8 +144,10 @@ public class PacManager {
    public PacManager(Context context, Handler handler, int proxyMessage) {
    public PacManager(Context context, Handler handler, int proxyMessage) {
        mContext = context;
        mContext = context;
        mLastPort = -1;
        mLastPort = -1;
        mNetThread.start();
        final HandlerThread netThread = new HandlerThread("android.pacmanager",
        mNetThreadHandler = new Handler(mNetThread.getLooper());
                android.os.Process.THREAD_PRIORITY_DEFAULT);
        netThread.start();
        mNetThreadHandler = new Handler(netThread.getLooper());


        mPacRefreshIntent = PendingIntent.getBroadcast(
        mPacRefreshIntent = PendingIntent.getBroadcast(
                context, 0, new Intent(ACTION_PAC_REFRESH), 0);
                context, 0, new Intent(ACTION_PAC_REFRESH), 0);
@@ -208,7 +208,7 @@ public class PacManager {
    /**
    /**
     * Does a post and reports back the status code.
     * Does a post and reports back the status code.
     *
     *
     * @throws IOException
     * @throws IOException if the URL is malformed, or the PAC file is too big.
     */
     */
    private static String get(Uri pacUri) throws IOException {
    private static String get(Uri pacUri) throws IOException {
        URL url = new URL(pacUri.toString());
        URL url = new URL(pacUri.toString());
@@ -254,7 +254,7 @@ public class PacManager {
    private String getPacChangeDelay() {
    private String getPacChangeDelay() {
        final ContentResolver cr = mContext.getContentResolver();
        final ContentResolver cr = mContext.getContentResolver();


        /** Check system properties for the default value then use secure settings value, if any. */
        // Check system properties for the default value then use secure settings value, if any.
        String defaultDelay = SystemProperties.get(
        String defaultDelay = SystemProperties.get(
                "conn." + Settings.Global.PAC_CHANGE_DELAY,
                "conn." + Settings.Global.PAC_CHANGE_DELAY,
                DEFAULT_DELAYS);
                DEFAULT_DELAYS);
@@ -276,10 +276,9 @@ public class PacManager {
        getAlarmManager().set(AlarmManager.ELAPSED_REALTIME, timeTillTrigger, mPacRefreshIntent);
        getAlarmManager().set(AlarmManager.ELAPSED_REALTIME, timeTillTrigger, mPacRefreshIntent);
    }
    }


    private boolean setCurrentProxyScript(String script) {
    private void setCurrentProxyScript(String script) {
        if (mProxyService == null) {
        if (mProxyService == null) {
            Log.e(TAG, "setCurrentProxyScript: no proxy service");
            Log.e(TAG, "setCurrentProxyScript: no proxy service");
            return false;
        }
        }
        try {
        try {
            mProxyService.setPacFile(script);
            mProxyService.setPacFile(script);
@@ -287,7 +286,6 @@ public class PacManager {
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            Log.e(TAG, "Unable to set PAC file", e);
            Log.e(TAG, "Unable to set PAC file", e);
        }
        }
        return true;
    }
    }


    private void bind() {
    private void bind() {
@@ -351,7 +349,7 @@ public class PacManager {
                    try {
                    try {
                        callbackService.getProxyPort(new IProxyPortListener.Stub() {
                        callbackService.getProxyPort(new IProxyPortListener.Stub() {
                            @Override
                            @Override
                            public void setProxyPort(int port) throws RemoteException {
                            public void setProxyPort(int port) {
                                if (mLastPort != -1) {
                                if (mLastPort != -1) {
                                    // Always need to send if port changed
                                    // Always need to send if port changed
                                    mHasSentBroadcast = false;
                                    mHasSentBroadcast = false;
+184 −0

File added.

Preview size limit exceeded, changes collapsed.