| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app.admin; |
| 18 |
|
| 19 |
import android.os.Parcel; |
| 20 |
import android.os.Parcelable; |
| 21 |
|
| 22 |
import java.net.InetAddress; |
| 23 |
import java.net.UnknownHostException; |
| 24 |
import java.util.ArrayList; |
| 25 |
import java.util.Collections; |
| 26 |
import java.util.List; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public final class DnsEvent extends NetworkEvent implements Parcelable { |
| 35 |
|
| 36 |
|
| 37 |
private final String mHostname; |
| 38 |
|
| 39 |
|
| 40 |
private final String[] mIpAddresses; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
private final int mIpAddressesCount; |
| 47 |
|
| 48 |
|
| 49 |
public DnsEvent(String hostname, String[] ipAddresses, int ipAddressesCount, |
| 50 |
String packageName, long timestamp) { |
| 51 |
super(packageName, timestamp); |
| 52 |
this.mHostname = hostname; |
| 53 |
this.mIpAddresses = ipAddresses; |
| 54 |
this.mIpAddressesCount = ipAddressesCount; |
| 55 |
} |
| 56 |
|
| 57 |
private DnsEvent(Parcel in) { |
| 58 |
this.mHostname = in.readString(); |
| 59 |
this.mIpAddresses = in.createStringArray(); |
| 60 |
this.mIpAddressesCount = in.readInt(); |
| 61 |
this.mPackageName = in.readString(); |
| 62 |
this.mTimestamp = in.readLong(); |
| 63 |
this.mId = in.readLong(); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
public String getHostname() { |
| 68 |
return mHostname; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
public List<InetAddress> getInetAddresses() { |
| 73 |
if (mIpAddresses == null || mIpAddresses.length == 0) { |
| 74 |
return Collections.emptyList(); |
| 75 |
} |
| 76 |
final List<InetAddress> inetAddresses = new ArrayList<>(mIpAddresses.length); |
| 77 |
for (final String ipAddress : mIpAddresses) { |
| 78 |
try { |
| 79 |
|
| 80 |
inetAddresses.add(InetAddress.getByName(ipAddress)); |
| 81 |
} catch (UnknownHostException e) { |
| 82 |
|
| 83 |
} |
| 84 |
} |
| 85 |
return inetAddresses; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public int getTotalResolvedAddressCount() { |
| 94 |
return mIpAddressesCount; |
| 95 |
} |
| 96 |
|
| 97 |
@Override |
| 98 |
public String toString() { |
| 99 |
return String.format("DnsEvent(%d, %s, %s, %d, %d, %s)", mId, mHostname, |
| 100 |
(mIpAddresses == null) ? "NONE" : String.join(" ", mIpAddresses), |
| 101 |
mIpAddressesCount, mTimestamp, mPackageName); |
| 102 |
} |
| 103 |
|
| 104 |
public static final @android.annotation.NonNull Parcelable.Creator<DnsEvent> CREATOR |
| 105 |
= new Parcelable.Creator<DnsEvent>() { |
| 106 |
@Override |
| 107 |
public DnsEvent createFromParcel(Parcel in) { |
| 108 |
if (in.readInt() != PARCEL_TOKEN_DNS_EVENT) { |
| 109 |
return null; |
| 110 |
} |
| 111 |
return new DnsEvent(in); |
| 112 |
} |
| 113 |
|
| 114 |
@Override |
| 115 |
public DnsEvent[] newArray(int size) { |
| 116 |
return new DnsEvent[size]; |
| 117 |
} |
| 118 |
}; |
| 119 |
|
| 120 |
@Override |
| 121 |
public int describeContents() { |
| 122 |
return 0; |
| 123 |
} |
| 124 |
|
| 125 |
@Override |
| 126 |
public void writeToParcel(Parcel out, int flags) { |
| 127 |
|
| 128 |
out.writeInt(PARCEL_TOKEN_DNS_EVENT); |
| 129 |
out.writeString(mHostname); |
| 130 |
out.writeStringArray(mIpAddresses); |
| 131 |
out.writeInt(mIpAddressesCount); |
| 132 |
out.writeString(mPackageName); |
| 133 |
out.writeLong(mTimestamp); |
| 134 |
out.writeLong(mId); |
| 135 |
} |
| 136 |
} |