diff --git a/services/core/java/com/android/server/connectivity/KeepalivePacketData.java b/services/core/java/com/android/server/connectivity/KeepalivePacketData.java index 2ccfdd1f31..f6b73b7d69 100644 --- a/services/core/java/com/android/server/connectivity/KeepalivePacketData.java +++ b/services/core/java/com/android/server/connectivity/KeepalivePacketData.java @@ -16,6 +16,9 @@ package com.android.server.connectivity; +import static android.net.util.NetworkConstants.IPV4_HEADER_MIN_LEN; +import static android.net.util.NetworkConstants.UDP_HEADER_LEN; + import android.system.OsConstants; import android.net.ConnectivityManager; import android.net.NetworkUtils; @@ -57,9 +60,6 @@ public class KeepalivePacketData { /** Packet data. A raw byte string of packet data, not including the link-layer header. */ public final byte[] data; - private static final int IPV4_HEADER_LENGTH = 20; - private static final int UDP_HEADER_LENGTH = 8; - protected KeepalivePacketData(InetAddress srcAddress, int srcPort, InetAddress dstAddress, int dstPort, byte[] data) throws InvalidPacketException { this.srcAddress = srcAddress; @@ -111,7 +111,7 @@ public class KeepalivePacketData { throw new InvalidPacketException(ERROR_INVALID_PORT); } - int length = IPV4_HEADER_LENGTH + UDP_HEADER_LENGTH + 1; + int length = IPV4_HEADER_MIN_LEN + UDP_HEADER_LEN + 1; ByteBuffer buf = ByteBuffer.allocate(length); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort((short) 0x4500); // IP version and TOS @@ -130,7 +130,7 @@ public class KeepalivePacketData { buf.putShort((short) 0); // UDP checksum buf.put((byte) 0xff); // NAT-T keepalive buf.putShort(ipChecksumOffset, IpUtils.ipChecksum(buf, 0)); - buf.putShort(udpChecksumOffset, IpUtils.udpChecksum(buf, 0, IPV4_HEADER_LENGTH)); + buf.putShort(udpChecksumOffset, IpUtils.udpChecksum(buf, 0, IPV4_HEADER_MIN_LEN)); return new KeepalivePacketData(srcAddress, srcPort, dstAddress, dstPort, buf.array()); } diff --git a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java index a4d7242086..85b70ca0ff 100644 --- a/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java +++ b/services/core/java/com/android/server/connectivity/NetworkAgentInfo.java @@ -223,14 +223,6 @@ public class NetworkAgentInfo implements Comparable { // This represents the last score received from the NetworkAgent. private int currentScore; - // Penalty applied to scores of Networks that have not been validated. - private static final int UNVALIDATED_SCORE_PENALTY = 40; - - // Score for explicitly connected network. - // - // This ensures that a) the explicitly selected network is never trumped by anything else, and - // b) the explicitly selected network is never torn down. - private static final int MAXIMUM_NETWORK_SCORE = 100; // The list of NetworkRequests being satisfied by this Network. private final SparseArray mNetworkRequests = new SparseArray<>(); @@ -428,12 +420,12 @@ public class NetworkAgentInfo implements Comparable { // down an explicitly selected network before the user gets a chance to prefer it when // a higher-scoring network (e.g., Ethernet) is available. if (networkMisc.explicitlySelected && (networkMisc.acceptUnvalidated || pretendValidated)) { - return MAXIMUM_NETWORK_SCORE; + return ConnectivityConstants.MAXIMUM_NETWORK_SCORE; } int score = currentScore; if (!lastValidated && !pretendValidated && !ignoreWifiUnvalidationPenalty()) { - score -= UNVALIDATED_SCORE_PENALTY; + score -= ConnectivityConstants.UNVALIDATED_SCORE_PENALTY; } if (score < 0) score = 0; return score; diff --git a/services/core/java/com/android/server/connectivity/NetworkDiagnostics.java b/services/core/java/com/android/server/connectivity/NetworkDiagnostics.java index 85d1d1ef1d..c471f0caa3 100644 --- a/services/core/java/com/android/server/connectivity/NetworkDiagnostics.java +++ b/services/core/java/com/android/server/connectivity/NetworkDiagnostics.java @@ -24,6 +24,7 @@ import android.net.Network; import android.net.NetworkUtils; import android.net.RouteInfo; import android.net.TrafficStats; +import android.net.util.NetworkConstants; import android.os.SystemClock; import android.system.ErrnoException; import android.system.Os; @@ -421,8 +422,6 @@ public class NetworkDiagnostics { private class IcmpCheck extends SimpleSocketCheck implements Runnable { private static final int TIMEOUT_SEND = 100; private static final int TIMEOUT_RECV = 300; - private static final int ICMPV4_ECHO_REQUEST = 8; - private static final int ICMPV6_ECHO_REQUEST = 128; private static final int PACKET_BUFSIZE = 512; private final int mProtocol; private final int mIcmpType; @@ -432,11 +431,11 @@ public class NetworkDiagnostics { if (mAddressFamily == AF_INET6) { mProtocol = IPPROTO_ICMPV6; - mIcmpType = ICMPV6_ECHO_REQUEST; + mIcmpType = NetworkConstants.ICMPV6_ECHO_REQUEST_TYPE; mMeasurement.description = "ICMPv6"; } else { mProtocol = IPPROTO_ICMP; - mIcmpType = ICMPV4_ECHO_REQUEST; + mIcmpType = NetworkConstants.ICMPV4_ECHO_REQUEST_TYPE; mMeasurement.description = "ICMPv4"; } @@ -504,7 +503,6 @@ public class NetworkDiagnostics { private class DnsUdpCheck extends SimpleSocketCheck implements Runnable { private static final int TIMEOUT_SEND = 100; private static final int TIMEOUT_RECV = 500; - private static final int DNS_SERVER_PORT = 53; private static final int RR_TYPE_A = 1; private static final int RR_TYPE_AAAA = 28; private static final int PACKET_BUFSIZE = 512; @@ -546,7 +544,8 @@ public class NetworkDiagnostics { } try { - setupSocket(SOCK_DGRAM, IPPROTO_UDP, TIMEOUT_SEND, TIMEOUT_RECV, DNS_SERVER_PORT); + setupSocket(SOCK_DGRAM, IPPROTO_UDP, TIMEOUT_SEND, TIMEOUT_RECV, + NetworkConstants.DNS_SERVER_PORT); } catch (ErrnoException | IOException e) { mMeasurement.recordFailure(e.toString()); return;