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