Change visibility of members in StatsEvent

- Rename writeAttributionNode to writeAttributionChain
- Make Type Id, size limit constants public and @hide for testing
- Change visibility of StatsEvent package protected functions to public

Bug: 141696033
Test: m -j
Change-Id: Ia4818f621672d469390bf7654bdd317f0cd11692
This commit is contained in:
Muhammad Qureshi
2019-11-21 17:44:22 -08:00
parent 2b20464232
commit 3e301e8c1b

View File

@@ -45,6 +45,166 @@ import com.android.internal.annotations.VisibleForTesting;
* @hide
**/
public final class StatsEvent implements Parcelable {
// Type Ids.
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_INT = 0x00;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_LONG = 0x01;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_STRING = 0x02;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_LIST = 0x03;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_FLOAT = 0x04;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_BOOLEAN = 0x05;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_BYTE_ARRAY = 0x06;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_OBJECT = 0x07;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_KEY_VALUE_PAIRS = 0x08;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_ATTRIBUTION_CHAIN = 0x09;
/**
* @hide
**/
@VisibleForTesting
public static final byte TYPE_ERRORS = 0x0F;
// Error flags.
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_NO_TIMESTAMP = 0x1;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_NO_ATOM_ID = 0x2;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_OVERFLOW = 0x4;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_ATTRIBUTION_CHAIN_TOO_LONG = 0x8;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_TOO_MANY_KEY_VALUE_PAIRS = 0x10;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_ANNOTATION_DOES_NOT_FOLLOW_FIELD = 0x20;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_INVALID_ANNOTATION_ID = 0x40;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_ANNOTATION_ID_TOO_LARGE = 0x80;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_TOO_MANY_ANNOTATIONS = 0x100;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_TOO_MANY_FIELDS = 0x200;
/**
* @hide
**/
@VisibleForTesting
public static final int ERROR_ATTRIBUTION_UIDS_TAGS_SIZES_NOT_EQUAL = 0x400;
// Size limits.
/**
* @hide
**/
@VisibleForTesting
public static final int MAX_ANNOTATION_COUNT = 15;
/**
* @hide
**/
@VisibleForTesting
public static final int MAX_ATTRIBUTION_NODES = 127;
/**
* @hide
**/
@VisibleForTesting
public static final int MAX_NUM_ELEMENTS = 127;
/**
* @hide
**/
@VisibleForTesting
public static final int MAX_KEY_VALUE_PAIRS = 127;
private static final int LOGGER_ENTRY_MAX_PAYLOAD = 4068;
// Max payload size is 4 bytes less as 4 bytes are reserved for statsEventTag.
@@ -69,23 +229,74 @@ public final class StatsEvent implements Parcelable {
return new StatsEvent.Builder(Buffer.obtain());
}
int getAtomId() {
/**
* Get the atom Id of the atom encoded in this StatsEvent object.
*
* @hide
**/
public int getAtomId() {
return mAtomId;
}
/**
* Get the byte array that contains the encoded payload that can be sent to statsd.
*
* @hide
**/
@NonNull
byte[] getBytes() {
public byte[] getBytes() {
return mBuffer.getBytes();
}
int getNumBytes() {
/**
* Get the number of bytes used to encode the StatsEvent payload.
*
* @hide
**/
public int getNumBytes() {
return mNumBytes;
}
void release() {
/**
* Recycle this StatsEvent object.
**/
public void release() {
mBuffer.release();
}
/**
* Boilerplate for Parcel.
*/
public static final @NonNull Parcelable.Creator<StatsEvent> CREATOR =
new Parcelable.Creator<StatsEvent>() {
public StatsEvent createFromParcel(Parcel in) {
// Purposefully leaving this method not implemented.
throw new RuntimeException("Not implemented");
}
public StatsEvent[] newArray(int size) {
// Purposefully leaving this method not implemented.
throw new RuntimeException("Not implemented");
}
};
/**
* Boilerplate for Parcel.
*/
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mAtomId);
out.writeInt(getNumBytes());
out.writeByteArray(getBytes());
}
/**
* Boilerplate for Parcel.
*/
public int describeContents() {
return 0;
}
/**
* Builder for constructing a StatsEvent object.
*
@@ -114,41 +325,8 @@ public final class StatsEvent implements Parcelable {
* .addBooleanAnnotation(annotation1Id, true)
* .build();
* </pre>
* @hide
**/
public static final class Builder {
// Type Ids.
private static final byte TYPE_INT = 0x00;
private static final byte TYPE_LONG = 0x01;
private static final byte TYPE_STRING = 0x02;
private static final byte TYPE_LIST = 0x03;
private static final byte TYPE_FLOAT = 0x04;
private static final byte TYPE_BOOLEAN = 0x05;
private static final byte TYPE_BYTE_ARRAY = 0x06;
private static final byte TYPE_OBJECT = 0x07;
private static final byte TYPE_KEY_VALUE_PAIRS = 0x08;
private static final byte TYPE_ATTRIBUTION_CHAIN = 0x09;
private static final byte TYPE_ERRORS = 0x0F;
// Error flags.
private static final int ERROR_NO_TIMESTAMP = 0x1;
private static final int ERROR_NO_ATOM_ID = 0x2;
private static final int ERROR_OVERFLOW = 0x4;
private static final int ERROR_ATTRIBUTION_CHAIN_TOO_LONG = 0x8;
private static final int ERROR_TOO_MANY_KEY_VALUE_PAIRS = 0x10;
private static final int ERROR_ANNOTATION_DOES_NOT_FOLLOW_FIELD = 0x20;
private static final int ERROR_INVALID_ANNOTATION_ID = 0x40;
private static final int ERROR_ANNOTATION_ID_TOO_LARGE = 0x80;
private static final int ERROR_TOO_MANY_ANNOTATIONS = 0x100;
private static final int ERROR_TOO_MANY_FIELDS = 0x200;
private static final int ERROR_ATTRIBUTION_UIDS_TAGS_SIZES_NOT_EQUAL = 0x400;
// Size limits.
private static final int MAX_ANNOTATION_COUNT = 15;
private static final int MAX_ATTRIBUTION_NODES = 127;
private static final int MAX_NUM_ELEMENTS = 127;
private static final int MAX_KEY_VALUE_PAIRS = 127;
// Fixed positions.
private static final int POS_NUM_ELEMENTS = 1;
private static final int POS_TIMESTAMP_NS = POS_NUM_ELEMENTS + Byte.BYTES;
@@ -290,7 +468,7 @@ public final class StatsEvent implements Parcelable {
* @param tags array of tags in the attribution nodes.
**/
@NonNull
public Builder writeAttributionNode(
public Builder writeAttributionChain(
@NonNull final int[] uids, @NonNull final String[] tags) {
final byte numUids = (byte) uids.length;
final byte numTags = (byte) tags.length;
@@ -633,39 +811,4 @@ public final class StatsEvent implements Parcelable {
return 0;
}
}
/**
* Boilerplate for Parcel.
*
* @hide
*/
public static final @NonNull Parcelable.Creator<StatsEvent> CREATOR =
new Parcelable.Creator<StatsEvent>() {
public StatsEvent createFromParcel(Parcel in) {
// Purposefully leaving this method not implemented.
throw new RuntimeException("Not implemented");
}
public StatsEvent[] newArray(int size) {
// Purposefully leaving this method not implemented.
throw new RuntimeException("Not implemented");
}
};
/**
* @hide
*/
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mAtomId);
out.writeInt(getNumBytes());
out.writeByteArray(getBytes());
}
/**
* Boilerplate for Parcel.
*/
public int describeContents() {
return 0;
}
}