Merge "Add documentation for CaptivePortal APP_RETURN_*" am: 3886def4fa am: c168c30849
am: befedce6dd
Change-Id: I2fce43bf23ac9689f69bc2c432b3032cc9abb7d9
diff --git a/core/java/android/net/CaptivePortal.java b/core/java/android/net/CaptivePortal.java
index ba7323d..7873fc0 100644
--- a/core/java/android/net/CaptivePortal.java
+++ b/core/java/android/net/CaptivePortal.java
@@ -79,7 +79,7 @@
out.writeStrongBinder(mBinder);
}
- public static final Parcelable.Creator<CaptivePortal> CREATOR
+ public static final @android.annotation.NonNull Parcelable.Creator<CaptivePortal> CREATOR
= new Parcelable.Creator<CaptivePortal>() {
@Override
public CaptivePortal createFromParcel(Parcel in) {
diff --git a/core/java/android/net/ConnectionInfo.java b/core/java/android/net/ConnectionInfo.java
index 58d0e05..4514a84 100644
--- a/core/java/android/net/ConnectionInfo.java
+++ b/core/java/android/net/ConnectionInfo.java
@@ -54,7 +54,7 @@
out.writeInt(remote.getPort());
}
- public static final Creator<ConnectionInfo> CREATOR = new Creator<ConnectionInfo>() {
+ public static final @android.annotation.NonNull Creator<ConnectionInfo> CREATOR = new Creator<ConnectionInfo>() {
public ConnectionInfo createFromParcel(Parcel in) {
int protocol = in.readInt();
InetAddress localAddress;
diff --git a/core/java/android/net/DhcpInfo.java b/core/java/android/net/DhcpInfo.java
index 788d7d9..98bab44 100644
--- a/core/java/android/net/DhcpInfo.java
+++ b/core/java/android/net/DhcpInfo.java
@@ -84,7 +84,7 @@
}
/** Implement the Parcelable interface {@hide} */
- public static final Creator<DhcpInfo> CREATOR =
+ public static final @android.annotation.NonNull Creator<DhcpInfo> CREATOR =
new Creator<DhcpInfo>() {
public DhcpInfo createFromParcel(Parcel in) {
DhcpInfo info = new DhcpInfo();
diff --git a/core/java/android/net/IpConfiguration.java b/core/java/android/net/IpConfiguration.java
index 3319f33..2af82d7 100644
--- a/core/java/android/net/IpConfiguration.java
+++ b/core/java/android/net/IpConfiguration.java
@@ -189,7 +189,7 @@
}
/** Implement the Parcelable interface */
- public static final Creator<IpConfiguration> CREATOR =
+ public static final @android.annotation.NonNull Creator<IpConfiguration> CREATOR =
new Creator<IpConfiguration>() {
public IpConfiguration createFromParcel(Parcel in) {
IpConfiguration config = new IpConfiguration();
diff --git a/core/java/android/net/IpPrefix.java b/core/java/android/net/IpPrefix.java
index 175263f..21bbd30 100644
--- a/core/java/android/net/IpPrefix.java
+++ b/core/java/android/net/IpPrefix.java
@@ -285,7 +285,7 @@
/**
* Implement the Parcelable interface.
*/
- public static final Creator<IpPrefix> CREATOR =
+ public static final @android.annotation.NonNull Creator<IpPrefix> CREATOR =
new Creator<IpPrefix>() {
public IpPrefix createFromParcel(Parcel in) {
byte[] address = in.createByteArray();
diff --git a/core/java/android/net/KeepalivePacketData.java b/core/java/android/net/KeepalivePacketData.java
index 18726f7..9b8b732 100644
--- a/core/java/android/net/KeepalivePacketData.java
+++ b/core/java/android/net/KeepalivePacketData.java
@@ -105,7 +105,7 @@
}
/** Parcelable Creator */
- public static final Parcelable.Creator<KeepalivePacketData> CREATOR =
+ public static final @android.annotation.NonNull Parcelable.Creator<KeepalivePacketData> CREATOR =
new Parcelable.Creator<KeepalivePacketData>() {
public KeepalivePacketData createFromParcel(Parcel in) {
return new KeepalivePacketData(in);
diff --git a/core/java/android/net/LinkAddress.java b/core/java/android/net/LinkAddress.java
index 8b01960..78a4e72 100644
--- a/core/java/android/net/LinkAddress.java
+++ b/core/java/android/net/LinkAddress.java
@@ -357,7 +357,7 @@
/**
* Implement the Parcelable interface.
*/
- public static final Creator<LinkAddress> CREATOR =
+ public static final @android.annotation.NonNull Creator<LinkAddress> CREATOR =
new Creator<LinkAddress>() {
public LinkAddress createFromParcel(Parcel in) {
InetAddress address = null;
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java
index 42db0fd..b52b15e 100644
--- a/core/java/android/net/LinkProperties.java
+++ b/core/java/android/net/LinkProperties.java
@@ -1574,7 +1574,7 @@
/**
* Implement the Parcelable interface.
*/
- public static final Creator<LinkProperties> CREATOR =
+ public static final @android.annotation.NonNull Creator<LinkProperties> CREATOR =
new Creator<LinkProperties>() {
public LinkProperties createFromParcel(Parcel in) {
LinkProperties netProp = new LinkProperties();
diff --git a/core/java/android/net/MacAddress.java b/core/java/android/net/MacAddress.java
index c2b7d2c..aa8e010 100644
--- a/core/java/android/net/MacAddress.java
+++ b/core/java/android/net/MacAddress.java
@@ -167,7 +167,7 @@
return 0;
}
- public static final Parcelable.Creator<MacAddress> CREATOR =
+ public static final @android.annotation.NonNull Parcelable.Creator<MacAddress> CREATOR =
new Parcelable.Creator<MacAddress>() {
public MacAddress createFromParcel(Parcel in) {
return new MacAddress(in.readLong());
@@ -400,6 +400,21 @@
}
/**
+ * Checks if this MAC Address matches the provided range.
+ *
+ * @param baseAddress MacAddress representing the base address to compare with.
+ * @param mask MacAddress representing the mask to use during comparison.
+ * @return true if this MAC Address matches the given range.
+ *
+ * @hide
+ */
+ public boolean matches(@NonNull MacAddress baseAddress, @NonNull MacAddress mask) {
+ Preconditions.checkNotNull(baseAddress);
+ Preconditions.checkNotNull(mask);
+ return (mAddr & mask.mAddr) == (baseAddress.mAddr & mask.mAddr);
+ }
+
+ /**
* Create a link-local Inet6Address from the MAC address. The EUI-48 MAC address is converted
* to an EUI-64 MAC address per RFC 4291. The resulting EUI-64 is used to construct a link-local
* IPv6 address per RFC 4862.
diff --git a/core/java/android/net/NattKeepalivePacketData.java b/core/java/android/net/NattKeepalivePacketData.java
index bdb246f..5c55a98 100644
--- a/core/java/android/net/NattKeepalivePacketData.java
+++ b/core/java/android/net/NattKeepalivePacketData.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 The Android Open Source Project
+ * Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
diff --git a/core/java/android/net/Network.java b/core/java/android/net/Network.java
index e04b5fc..0fafdf7 100644
--- a/core/java/android/net/Network.java
+++ b/core/java/android/net/Network.java
@@ -470,7 +470,7 @@
dest.writeInt(netId);
}
- public static final Creator<Network> CREATOR =
+ public static final @android.annotation.NonNull Creator<Network> CREATOR =
new Creator<Network>() {
public Network createFromParcel(Parcel in) {
int netId = in.readInt();
diff --git a/core/java/android/net/NetworkAgent.java b/core/java/android/net/NetworkAgent.java
index b55f6ba..273f8cd 100644
--- a/core/java/android/net/NetworkAgent.java
+++ b/core/java/android/net/NetworkAgent.java
@@ -492,7 +492,7 @@
}
/**
- * Requests that the network hardware stops sending keepalive packets.
+ * Requests that the network hardware send the specified packet at the specified interval.
*/
protected void stopSocketKeepalive(Message msg) {
onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_HARDWARE_UNSUPPORTED);
diff --git a/core/java/android/net/NetworkCapabilities.java b/core/java/android/net/NetworkCapabilities.java
index e1cfe99..c57ae0c 100644
--- a/core/java/android/net/NetworkCapabilities.java
+++ b/core/java/android/net/NetworkCapabilities.java
@@ -1476,7 +1476,7 @@
dest.writeString(mSSID);
}
- public static final Creator<NetworkCapabilities> CREATOR =
+ public static final @android.annotation.NonNull Creator<NetworkCapabilities> CREATOR =
new Creator<NetworkCapabilities>() {
@Override
public NetworkCapabilities createFromParcel(Parcel in) {
diff --git a/core/java/android/net/NetworkInfo.java b/core/java/android/net/NetworkInfo.java
index 89d9961..cd83531 100644
--- a/core/java/android/net/NetworkInfo.java
+++ b/core/java/android/net/NetworkInfo.java
@@ -557,7 +557,7 @@
}
}
- public static final Creator<NetworkInfo> CREATOR = new Creator<NetworkInfo>() {
+ public static final @android.annotation.NonNull Creator<NetworkInfo> CREATOR = new Creator<NetworkInfo>() {
@Override
public NetworkInfo createFromParcel(Parcel in) {
int netType = in.readInt();
diff --git a/core/java/android/net/NetworkMisc.java b/core/java/android/net/NetworkMisc.java
index 6fb2390..9ba3bd9 100644
--- a/core/java/android/net/NetworkMisc.java
+++ b/core/java/android/net/NetworkMisc.java
@@ -106,7 +106,7 @@
out.writeInt(skip464xlat ? 1 : 0);
}
- public static final Creator<NetworkMisc> CREATOR = new Creator<NetworkMisc>() {
+ public static final @android.annotation.NonNull Creator<NetworkMisc> CREATOR = new Creator<NetworkMisc>() {
@Override
public NetworkMisc createFromParcel(Parcel in) {
NetworkMisc networkMisc = new NetworkMisc();
diff --git a/core/java/android/net/NetworkRequest.java b/core/java/android/net/NetworkRequest.java
index 9508217..dcb027d 100644
--- a/core/java/android/net/NetworkRequest.java
+++ b/core/java/android/net/NetworkRequest.java
@@ -363,7 +363,7 @@
dest.writeInt(requestId);
dest.writeString(type.name());
}
- public static final Creator<NetworkRequest> CREATOR =
+ public static final @android.annotation.NonNull Creator<NetworkRequest> CREATOR =
new Creator<NetworkRequest>() {
public NetworkRequest createFromParcel(Parcel in) {
NetworkCapabilities nc = NetworkCapabilities.CREATOR.createFromParcel(in);
diff --git a/core/java/android/net/NetworkState.java b/core/java/android/net/NetworkState.java
index 97fb3fb..292cf50 100644
--- a/core/java/android/net/NetworkState.java
+++ b/core/java/android/net/NetworkState.java
@@ -87,7 +87,7 @@
}
@UnsupportedAppUsage
- public static final Creator<NetworkState> CREATOR = new Creator<NetworkState>() {
+ public static final @android.annotation.NonNull Creator<NetworkState> CREATOR = new Creator<NetworkState>() {
@Override
public NetworkState createFromParcel(Parcel in) {
return new NetworkState(in);
diff --git a/core/java/android/net/NetworkUtils.java b/core/java/android/net/NetworkUtils.java
index 0ae29b1..ed410e2 100644
--- a/core/java/android/net/NetworkUtils.java
+++ b/core/java/android/net/NetworkUtils.java
@@ -16,10 +16,15 @@
package android.net;
+import static android.system.OsConstants.AF_INET;
+import static android.system.OsConstants.AF_INET6;
+
+import android.annotation.NonNull;
import android.annotation.UnsupportedAppUsage;
import android.net.shared.Inet4AddressUtils;
import android.os.Build;
import android.system.ErrnoException;
+import android.system.Os;
import android.util.Log;
import android.util.Pair;
@@ -480,4 +485,30 @@
}
return routedIPCount;
}
+
+ private static final int[] ADDRESS_FAMILIES = new int[] {AF_INET, AF_INET6};
+
+ /**
+ * Returns true if the hostname is weakly validated.
+ * @param hostname Name of host to validate.
+ * @return True if it's a valid-ish hostname.
+ *
+ * @hide
+ */
+ public static boolean isWeaklyValidatedHostname(@NonNull String hostname) {
+ // TODO(b/34953048): Use a validation method that permits more accurate,
+ // but still inexpensive, checking of likely valid DNS hostnames.
+ final String weakHostnameRegex = "^[a-zA-Z0-9_.-]+$";
+ if (!hostname.matches(weakHostnameRegex)) {
+ return false;
+ }
+
+ for (int address_family : ADDRESS_FAMILIES) {
+ if (Os.inet_pton(address_family, hostname) != null) {
+ return false;
+ }
+ }
+
+ return true;
+ }
}
diff --git a/core/java/android/net/ProxyInfo.java b/core/java/android/net/ProxyInfo.java
index ef2269a..807c467 100644
--- a/core/java/android/net/ProxyInfo.java
+++ b/core/java/android/net/ProxyInfo.java
@@ -342,7 +342,7 @@
dest.writeStringArray(mParsedExclusionList);
}
- public static final Creator<ProxyInfo> CREATOR =
+ public static final @android.annotation.NonNull Creator<ProxyInfo> CREATOR =
new Creator<ProxyInfo>() {
public ProxyInfo createFromParcel(Parcel in) {
String host = null;
diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java
index 5c0f758..c1c8f6e 100644
--- a/core/java/android/net/RouteInfo.java
+++ b/core/java/android/net/RouteInfo.java
@@ -486,7 +486,7 @@
/**
* Implement the Parcelable interface.
*/
- public static final Creator<RouteInfo> CREATOR =
+ public static final @android.annotation.NonNull Creator<RouteInfo> CREATOR =
new Creator<RouteInfo>() {
public RouteInfo createFromParcel(Parcel in) {
IpPrefix dest = in.readParcelable(null);
diff --git a/core/java/android/net/StaticIpConfiguration.java b/core/java/android/net/StaticIpConfiguration.java
index 99cf3a9..8b264ee 100644
--- a/core/java/android/net/StaticIpConfiguration.java
+++ b/core/java/android/net/StaticIpConfiguration.java
@@ -212,7 +212,7 @@
}
/** Implement the Parcelable interface */
- public static final Creator<StaticIpConfiguration> CREATOR =
+ public static final @android.annotation.NonNull Creator<StaticIpConfiguration> CREATOR =
new Creator<StaticIpConfiguration>() {
public StaticIpConfiguration createFromParcel(Parcel in) {
return readFromParcel(in);
diff --git a/core/java/android/net/TcpKeepalivePacketData.java b/core/java/android/net/TcpKeepalivePacketData.java
deleted file mode 100644
index f07dfb6..0000000
--- a/core/java/android/net/TcpKeepalivePacketData.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package android.net;
-
-import static android.net.SocketKeepalive.ERROR_INVALID_IP_ADDRESS;
-
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.net.SocketKeepalive.InvalidPacketException;
-import android.net.util.IpUtils;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.system.OsConstants;
-
-import java.net.Inet4Address;
-import java.net.InetAddress;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.util.Objects;
-
-/**
- * Represents the actual tcp keep alive packets which will be used for hardware offload.
- * @hide
- */
-public class TcpKeepalivePacketData extends KeepalivePacketData implements Parcelable {
- private static final String TAG = "TcpKeepalivePacketData";
-
- /** TCP sequence number. */
- public final int tcpSeq;
-
- /** TCP ACK number. */
- public final int tcpAck;
-
- /** TCP RCV window. */
- public final int tcpWnd;
-
- /** TCP RCV window scale. */
- public final int tcpWndScale;
-
- private static final int IPV4_HEADER_LENGTH = 20;
- private static final int IPV6_HEADER_LENGTH = 40;
- private static final int TCP_HEADER_LENGTH = 20;
-
- // This should only be constructed via static factory methods, such as
- // tcpKeepalivePacket.
- private TcpKeepalivePacketData(TcpSocketInfo tcpDetails, byte[] data)
- throws InvalidPacketException {
- super(tcpDetails.srcAddress, tcpDetails.srcPort, tcpDetails.dstAddress,
- tcpDetails.dstPort, data);
- tcpSeq = tcpDetails.seq;
- tcpAck = tcpDetails.ack;
- // In the packet, the window is shifted right by the window scale.
- tcpWnd = tcpDetails.rcvWnd;
- tcpWndScale = tcpDetails.rcvWndScale;
- }
-
- /**
- * Factory method to create tcp keepalive packet structure.
- */
- public static TcpKeepalivePacketData tcpKeepalivePacket(
- TcpSocketInfo tcpDetails) throws InvalidPacketException {
- final byte[] packet;
- if ((tcpDetails.srcAddress instanceof Inet4Address)
- && (tcpDetails.dstAddress instanceof Inet4Address)) {
- packet = buildV4Packet(tcpDetails);
- } else {
- // TODO: support ipv6
- throw new InvalidPacketException(ERROR_INVALID_IP_ADDRESS);
- }
-
- return new TcpKeepalivePacketData(tcpDetails, packet);
- }
-
- /**
- * Build ipv4 tcp keepalive packet, not including the link-layer header.
- */
- // TODO : if this code is ever moved to the network stack, factorize constants with the ones
- // over there.
- private static byte[] buildV4Packet(TcpSocketInfo tcpDetails) {
- final int length = IPV4_HEADER_LENGTH + TCP_HEADER_LENGTH;
- ByteBuffer buf = ByteBuffer.allocate(length);
- buf.order(ByteOrder.BIG_ENDIAN);
- // IP version and TOS. TODO : fetch this from getsockopt(SOL_IP, IP_TOS)
- buf.putShort((short) 0x4500);
- buf.putShort((short) length);
- buf.putInt(0x4000); // ID, flags=DF, offset
- // TODO : fetch TTL from getsockopt(SOL_IP, IP_TTL)
- buf.put((byte) 64);
- buf.put((byte) OsConstants.IPPROTO_TCP);
- final int ipChecksumOffset = buf.position();
- buf.putShort((short) 0); // IP checksum
- buf.put(tcpDetails.srcAddress.getAddress());
- buf.put(tcpDetails.dstAddress.getAddress());
- buf.putShort((short) tcpDetails.srcPort);
- buf.putShort((short) tcpDetails.dstPort);
- buf.putInt(tcpDetails.seq); // Sequence Number
- buf.putInt(tcpDetails.ack); // ACK
- buf.putShort((short) 0x5010); // TCP length=5, flags=ACK
- buf.putShort((short) (tcpDetails.rcvWnd >> tcpDetails.rcvWndScale)); // Window size
- final int tcpChecksumOffset = buf.position();
- buf.putShort((short) 0); // TCP checksum
- // URG is not set therefore the urgent pointer is not included
- buf.putShort(ipChecksumOffset, IpUtils.ipChecksum(buf, 0));
- buf.putShort(tcpChecksumOffset, IpUtils.tcpChecksum(
- buf, 0, IPV4_HEADER_LENGTH, TCP_HEADER_LENGTH));
-
- return buf.array();
- }
-
- // TODO: add buildV6Packet.
-
- /** Represents tcp/ip information. */
- // TODO: Replace TcpSocketInfo with TcpKeepalivePacketDataParcelable.
- public static class TcpSocketInfo {
- public final InetAddress srcAddress;
- public final InetAddress dstAddress;
- public final int srcPort;
- public final int dstPort;
- public final int seq;
- public final int ack;
- public final int rcvWnd;
- public final int rcvWndScale;
-
- public TcpSocketInfo(InetAddress sAddr, int sPort, InetAddress dAddr,
- int dPort, int writeSeq, int readSeq, int rWnd, int rWndScale) {
- srcAddress = sAddr;
- dstAddress = dAddr;
- srcPort = sPort;
- dstPort = dPort;
- seq = writeSeq;
- ack = readSeq;
- rcvWnd = rWnd;
- rcvWndScale = rWndScale;
- }
- }
-
- @Override
- public boolean equals(@Nullable final Object o) {
- if (!(o instanceof TcpKeepalivePacketData)) return false;
- final TcpKeepalivePacketData other = (TcpKeepalivePacketData) o;
- return this.srcAddress.equals(other.srcAddress)
- && this.dstAddress.equals(other.dstAddress)
- && this.srcPort == other.srcPort
- && this.dstPort == other.dstPort
- && this.tcpAck == other.tcpAck
- && this.tcpSeq == other.tcpSeq
- && this.tcpWnd == other.tcpWnd
- && this.tcpWndScale == other.tcpWndScale;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(srcAddress, dstAddress, srcPort, dstPort, tcpAck, tcpSeq, tcpWnd,
- tcpWndScale);
- }
-
- /* Parcelable Implementation. */
- /* Note that this object implements parcelable (and needs to keep doing this as it inherits
- * from a class that does), but should usually be parceled as a stable parcelable using
- * the toStableParcelable() and fromStableParcelable() methods.
- */
- public int describeContents() {
- return 0;
- }
-
- /** Write to parcel. */
- public void writeToParcel(Parcel out, int flags) {
- super.writeToParcel(out, flags);
- out.writeInt(tcpSeq);
- out.writeInt(tcpAck);
- out.writeInt(tcpWnd);
- out.writeInt(tcpWndScale);
- }
-
- private TcpKeepalivePacketData(Parcel in) {
- super(in);
- tcpSeq = in.readInt();
- tcpAck = in.readInt();
- tcpWnd = in.readInt();
- tcpWndScale = in.readInt();
- }
-
- /** Parcelable Creator. */
- public static final Parcelable.Creator<TcpKeepalivePacketData> CREATOR =
- new Parcelable.Creator<TcpKeepalivePacketData>() {
- public TcpKeepalivePacketData createFromParcel(Parcel in) {
- return new TcpKeepalivePacketData(in);
- }
-
- public TcpKeepalivePacketData[] newArray(int size) {
- return new TcpKeepalivePacketData[size];
- }
- };
-
- /**
- * Convert this TcpKeepalivePacketData to a TcpKeepalivePacketDataParcelable.
- */
- @NonNull
- public TcpKeepalivePacketDataParcelable toStableParcelable() {
- final TcpKeepalivePacketDataParcelable parcel = new TcpKeepalivePacketDataParcelable();
- parcel.srcAddress = srcAddress.getAddress();
- parcel.srcPort = srcPort;
- parcel.dstAddress = dstAddress.getAddress();
- parcel.dstPort = dstPort;
- parcel.seq = tcpSeq;
- parcel.ack = tcpAck;
- return parcel;
- }
-
- @Override
- public String toString() {
- return "saddr: " + srcAddress
- + " daddr: " + dstAddress
- + " sport: " + srcPort
- + " dport: " + dstPort
- + " seq: " + tcpSeq
- + " ack: " + tcpAck
- + " wnd: " + tcpWnd
- + " wndScale: " + tcpWndScale;
- }
-}
diff --git a/core/java/android/net/UidRange.java b/core/java/android/net/UidRange.java
index 793c82d..e56f059 100644
--- a/core/java/android/net/UidRange.java
+++ b/core/java/android/net/UidRange.java
@@ -19,14 +19,17 @@
import static android.os.UserHandle.PER_USER_RANGE;
import android.os.Parcel;
+import android.os.Parcelable;
/**
* An inclusive range of UIDs.
*
* @hide
*/
-public final class UidRange extends UidRangeParcel {
- private UidRange() {}
+public final class UidRange implements Parcelable {
+ public final int start;
+ public final int stop;
+
public UidRange(int startUid, int stopUid) {
if (startUid < 0) throw new IllegalArgumentException("Invalid start UID.");
if (stopUid < 0) throw new IllegalArgumentException("Invalid stop UID.");
@@ -86,18 +89,28 @@
return start + "-" + stop;
}
- /**
- * DO NOT override "writeToParcel" and "readFromParcel" in this class.
- * The parceling code is autogenerated by the superclass.
- */
+ // Implement the Parcelable interface
+ // TODO: Consider making this class no longer parcelable, since all users are likely in the
+ // system server.
+ @Override
+ public int describeContents() {
+ return 0;
+ }
- public static final Creator<UidRange> CREATOR =
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(start);
+ dest.writeInt(stop);
+ }
+
+ public static final @android.annotation.NonNull Creator<UidRange> CREATOR =
new Creator<UidRange>() {
@Override
public UidRange createFromParcel(Parcel in) {
- UidRange obj = new UidRange();
- obj.readFromParcel(in);
- return obj;
+ int start = in.readInt();
+ int stop = in.readInt();
+
+ return new UidRange(start, stop);
}
@Override
public UidRange[] newArray(int size) {
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 4416b4d..b2ee686 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -2716,7 +2716,7 @@
switch (msg.what) {
default:
return false;
- case android.net.NetworkFactory.EVENT_UNFULFILLABLE_REQUEST: {
+ case NetworkFactory.EVENT_UNFULFILLABLE_REQUEST: {
handleReleaseNetworkRequest((NetworkRequest) msg.obj, msg.sendingUid,
/* callOnUnavailable */ true);
break;
diff --git a/tests/net/java/android/net/MacAddressTest.java b/tests/net/java/android/net/MacAddressTest.java
index b0e5fb1..daf187d 100644
--- a/tests/net/java/android/net/MacAddressTest.java
+++ b/tests/net/java/android/net/MacAddressTest.java
@@ -254,6 +254,39 @@
}
}
+ @Test
+ public void testMatches() {
+ // match 4 bytes prefix
+ assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
+ MacAddress.fromString("aa:bb:cc:dd:00:00"),
+ MacAddress.fromString("ff:ff:ff:ff:00:00")));
+
+ // match bytes 0,1,2 and 5
+ assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
+ MacAddress.fromString("aa:bb:cc:00:00:11"),
+ MacAddress.fromString("ff:ff:ff:00:00:ff")));
+
+ // match 34 bit prefix
+ assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
+ MacAddress.fromString("aa:bb:cc:dd:c0:00"),
+ MacAddress.fromString("ff:ff:ff:ff:c0:00")));
+
+ // fail to match 36 bit prefix
+ assertFalse(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
+ MacAddress.fromString("aa:bb:cc:dd:40:00"),
+ MacAddress.fromString("ff:ff:ff:ff:f0:00")));
+
+ // match all 6 bytes
+ assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
+ MacAddress.fromString("aa:bb:cc:dd:ee:11"),
+ MacAddress.fromString("ff:ff:ff:ff:ff:ff")));
+
+ // match none of 6 bytes
+ assertTrue(MacAddress.fromString("aa:bb:cc:dd:ee:11").matches(
+ MacAddress.fromString("00:00:00:00:00:00"),
+ MacAddress.fromString("00:00:00:00:00:00")));
+ }
+
/**
* Tests that link-local address generation from MAC is valid.
*/
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index 3efdfd9..3263ef9 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -3697,7 +3697,7 @@
testFactory.setScoreFilter(40);
// Register the factory and expect it to receive the default request.
- testFactory.expectAddRequestsWithScores(0); // default request score is 0, not served yet
+ testFactory.expectAddRequestsWithScores(0);
testFactory.register();
SparseArray<NetworkRequest> requests = testFactory.waitForNetworkRequests(1);