public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable {
method public java.lang.String getHostname();
- method public java.net.InetAddress[] getInetAddresses();
+ method public java.util.List<java.net.InetAddress> getInetAddresses();
method public int getTotalResolvedAddressCount();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.admin.DnsEvent> CREATOR;
public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable {
method public java.lang.String getHostname();
- method public java.net.InetAddress[] getInetAddresses();
+ method public java.util.List<java.net.InetAddress> getInetAddresses();
method public int getTotalResolvedAddressCount();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.admin.DnsEvent> CREATOR;
public final class DnsEvent extends android.app.admin.NetworkEvent implements android.os.Parcelable {
method public java.lang.String getHostname();
- method public java.net.InetAddress[] getInetAddresses();
+ method public java.util.List<java.net.InetAddress> getInetAddresses();
method public int getTotalResolvedAddressCount();
method public void writeToParcel(android.os.Parcel, int);
field public static final android.os.Parcelable.Creator<android.app.admin.DnsEvent> CREATOR;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
/**
* A class that represents a DNS lookup event.
}
/** Returns (possibly a subset of) the IP addresses returned. */
- public InetAddress[] getInetAddresses() {
- final int length = ipAddresses != null ? ipAddresses.length : 0;
- final InetAddress[] inetAddresses = new InetAddress[length];
- for (int i = 0; i < length; i++) {
+ public List<InetAddress> getInetAddresses() {
+ if (ipAddresses == null || ipAddresses.length == 0) {
+ return Collections.emptyList();
+ }
+ final List<InetAddress> inetAddresses = new ArrayList<>(ipAddresses.length);
+ for (final String ipAddress : ipAddresses) {
try {
// ipAddress is already an address, not a host name, no DNS resolution will happen.
- inetAddresses[i] = InetAddress.getByName(ipAddresses[i]);
+ inetAddresses.add(InetAddress.getByName(ipAddress));
} catch (UnknownHostException e) {
// Should never happen as we aren't passing a host name.
- inetAddresses[i] = InetAddress.getLoopbackAddress();
}
}
return inetAddresses;
/**
* Returns the number of IP addresses returned from the DNS lookup event. May be different from
- * the length of the array returned by {@link #getInetAddresses()} if there were too many
+ * the length of the list returned by {@link #getInetAddresses()} if there were too many
* addresses to log.
*/
public int getTotalResolvedAddressCount() {
DnsEvent unparceledEvent = p.readParcelable(NetworkEventTest.class.getClassLoader());
p.recycle();
assertEquals(event.getHostname(), unparceledEvent.getHostname());
- assertEquals(event.getInetAddresses()[0], unparceledEvent.getInetAddresses()[0]);
- assertEquals(event.getInetAddresses()[1], unparceledEvent.getInetAddresses()[1]);
- assertEquals(event.getTotalResolvedAddressCount(), unparceledEvent.getTotalResolvedAddressCount());
+ assertEquals(event.getInetAddresses().get(0), unparceledEvent.getInetAddresses().get(0));
+ assertEquals(event.getInetAddresses().get(1), unparceledEvent.getInetAddresses().get(1));
+ assertEquals(event.getTotalResolvedAddressCount(),
+ unparceledEvent.getTotalResolvedAddressCount());
assertEquals(event.getPackageName(), unparceledEvent.getPackageName());
assertEquals(event.getTimestamp(), unparceledEvent.getTimestamp());
}