Merge \"IpConn metrics: use @IntDef\" into nyc-mr1-dev
am: 018a205824
Change-Id: Ie2b1fc7934ea51bd65a9f360fa3949c2f03afe01
This commit is contained in:
@@ -16,16 +16,21 @@
|
||||
|
||||
package android.net.metrics;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.text.TextUtils;
|
||||
import android.util.SparseArray;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.android.internal.util.MessageUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An event logged when there is a change or event that requires updating the
|
||||
* the APF program in place with a new APF program.
|
||||
@@ -36,10 +41,14 @@ public final class ApfProgramEvent implements Parcelable {
|
||||
|
||||
// Bitflag constants describing what an Apf program filters.
|
||||
// Bits are indexeds from LSB to MSB, starting at index 0.
|
||||
// TODO: use @IntDef
|
||||
public static final int FLAG_MULTICAST_FILTER_ON = 0;
|
||||
public static final int FLAG_HAS_IPV4_ADDRESS = 1;
|
||||
|
||||
/** {@hide} */
|
||||
@IntDef(flag = true, value = {FLAG_MULTICAST_FILTER_ON, FLAG_HAS_IPV4_ADDRESS})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Flags {}
|
||||
|
||||
public final long lifetime; // Lifetime of the program in seconds
|
||||
public final int filteredRas; // Number of RAs filtered by the APF program
|
||||
public final int currentRas; // Total number of current RAs at generation time
|
||||
@@ -48,7 +57,7 @@ public final class ApfProgramEvent implements Parcelable {
|
||||
|
||||
/** {@hide} */
|
||||
public ApfProgramEvent(
|
||||
long lifetime, int filteredRas, int currentRas, int programLength, int flags) {
|
||||
long lifetime, int filteredRas, int currentRas, int programLength, @Flags int flags) {
|
||||
this.lifetime = lifetime;
|
||||
this.filteredRas = filteredRas;
|
||||
this.currentRas = currentRas;
|
||||
@@ -97,7 +106,7 @@ public final class ApfProgramEvent implements Parcelable {
|
||||
};
|
||||
|
||||
/** {@hide} */
|
||||
public static int flagsFor(boolean hasIPv4, boolean multicastFilterOn) {
|
||||
public static @Flags int flagsFor(boolean hasIPv4, boolean multicastFilterOn) {
|
||||
int bitfield = 0;
|
||||
if (hasIPv4) {
|
||||
bitfield |= (1 << FLAG_HAS_IPV4_ADDRESS);
|
||||
@@ -108,25 +117,14 @@ public final class ApfProgramEvent implements Parcelable {
|
||||
return bitfield;
|
||||
}
|
||||
|
||||
// TODO: consider using java.util.BitSet
|
||||
private static int[] bitflagsOf(int bitfield) {
|
||||
int[] flags = new int[Integer.bitCount(bitfield)];
|
||||
int i = 0;
|
||||
int bitflag = 0;
|
||||
while (bitfield != 0) {
|
||||
if ((bitfield & 1) != 0) {
|
||||
flags[i++] = bitflag;
|
||||
}
|
||||
bitflag++;
|
||||
bitfield = bitfield >>> 1;
|
||||
private static String namesOf(@Flags int bitfield) {
|
||||
List<String> names = new ArrayList<>(Integer.bitCount(bitfield));
|
||||
BitSet set = BitSet.valueOf(new long[]{bitfield & Integer.MAX_VALUE});
|
||||
// Only iterate over flag bits which are set.
|
||||
for (int bit = set.nextSetBit(0); bit >= 0; bit = set.nextSetBit(bit+1)) {
|
||||
names.add(Decoder.constants.get(bit));
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
private static String namesOf(int bitfields) {
|
||||
return Arrays.stream(bitflagsOf(bitfields))
|
||||
.mapToObj(i -> Decoder.constants.get(i))
|
||||
.collect(Collectors.joining(", "));
|
||||
return TextUtils.join(", ", names);
|
||||
}
|
||||
|
||||
final static class Decoder {
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* An event recorded by ConnectivityService when there is a change in the default network.
|
||||
* {@hide}
|
||||
*/
|
||||
@SystemApi
|
||||
@@ -55,6 +56,7 @@ public final class DefaultNetworkEvent implements Parcelable {
|
||||
this.prevIPv6 = (in.readByte() > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeInt(netId);
|
||||
out.writeIntArray(transportTypes);
|
||||
@@ -63,6 +65,7 @@ public final class DefaultNetworkEvent implements Parcelable {
|
||||
out.writeByte(prevIPv6 ? (byte) 1 : (byte) 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ import android.util.SparseArray;
|
||||
import com.android.internal.util.MessageUtils;
|
||||
|
||||
/**
|
||||
* {@hide} Event class used to record error events when parsing DHCP response packets.
|
||||
* Event class used to record error events when parsing DHCP response packets.
|
||||
* {@hide}
|
||||
*/
|
||||
@SystemApi
|
||||
public final class DhcpErrorEvent implements Parcelable {
|
||||
@@ -72,11 +73,13 @@ public final class DhcpErrorEvent implements Parcelable {
|
||||
this.errorCode = in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(ifName);
|
||||
out.writeInt(errorCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* An event recorded by DnsEventListenerService.
|
||||
* {@hide}
|
||||
*/
|
||||
@SystemApi
|
||||
@@ -60,6 +61,7 @@ final public class DnsEvent implements Parcelable {
|
||||
out.writeIntArray(latenciesMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net.metrics;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@@ -23,23 +24,32 @@ import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.util.MessageUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* An event recorded by IpManager when IP provisioning completes for a network or
|
||||
* when a network disconnects.
|
||||
* {@hide}
|
||||
*/
|
||||
@SystemApi
|
||||
public final class IpManagerEvent implements Parcelable {
|
||||
|
||||
// TODO: use @IntDef
|
||||
public static final int PROVISIONING_OK = 1;
|
||||
public static final int PROVISIONING_FAIL = 2;
|
||||
public static final int COMPLETE_LIFECYCLE = 3;
|
||||
|
||||
/** {@hide} */
|
||||
@IntDef(value = {PROVISIONING_OK, PROVISIONING_FAIL, COMPLETE_LIFECYCLE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface EventType {}
|
||||
|
||||
public final String ifName;
|
||||
public final int eventType;
|
||||
public final @EventType int eventType;
|
||||
public final long durationMs;
|
||||
|
||||
/** {@hide} */
|
||||
public IpManagerEvent(String ifName, int eventType, long duration) {
|
||||
public IpManagerEvent(String ifName, @EventType int eventType, long duration) {
|
||||
this.ifName = ifName;
|
||||
this.eventType = eventType;
|
||||
this.durationMs = duration;
|
||||
@@ -51,12 +61,14 @@ public final class IpManagerEvent implements Parcelable {
|
||||
this.durationMs = in.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(ifName);
|
||||
out.writeInt(eventType);
|
||||
out.writeLong(durationMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net.metrics;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@@ -23,6 +24,9 @@ import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.util.MessageUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* {@hide}
|
||||
*/
|
||||
@@ -37,19 +41,32 @@ public final class NetworkEvent implements Parcelable {
|
||||
public static final int NETWORK_UNLINGER = 6;
|
||||
public static final int NETWORK_DISCONNECTED = 7;
|
||||
|
||||
/** {@hide} */
|
||||
@IntDef(value = {
|
||||
NETWORK_CONNECTED,
|
||||
NETWORK_VALIDATED,
|
||||
NETWORK_VALIDATION_FAILED,
|
||||
NETWORK_CAPTIVE_PORTAL_FOUND,
|
||||
NETWORK_LINGER,
|
||||
NETWORK_UNLINGER,
|
||||
NETWORK_DISCONNECTED,
|
||||
})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface EventType {}
|
||||
|
||||
public final int netId;
|
||||
public final int eventType;
|
||||
public final @EventType int eventType;
|
||||
public final long durationMs;
|
||||
|
||||
/** {@hide} */
|
||||
public NetworkEvent(int netId, int eventType, long durationMs) {
|
||||
public NetworkEvent(int netId, @EventType int eventType, long durationMs) {
|
||||
this.netId = netId;
|
||||
this.eventType = eventType;
|
||||
this.durationMs = durationMs;
|
||||
}
|
||||
|
||||
/** {@hide} */
|
||||
public NetworkEvent(int netId, int eventType) {
|
||||
public NetworkEvent(int netId, @EventType int eventType) {
|
||||
this(netId, eventType, 0);
|
||||
}
|
||||
|
||||
@@ -59,12 +76,14 @@ public final class NetworkEvent implements Parcelable {
|
||||
durationMs = in.readLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeInt(netId);
|
||||
out.writeInt(eventType);
|
||||
out.writeLong(durationMs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.net.metrics;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.annotation.SystemApi;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
@@ -23,13 +24,16 @@ import android.util.SparseArray;
|
||||
|
||||
import com.android.internal.util.MessageUtils;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
/**
|
||||
* An event recorded by NetworkMonitor when sending a probe for finding captive portals.
|
||||
* {@hide}
|
||||
*/
|
||||
@SystemApi
|
||||
public final class ValidationProbeEvent implements Parcelable {
|
||||
|
||||
// TODO: use @IntDef
|
||||
public static final int PROBE_DNS = 0;
|
||||
public static final int PROBE_HTTP = 1;
|
||||
public static final int PROBE_HTTPS = 2;
|
||||
@@ -38,13 +42,24 @@ public final class ValidationProbeEvent implements Parcelable {
|
||||
public static final int DNS_FAILURE = 0;
|
||||
public static final int DNS_SUCCESS = 1;
|
||||
|
||||
/** {@hide} */
|
||||
@IntDef(value = {PROBE_DNS, PROBE_HTTP, PROBE_HTTPS, PROBE_PAC})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ProbeType {}
|
||||
|
||||
/** {@hide} */
|
||||
@IntDef(value = {DNS_FAILURE, DNS_SUCCESS})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface ReturnCode {}
|
||||
|
||||
public final int netId;
|
||||
public final long durationMs;
|
||||
public final int probeType;
|
||||
public final int returnCode;
|
||||
public final @ProbeType int probeType;
|
||||
public final @ReturnCode int returnCode;
|
||||
|
||||
/** @hide */
|
||||
public ValidationProbeEvent(int netId, long durationMs, int probeType, int returnCode) {
|
||||
public ValidationProbeEvent(
|
||||
int netId, long durationMs, @ProbeType int probeType, @ReturnCode int returnCode) {
|
||||
this.netId = netId;
|
||||
this.durationMs = durationMs;
|
||||
this.probeType = probeType;
|
||||
@@ -58,6 +73,7 @@ public final class ValidationProbeEvent implements Parcelable {
|
||||
returnCode = in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeInt(netId);
|
||||
out.writeLong(durationMs);
|
||||
@@ -65,6 +81,7 @@ public final class ValidationProbeEvent implements Parcelable {
|
||||
out.writeInt(returnCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user